Draft
Skip GroupQueryAttentionFusion when GQA node has inputs beyond sin_cache#29552
Conversation
Copilot
AI
changed the title
[WIP] Fix invalid graph issue in GroupQueryAttentionFusion with more than 9 inputs
Skip GroupQueryAttentionFusion when GQA node has inputs beyond sin_cache
Jul 5, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses a graph validity/correctness issue in the CUDA L2 optimizer GroupQueryAttentionFusion: the fusion rewrites a com.microsoft.GroupQueryAttention node to a fixed 9-input form (up to sin_cache), which can invalidate the graph and/or drop semantics when the original node includes optional inputs beyond sin_cache (e.g., attention_bias).
Changes:
- Skip
GroupQueryAttentionFusionwhen the matched GQA node has an optional input beyondsin_cache(input index ≥ 9). - Add a regression test ensuring the fusion does not fire (and the graph remains resolvable) for a bias-carrying GQA model.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| onnxruntime/core/optimizer/group_query_attention_fusion.cc | Adds a guard to skip fusion when optional inputs beyond sin_cache are present on the GQA node. |
| onnxruntime/test/optimizer/graph_transform_test_layernorm.cc | Adds a unit test verifying the fusion is not applied for a GQA node with attention_bias and that graph.Resolve() succeeds. |
Comment on lines
+313
to
+320
| const auto& node_input_defs = node.InputDefs(); | ||
| bool has_unsupported_optional_input = false; | ||
| for (size_t i = 9; i < node_input_defs.size(); ++i) { | ||
| if (node_input_defs[i] != nullptr && node_input_defs[i]->Exists()) { | ||
| has_unsupported_optional_input = true; | ||
| break; | ||
| } | ||
| } |
This was referenced Jul 14, 2026
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.
Description
GroupQueryAttentionFusion(CUDA-EP L2) rewrites a matched GQA node's inputs to a fixed 9-element list (up tosin_cache, input #8) but only fixes up the arg-count entries for inputs 7 and 8. When the node carries an optional input beyondsin_cache—position_ids(#9),attention_bias(#10),head_sink(#11) — the arg-count array keeps stale entries for the truncated slots, soGraph::Resolvefails at session creation:The fusion also silently drops those inputs, so patching only the count array would still produce a node that computes the wrong result.
group_query_attention_fusion.cc: InApplyImpl, skip fusion for any GQA node with a bound input def at index ≥ 9. Chosen over "preserve + resize" since inputs likeattention_biasaren't reproducible in the fused node.graph_transform_test_layernorm.cc: AddTestGQAFusionNotApplied(wired intoGroupQueryAttentionFusionTest) asserting the fusion does not fire (bothRotaryEmbeddingnodes preserved) and the graph still resolves.gqa_fusion_with_attention_bias.onnx: New test model carryingattention_biasat input Hecli/cuda9.1 #10, derived fromgqa_fusion_quantized_simple.onnx.Motivation and Context
Affected models (e.g.
onnx-community/Voxtral-Mini-4B-Realtime-2602-ONNX, whose audio encoder expresses bidirectional attention viaattention_bias) fail to load on the CUDA EP at default optimization level, while loading fine withGroupQueryAttentionFusiondisabled or atbasicoptimization — a silent CUDA-only regression. Related: #29506 (CUDA GQA kernel also rejectsattention_bias; both are needed before bias-carrying GQA models run on CUDA).