Uh oh!
There was an error while loading. Please reload this page.
Validate FastGelu fusion scale node - #32016
Conversation
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.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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).