Repository navigation
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
Closed
xiaoh-amd (xiaoh-amd) wants to merge 1 commit into
xiaoh-amd (xiaoh-amd) wants to merge 1 commit into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
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.
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.