Skip to content

support fusing non constant bias into conv#37

Open
daquexian wants to merge 3 commits into
mainfrom
support_fuse_non_constant_bias
Open

support fusing non constant bias into conv#37
daquexian wants to merge 3 commits into
mainfrom
support_fuse_non_constant_bias

Conversation

@daquexian
Copy link
Copy Markdown
Member

No description provided.

Signed-off-by: daquexian <daquexian566@gmail.com>
Signed-off-by: daquexian <daquexian566@gmail.com>
@daquexian daquexian force-pushed the support_fuse_non_constant_bias branch from ec8ff8e to 8e3c881 Compare April 4, 2021 10:14
@andife
Copy link
Copy Markdown
Member

andife commented May 26, 2026

@copilot resolve the merge conflicts in this pull request

Copilot AI requested review from a team as code owners May 26, 2026 18:40
Copy link
Copy Markdown
Contributor

Copilot AI commented May 26, 2026

@copilot resolve the merge conflicts in this pull request

Merge conflicts resolved in commit 79b0565. The source files (fuse_add_bias_into_conv.h and optimizer_test.py) auto-merged cleanly; the only manual resolution needed was the third_party/onnx submodule conflict, which was resolved by using the version from origin/main.

Copilot finished work on behalf of andife May 26, 2026 18:40
Copilot AI requested a review from andife May 26, 2026 18:40
@andife andife requested a review from Copilot May 26, 2026 18:41
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 QuantizeLinearDequantizeLinear (QDQ) chain.

Changes:

  • Relaxed fusion constraints in FuseAddBiasIntoConv to 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.

Comment on lines +170 to 174
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 &&
Comment on lines 133 to +136
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(
Comment on lines 174 to 180
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):
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants