Skip to content

[Fix][Relax] Normalize squeeze axes before layout inference - #20773

Open
Edwardssss wants to merge 1 commit into
apache:mainfrom
Edwardssss:fix/squeeze-negative-axis-layout
Open

Edwardssss wants to merge 1 commit into
apache:mainfrom
Edwardssss:fix/squeeze-negative-axis-layout

Conversation

@Edwardssss

Copy link
Copy Markdown

Description

Fixes #20422.

InferLayoutSqueeze uses the squeeze axes to index a rank-sized axis mask. Previously, explicit negative axes were used without normalization. This can index outside the mask and cause undefined behavior during ConvertLayout, including the reported allocation failure. Structural inference normalizes its own local axes but does not rewrite the original operator attributes, so that
normalization does not protect layout inference.

Normalize explicit axes with the existing NormalizeAxes helper using the logical input rank before constructing the layout mask. This preserves existing axis validation and leaves omitted-axis handling and blocked-layout fallback behavior unchanged. The fix applies to Relax directly as well as ONNX-imported graphs, rather than special-casing the importer.

Test

Extend the existing squeeze layout tests with negative and mixed-sign axes, including blocked-layout fallback. Add coverage for a squeeze without layout changes, omitted and empty axes, and a channel squeeze remapped from NCHW to NHWC. The channel test explicitly checks the resulting axis is 3.

@Edwardssss Edwardssss changed the title [Relax] Normalize squeeze axes before layout inference [Fix][Relax] Normalize squeeze axes before layout inference Oct 17, 2026

This branch has not been deployed

No deployments
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.

[Bug] Onnx frontend can import invalid squeeze axis

1 participant