Skip to content

Only push a transpose through a shared output when it can cancel. - #32868

Open
xiaohanAMD wants to merge 3 commits into
microsoft:mainfrom
xiaohanAMD:xiao.add_branch_case_check_for_cost
Open

xiaohanAMD wants to merge 3 commits into
microsoft:mainfrom
xiaohanAMD:xiao.add_branch_case_check_for_cost

Conversation

@xiaohanAMD

@xiaohanAMD xiaohanAMD commented Sep 28, 2026 •

Copy link
Copy Markdown

Description

The transpose optimizer now pushes a transpose through a shared output only when that permutation can be canceled.

The cost check used to treat any output that leads to a downstream Transpose as a benefit. A shared quantized value was pushed even when another branch could not cancel the permutation, which left an extra Transpose on that branch.

The benefit is counted only when:

the output has a single node consumer, or
a walk through nodes that can carry the transpose reaches a Transpose with the inverse permutation.
A graph output or subgraph input is not listed in GetValueConsumers::nodes (comprehensive == false). That use cannot cancel the permutation, so it blocks the benefit both on the value being pushed through and on any later value the walk would cross.

The tests cover a shared QDQ output, a graph output that shares the quantized value, and an intermediate graph output that sits on the only canceling path.

Motivation and Context

Pushing a transpose through a shared output duplicates it onto every consumer. When one consumer cannot cancel it, the optimized graph keeps a Transpose that the cost check expected to disappear. A graph output or subgraph input is the same kind of extra consumer, because the consumer list only includes nodes.

The cost check treated any output that leads to a transpose as a benefit, so a shared QDQ value was pushed even when another branch could not cancel the permutation. Count that benefit only for a single consumer or a path that reaches the inverse permutation.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copilot AI balanced review requested due to automatic review settings September 28, 2026 07:46
@azure-pipelines

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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Path feasibility and non-node consumers can still cause false cancellation benefits.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Refines transpose cost estimation so shared outputs are pushed only when a downstream transpose can cancel the permutation.

Changes:

  • Adds downstream cancellation-path analysis.
  • Adds regression coverage for branched QDQ graphs.
File Description
onnxruntime/​core/​optimizer/​transpose_optimization/​onnx_transpose_optimization.cc Refines transpose benefit calculation.
onnxruntime/​test/​optimizer/​transpose_optimizer_test.cc Tests shared QDQ output behavior.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@xiaohanAMD

Copy link
Copy Markdown
Author

Scott McKay (@skottmckay) mirounga
Edward Chen (@edgchen1) please review, thanks!

GetValueConsumers only lists node consumers, so a graph output or subgraph input was treated as a single consumer and the shared transpose was still pushed.

Co-authored-by: Cursor <cursoragent@cursor.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The path traversal can incorrectly count cancellation through intermediate graph outputs or implicit subgraph inputs.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
Resolved since last review (1)

The cost check already ignored a non-comprehensive consumer on the node output. A later value on the path could still be a graph output and was credited when a node consumer reached the inverse permutation.

Co-authored-by: Cursor <cursoragent@cursor.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The path analysis still credits transposes reached through EP-assigned nodes that the optimizer cannot modify.

Review effort: Balanced
Findings: None

Resolved since last review (1)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

The uncached graph traversal risks quadratic optimization time, and rank-changing branches lack focused coverage.

Review effort: Balanced
Findings: 1 Medium severity · 1 Low severity

Open (2)

@mirounga
mirounga self-requested a review September 28, 2026 14:49

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.

2 participants