Validate FastGelu fusion scale node - #32016
Merged
Akshay Sonawane (apsonawane) merged 5 commits intoAug 14, 2026
Merged
Conversation
Akshay Sonawane (apsonawane)
enabled auto-merge (squash)
August 12, 2026 06:43
Copilot started reviewing on behalf of
Akshay Sonawane (apsonawane)
August 12, 2026 06:47
View session
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens the FastGeluFusion graph rewrite by adding input-count validation so malformed Mul/Pow nodes are skipped instead of being processed, and adds a regression test to ensure the fusion does not produce a com.microsoft.FastGelu node when the scale Mul is malformed.
Changes:
- Add
InputDefs().size() == 2/!= 2checks for keyMulandPownodes used by the FastGelu pattern matcher. - Fix the first-formula scale-mul validation to actually validate the upstream
Mulnode being inspected. - Add a unit test that mutates the FastGelu test model to create a malformed scale
Muland verifies fusion is skipped.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| onnxruntime/core/optimizer/fast_gelu_fusion.cc | Adds stricter input-count validation in FastGelu pattern matching to avoid processing malformed nodes. |
| onnxruntime/test/optimizer/graph_transform_test.cc | Adds a regression test that forces a malformed scale Mul and checks the fusion optimizer does not emit com.microsoft.FastGelu. |
Suppressed comments (1)
onnxruntime/core/optimizer/fast_gelu_fusion.cc:122
- Similar to the
pow1_node.InputDefs().size() != 2guard, the rest ofCheckSecondFormulaassumes intermediate nodes have 2 inputs and thatIndexOfNodeInputreturns a valid index before using[(input_index + 1) % 2](e.g., the checks around lines 135-138 and 174-177). For malformed graphs this can still access out-of-range inputs or match the wrong operand whenIndexOfNodeInputreturns-1. Consider addingInputDefs().size() == 2andinput_index >= 0guards before all modulo-based input indexing so the fusion always fails safely.
if (!graph_utils::IsSupportedOptypeVersionAndDomain(pow1_node, "Pow", {7, 12, 13, 15}) ||
pow1_node.InputDefs().size() != 2 ||
!graph_utils::IsSupportedProvider(pow1_node, GetCompatibleExecutionProviders()) ||
pow1_node.GetOutputEdgesCount() != 1 ||
!IsSupportedDataType(pow1_node)) {
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Ti-Tai Wang (titaiwangms)
previously approved these changes
Aug 13, 2026
Justin Chu (justinchuby)
approved these changes
Aug 14, 2026
Akshay Sonawane (apsonawane)
deleted the
fix/fast-gelu-fusion-node-validation
branch
August 14, 2026 14:24
Tianlei Wu (tianleiwu)
pushed a commit
that referenced
this pull request
Aug 17, 2026
This was referenced Aug 19, 2026
Closed
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.
This pull request improves the robustness of the FastGelu fusion optimization by ensuring malformed nodes are properly skipped and adds a test to verify this behavior. The main changes include stricter input validation in the fusion logic and a new unit test.
Fusion logic improvements:
InputDefs().size()) inMulandPownodes within theFastGeluFusionoptimizer to ensure only well-formed nodes are considered for fusion. [1] [2] [3]Testing enhancements:
FastGeluFusionSkipsMalformedScaleMul, that modifies a model to create a malformedMulnode and verifies that the fusion optimizer correctly skips it (i.e., does not produce aFastGelunode).