Fix element type mismatch in attention preSoftmax fusion#2211
Merged
justinrosner merged 6 commits intodevelopfrom Jan 29, 2026
Merged
Fix element type mismatch in attention preSoftmax fusion#2211justinrosner merged 6 commits intodevelopfrom
justinrosner merged 6 commits intodevelopfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a crash in MIGraphX when compiling attention kernels with preSoftmax fusion. The issue occurred when lowering gridwise_attention_accel operations where the gemm0 output buffer element type was incorrectly set to the values input element type (elemTypeV), causing a type mismatch when the preSoftmax body's linalg.generic operation expected a different element type (e.g., when truncating or extending).
Changes:
- Modified element type determination logic to walk the preSoftmax body and extract the correct type from the first
linalg.genericoperation's gemm0-based input - Added a comprehensive LIT test that reproduces the original MIGraphX failure scenario with type conversions in the preSoftmax fusion body
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| mlir/lib/Dialect/Rock/Transforms/GridwiseGemmToBlockwise.cpp | Added logic to walk preSoftmax body and determine gemmOutElemType from the first generic's gemm0-based input, and fusionOutElemType from the last generic's output, fixing the element type mismatch |
| mlir/test/Dialect/Rock/gridwise-gemm-linalg-failure.mlir | New test file verifying correct handling of attention operations with preSoftmax fusion that performs f16 to f32 extension, ensuring the lowering produces correct buffer types |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
dhernandez0
reviewed
Jan 28, 2026
Contributor
pabloantoniom
left a comment
There was a problem hiding this comment.
I second both of Daniel's comments
pabloantoniom
approved these changes
Jan 29, 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.
Motivation
This PR fixes a crash that MIGraphX was seeing when compiling an attention kernel with fusion: https://amd-hub.atlassian.net/browse/AIROCMLIR-438
Technical Details
When lowering
gridwise_attention_accelops with preSoftmax fusion, the gemm0 output buffer element type was unconditionally set toelemTypeV(the values input element type). This caused a type mismatch when the preSoftmax body'slinalg.genericexpected a different element type for it's gemm0 based input (e.g., when thelinalg.genericwas truncating/extending).Test Plan
Test Result
Submission Checklist