support fusing non constant bias into conv#37
Conversation
Signed-off-by: daquexian <daquexian566@gmail.com>
Signed-off-by: daquexian <daquexian566@gmail.com>
ec8ff8e to
8e3c881
Compare
|
@copilot resolve the merge conflicts in this pull request |
Merge conflicts resolved in commit |
There was a problem hiding this comment.
Pull request overview
This PR extends the fuse_add_bias_into_conv optimization to fuse Add into Conv even when the bias input is produced dynamically (non-constant), including a new case where the bias comes from a QuantizeLinear → DequantizeLinear (QDQ) chain.
Changes:
- Relaxed fusion constraints in
FuseAddBiasIntoConvto allow non-constant bias values when shape information is available. - Added QDQ-aware handling to reshape bias for Conv bias input expectations.
- Added new unit tests covering non-constant bias and QDQ bias fusion behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| onnxoptimizer/passes/fuse_add_bias_into_conv.h | Expands the fusion pass to accept non-constant bias and introduces QDQ-specific reshaping/reordering logic. |
| onnxoptimizer/test/optimizer_test.py | Adds regression tests for non-constant bias fusion and QDQ bias fusion. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const bool is_input_qdq = | ||
| orig_bias->node()->kind() == Symbol("DequantizeLinear") && | ||
| orig_bias->node()->input(0)->node()->kind() == | ||
| Symbol("QuantizeLinear"); | ||
| if (orig_bias->node()->kind() != kParam && |
| if (bias_shape.size() > 1) { | ||
| std::vector<int64_t> axes(bias_shape.size() - 1); | ||
| std::iota(axes.begin(), axes.end(), 0); | ||
| Node *squeeze = makeSqueezeOrUnsqueeze(graph, axes, conv_3rd_input, | ||
| orig_conv->node(), kSqueeze); | ||
| Node *squeeze = makeSqueezeOrUnsqueeze( |
| if (orig_bias->node()->kind() != kParam && | ||
| orig_conv->node()->isBefore(orig_bias->node())) { | ||
| if (is_input_qdq) { | ||
| orig_bias->node()->input(0)->node()->moveBefore(orig_conv->node()); | ||
| } | ||
| orig_bias->node()->moveBefore(orig_conv->node()); | ||
| } |
| assert optimized_model.graph.output[0].name == 'C' | ||
|
|
||
| # type: () -> None | ||
| def test_fuse_add_bias_into_conv_with_quanted_bias(self): |
No description provided.