Address PadFusion shortcomings#28780
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request hardens the PadFusion graph rewrite to avoid fusing invalid/malformed Pad configurations (especially around pads length/rank expectations), and adds regression tests to ensure the optimizer safely skips those cases without crashing.
Changes:
- Tightened
padsvalidation inPadFusion::Apply(minimum length, even length, and target nodepadslength compatibility). - Switched size/index types in
pad_fusion.ccfromuint32_ttosize_tand adjusted indexing accordingly. - Added new optimizer tests covering short/odd
pads, negativepads, and mismatched childpadsrank (including opset-10 attribute-form Pad).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| onnxruntime/core/optimizer/pad_fusion.cc | Adds stricter pads validation and guards to prevent unsafe fusion when Pad/target padding attributes are malformed or incompatible. |
| onnxruntime/test/optimizer/graph_transform_test.cc | Adds regression tests ensuring PadFusion safely bails out (no fusion, no crash) for multiple malformed pads edge cases. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
xadupre
approved these changes
Jun 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request improves the robustness and correctness of the PadFusion graph optimization in ONNX Runtime by tightening validation on the
padsattribute and adding comprehensive test coverage for edge cases. The changes ensure that PadFusion only applies when thepadsattribute meets ONNX specification requirements and that it safely handles malformed or unexpected input without crashing.PadFusion validation improvements:
padsattribute has at least four elements and an even length, as required by the ONNX Pad specification. If these conditions are not met, the fusion is skipped.padsattribute, its length matches the expected spatial rank implied by the Pad node. If not, the fusion is skipped to prevent mismatched padding.Code consistency and safety:
uint32_ttosize_tfor variables representing sizes and indices, improving type safety and consistency throughoutpad_fusion.cc. [1] [2]Test coverage enhancements:
padsattribute or initializer is too short or has an odd length.padsattribute contains negative values.padsattribute length does not match the spatial rank implied by the Pad node.padsattribute.