Skip to content

Fix fuse_pad_into_conv incorrectly fusing when Pad contains negative values#2841

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-negative-pad-values
Draft

Fix fuse_pad_into_conv incorrectly fusing when Pad contains negative values#2841
Copilot wants to merge 2 commits intomainfrom
copilot/fix-negative-pad-values

Conversation

Copy link
Contributor

Copilot AI commented Mar 4, 2026

The fuse_pad_into_conv optimization would fuse a Pad node into Conv even when pads contained negative values (valid for Pad as crop operations, but invalid for Conv's pads attribute), producing an invalid model.

Changes

  • _fuse_pad_into_conv.py: Added a guard in _FuseConvPadBase.check() to bail out when any computed pad value is negative, preventing fusion that would produce an invalid Conv node:
    if any(p < 0 for p in self._pads_list):
        return check_result.fail(f"{pads.name} must not contain negative values.")
  • _fuse_pad_into_conv_test.py: Added a test case to test_unsupported_fuse_pad_into_conv verifying that fusion is rejected when spatial pads are negative.
Original prompt

This section details on the original issue you should resolve

<issue_title>fuse_pad_into_conv optimization incorrectly fuses when 'pads' contain negative values</issue_title>
<issue_description>converting the attached ONNX model with the following script:

from onnxscript import ir
from onnxscript.optimizer import optimize

ir_model = ir.load("input.onnx")
optimized_model = optimize(ir_model)
ir.save(optimized_model, "output.onnx")

results in the following output model:

Image

The Conv layer has negative pad values, which is not allowed per spec. This optimization should check for negative pad values.

input.onnx.zip

versions of relevant packages:

ml_dtypes         0.5.4
onnx              1.20.1
onnx-ir           0.1.16
onnxscript        0.6.2
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix optimization to handle negative pad values in Conv layer Fix fuse_pad_into_conv incorrectly fusing when Pad contains negative values Mar 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

fuse_pad_into_conv optimization incorrectly fuses when 'pads' contain negative values

2 participants