Skip to content

Fix DivMulFusion producer edge rewiring - #32430

Open
Sylvester Kaczmarek (sylvesterkaczmarek) wants to merge 2 commits into
microsoft:mainfrom
sylvesterkaczmarek:fix/div-mul-fusion-producer-edge
Open

Fix DivMulFusion producer edge rewiring#32430
Sylvester Kaczmarek (sylvesterkaczmarek) wants to merge 2 commits into
microsoft:mainfrom
sylvesterkaczmarek:fix/div-mul-fusion-producer-edge

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown
Contributor

Description

Fixes #32413, #32414 and #32416.

DivMulFusion rewrites 1 / x1 * x2 to x2 / x1 by replacing input 0 of the Div with the other Mul input. ReplaceNodeInput() only changes the NodeArg and intentionally does not create a graph edge.

When x2 is produced by another node, its producer edge still targets the Mul. FinalizeNodeFusion() then removes that edge with the Mul, leaving the new Div consuming a value without a producer edge. A later producer-elimination rule can remove the producer and leave an invalid graph.

This change adds the producer edge from the replacement input to the fused Div whenever the replacement input is node-produced. Graph inputs and initializers retain the existing behaviour.

Tests

Adds a regression graph with a node-produced Mul input and verifies the fused Div retains the producer connection and the graph resolves successfully.

Copilot AI balanced review requested due to automatic review settings September 3, 2026 19: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.

🟢 Approval recommended

The focused fix correctly preserves graph connectivity and includes adequate regression coverage.

Pull request overview

Fixes DivMulFusion graph rewiring so node-produced replacement inputs retain their producer edges.

Changes:

  • Adds the producer-to-fused-Div edge during rewiring.
  • Adds regression coverage validating edge preservation and graph resolution.
File summaries
File Description
onnxruntime/core/optimizer/div_mul_fusion.cc Preserves producer edges during fusion.
onnxruntime/test/optimizer/div_mul_fusion_test.cc Tests node-produced replacement inputs.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Balanced

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

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.

Basic optimization can produce invalid graph for Identity feeding folded Mul-one

3 participants