Validate GQA fusion projection shapes - #32018
Merged
Akshay Sonawane (apsonawane) merged 3 commits intoAug 14, 2026
Merged
Conversation
Akshay Sonawane (apsonawane)
enabled auto-merge (squash)
August 12, 2026 07:09
Copilot started reviewing on behalf of
Akshay Sonawane (apsonawane)
August 12, 2026 07:14
View session
Contributor
There was a problem hiding this comment.
Pull request overview
This PR tightens the GroupQueryAttentionFusion preconditions by validating that Q/K/V projection initializers match the expected hidden sizes derived from GQA head attributes, and by adding overflow/validity guards around hidden size calculations. It also extends the existing GQA fusion test graph builder and adds a new unit test covering a mismatched-projection scenario to ensure fusion is skipped.
Changes:
- Added
ProjectionTensorShapesMatchand integrated it into the GQA fusion eligibility checks. - Added positivity and integer-overflow guards when computing
q_hidden_size,kv_hidden_size, andoutput_hidden_size. - Updated the rotary-embedding GQA fusion test graph builder to allow custom
num_heads, and added a regression test ensuring fusion is skipped when projection sizes don’t match head attributes.
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 projection shape validation and overflow-safe hidden size computations to gate the GQA fusion. |
| onnxruntime/test/optimizer/graph_transform_test_layernorm.cc | Extends the GQA fusion graph builder to parameterize head count and adds a test for mismatched projection sizes (fusion should be skipped). |
💡 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
Ti-Tai Wang (titaiwangms)
approved these changes
Aug 14, 2026
Akshay Sonawane (apsonawane)
deleted the
fix/gqa-fusion-weight-shape-validation
branch
August 14, 2026 17:35
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 strengthens the validation logic for Group Query Attention (GQA) fusion in ONNX Runtime by adding stricter shape checks for projection tensors and guarding against integer overflows in hidden size calculations. It also introduces a new unit test to ensure that the fusion is skipped when projection tensor shapes do not match the expected configuration.
Improved validation and error handling:
ProjectionTensorShapesMatchfunction to verify that the Q, K, and V projection tensor shapes match the expected dimensions based on quantization and head attributes. The fusion is skipped if the shapes do not match. [1] [2]q_hidden_size,kv_hidden_size, andoutput_hidden_size, ensuring all head attributes are positive and calculations are safe.<limits>for use ofstd::numeric_limitsin overflow checks.Testing enhancements:
GroupQueryAttentionFusionSkipsMismatchedProjectionSizesTest, to verify that fusion is correctly skipped when projection tensor sizes do not match the head attributes.