Skip to content

Avoid transpose optimizer if pushing transpose doesn't finally cancel with another transpose - #32704

Closed
xiaoh-amd (xiaoh-amd) wants to merge 1 commit into
microsoft:rel-1.27.0from
xiaoh-amd:fix_transpose_opt_no_cancellation
Closed

xiaoh-amd (xiaoh-amd) wants to merge 1 commit into
microsoft:rel-1.27.0from
xiaoh-amd:fix_transpose_opt_no_cancellation

Conversation

@xiaoh-amd

@xiaoh-amd xiaoh-amd (xiaoh-amd) commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary
Stop the transpose optimizer from pushing a Transpose through an op when that move does not actually cancel a later Transpose.

Stock ORT treats “any downstream Transpose” as a reason to push. Two Transposes cancel only when their perms are inverses (both disappear). They merge when the perms compose into a remaining Transpose. For a shared Transpose, a merge does not remove the original node, so the graph is not simpler and QDQ layout can be broken.

Behavior
Cost model: waive the cost of a Transpose inserted on the output only if a downstream Transpose would cancel the pushed perm, or the incoming Transpose has a single consumer (merge still drops a node). A shared Transpose that would only merge is not pushed.

QDQ guard: if a Transpose already sits in a complete DQ → Transpose → Q unit, do not push it through that Q unless the relocated Transpose would cancel downstream. Dead-end branches (no Transpose) are allowed when cancellation happens on another branch, because the relocated Transpose can stay on those branches.

Test plan
TestSliceSharedTransposeCancel / TestSliceSharedTransposeNoCancel / TestSliceUnsharedTransposeNoCancel
TestQDQSharedTransposeSliceCancel / TestQDQSharedTransposeSliceNoCancel
TestQDQTransposeNotPushedThroughOwnQ
TransposeOptimizerTests (171 tests) pass on the v1.27.0 build.
image

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

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.

1 participant