Repository navigation
[HIP] Fix out-of-bounds read in MLA metadata planner when head-folding - #6188
simondanielsson wants to merge 4 commits into
Conversation
Signed-off-by: simondanielsson <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
Signed-off-by: simondanielsson <[email protected]>
|
@aiter-bot review |
|
aiter-bot — queued behind 1 review(s); expect to start in about 50 min. The box reviews one PR at a time. |
[ROCm/aiter] PR #6188 — [HIP] Fix out-of-bounds read in MLA metadata planner when head-foldingTeaches the MLA metadata planner's per-batch q/o helper to map head-folded pseudo-batch ids back through the fold before indexing the caller's unfolded qo_indptr, so non-uniform decode on a folded shape (e.g. DSv3 TP1/DP8 bf16, 128 heads on gfx942) stops reading past the tensor's end and emits row offsets in the folded space the decode kernel consumes. Review (advisory): 🔴 HIGH RISK 🔴 [verified] The changed planner (csrc/kernels/mla/metadata/v1_comm.cuh) feeds the persistent mla_decode_fwd path that vLLM/SGLang/ATOM MLA decode consume — the PR's own reproducer is a vLLM DSv3-0324 DP8×TP1 bf16 run — yet the PR carries only the HIP label, so the label-gated vllm/atom/sglang downstream jobs all skip and only the in-repo unit test runs before merge. Author must add ci:vllm (or ci:all) and require the downstream job green before merge. |
|
Where that review came from — I ran the bot on your PR to show what it does. It is not an automatic hook; nothing reviews your PR unless somebody asks. Any reviewer on the aiter allowlist can ask for one, on any PR including their own. The trigger is a comment containing the words below — shown quoted here, because quoted lines deliberately do not trigger it:
Feedback on the review itself is welcome; it is how the rules get better. |
|
No activity for 15 days, so this is now labelled |
Motivation
When the MLA metadata planner "head-folds" with 128 heads it reads garbage/OOB from one its input tensors. This leads to garbage propagating to the attention output and increasing the probability of corrupt and gibberish output.
This PR fixes it by making the planner correctly "unfolding" the index back before using it.
Intuitively
DSv3 shapes with TP1 (and DP8) is not natively_supported by the MLA kernel on gfx942 (i.e. 128 heads). In these cases, it "folds" the heads into the batch dimension so it runs with 16 heads. Before you can correctly access the input after folding, one needs to unfold it.
So if you're on 128 heads, it converts it from
and there's a mapping
E.g. to get real batch
bidyou hence have to compute it asbid = pseudo_bid / foldsp_seqlens_qo_indptris not folded, so if you try to access this with these folded "pseudo-batches" you will read out of bounds. This is done in several places in the code already, but not in all places.Test Plan
1. Unit test
Run ok on this branch
It should fail on main:
Full sweep should be ok:
2. e2e test in vllm
We can see increased gibberish by running SpeedBench with a very large
max-output-tokensvalue set, as gibberish generation often leads to long tail generations (due to not properly generating eos)Run DPA:
Run Speedbench with max output tokens 16k;
Print out the longest generations and check quality of output:
Test Result
1. Unit test
This branch: succeeds
Main: errors
2. e2e test in vllm
Without fix: lots of random gibberish
With this branch: just non-english languages.
Submission Checklist