Conversation
[ROCm] Bug fix: ROCMAiterMLASparseBackend returns attn_out as 3D [num_tokens, num_heads, v_head_dim] instead of expected 2D [num_tokens, num_heads * v_head_dim]. Flatten before o_proj. Validated: GLM-5.1-FP8 on 8x MI300X (gfx942), TP=8 - PASS Signed-off-by: psakhamo <psakhamo@amd.com>
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.
[ROCm] Bug fix: ROCMAiterMLASparseBackend returns attn_out as 3D
[num_tokens, num_heads, v_head_dim] instead of expected 2D
[num_tokens, num_heads * v_head_dim]. Flatten before o_proj.
Validated: GLM-5.1-FP8 on 8x MI300X (gfx942), TP=8 - PASS
Purpose
Fixes a shape mismatch crash introduced by the ROCm AITER sparse MLA
backend (
ROCMAiterMLASparseBackend). Unlike the CUDA path, this backendreturns attention output as a 3D tensor
[num_tokens, num_heads, v_head_dim]instead of the expected 2D
[num_tokens, num_heads * v_head_dim].Without this fix, the unflattened tensor is passed directly into
o_proj,which expects a 2D input, causing a shape mismatch that surfaces as a
ValueErrorseveral layers later inDeepseekV2MoE.forward():num_tokens, hidden_dim = hidden_states.shape
ValueError: too many values to unpack (expected 2)
This was root-caused via runtime shape probes on 8× MI300X (gfx942) at TP=8,
where
hidden_statesentering every MoE layer was confirmed to be(num_tokens, 8, 6144)— 3D withnum_heads=8as the middle dimension.The fix adds a defensive reshape before
o_proj. It is a strict no-op for2D inputs (the normal CUDA/non-ROCm path) and has no effect on model weights,
KV cache, or any other tensor. Affected models: all models using MLA with the
ROCm AITER sparse backend (DeepSeek-V2/V3/R1, GLM-5).
Closes vllm-project#39168 (related — ROCm MLA head-repeat padding)
Test Plan
Test Result
Tested on: GLM-5.1-FP8 (
GlmMoeDsaForCausalLM, 744B MoE) on 8× AMD InstinctMI300X (gfx942), TP=8, vLLM v0.17.1 ROCm build, AITER enabled.
Before fix:
ValueError: too many values to unpack (expected 2)
File ".../vllm/model_executor/models/deepseek_v2.py", line 412
num_tokens, hidden_dim = hidden_states.shape
Server crashes immediately after attention forward pass.
After fix:
"content":"2+2 equals 4"returned correctlyfinish_reason="tool_calls"confirmed,tool_callsarray non-empty, bash(ls) function call routed correctlyNo regression observed on standard inference path (2D attn_out case unchanged).
Essential Elements of an Effective PR Description Checklist
BEFORE SUBMITTING, PLEASE READ https://docs.vllm.ai/en/latest/contributing