[ROCm][Perf] Fold scalar KV scales in MiniMax-M3 sparse attention - #52060
Open
akii96 wants to merge 1 commit into
Open
[ROCm][Perf] Fold scalar KV scales in MiniMax-M3 sparse attention#52060akii96 wants to merge 1 commit into
akii96 wants to merge 1 commit into
Conversation
akii96
marked this pull request as ready for review
August 13, 2026 04:18
akii96
requested review from
dllehr-amd,
hongxiayang and
tjtanaa
as code owners
August 13, 2026 04:18
4 tasks
akii96
force-pushed
the
perf/triton-sparse-kv-scale-folding
branch
from
August 19, 2026 21:47
c8bcfb6 to
77c69c7
Compare
akii96
force-pushed
the
perf/triton-sparse-kv-scale-folding
branch
from
August 19, 2026 21:48
77c69c7 to
8bc3023
Compare
Signed-off-by: Aakif Nawaz <aakif.nawaz@amd.com>
akii96
force-pushed
the
perf/triton-sparse-kv-scale-folding
branch
from
August 19, 2026 22:00
8bc3023 to
61bbbba
Compare
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.
Purpose
MiniMax-M3 Triton sparse attention currently applies scalar FP8 KV scales to every K and V element loaded inside the attention loop. These scales are loop invariant, so the repeated conversions and multiplications add unnecessary work.
Suggested Fix
For scalar scales (
KV_SCALE_MODE == 1), fold the K scale into the attention score scale and apply the V scale once to the normalized FP32 accumulator.The change covers AMD prefill, common prefill, and common decode. No-scale and per-token/head scale modes remain unchanged through the existing compile-time dispatch.
Test Plan
Compares scalar and per-token/head FP8 KV-cache outputs against a dequantized BF16 reference for both prefill and decode.
Serve command
Test Result
Kernel accuracy: 4/4 passed (scalar + per-token/head, prefill + decode).
End-to-end serving on 4x MI325X (gfx942), TP4,
EmbeddedLLM/MiniMax-M3-FP8-dynamic, FP8 KV cache: