Skip to content

[Bugfix][Model] Fix MiMo-V2.5 fused fp8 qkv_proj sharding (pre-shard count is num_key_value_heads; MTP path too) - #57508

Merged
vllm-bot merged 8 commits into
vllm-project:mainfrom
EmbeddedLLM:mimo-v25-fp8-qkv-scale-grid
Sep 19, 2026
Merged

vllm-bot merged 8 commits into
vllm-project:mainfrom
EmbeddedLLM:mimo-v25-fp8-qkv-scale-grid

Conversation

@vllmellm

Copy link
Copy Markdown
Contributor

Purpose

XiaomiMiMo/MiMo-V2.5 cannot load on current main at any TP size.

Currently with TP4, on mi355x/mi300x we will hit this error.

File ".../vllm/model_executor/models/mimo_v2.py", line 527, in _shard_fp8_qkv_proj
    w_g_dequant = w_g * s_g_expanded
RuntimeError: The size of tensor a (1856) must match the size of tensor b (1792) at non-singleton dimension 0

This is not platform specific, so every platform that runs this checkpoint is affected.

The root cause is, the checkpoint's fused qkv_proj is pre-sharded at ckpt_tp = config.num_key_value_heads (4 here), each chunk holding [Q_c | K_c | V_c] with its own fp8 block scales, while _shard_fp8_qkv_proj (#45200) assumes one chunk per KV head. The assumption holds for Pro (8 KV heads / 8 chunks) and for V2.5's GA layers (4/4) — those load fine today — but not for the SWA layers: 8 KV heads over 4 chunks, so each chunk carries two KV heads.

Concretely, for model.layers.1.self_attn.qkv_proj:

  • weight (14848, 4096) = 4 chunks of 3072 Q + 384 K + 256 V = 3712 rows = 29 blocks exactly
  • weight_scale_inv (116, 32) = 4 × 29; the one-per-KV-head reading expects 8 × 15 = 120 and per-group-floor 112, so the loader's 116 // 8 = 14 expands to 1792 rows vs the 1856-row slice

For GA layers ((13568, 108), chunks of 3392 = 3072+192+128) and Pro ((27136, 216), 8 chunks of 3392) the pre-shard count happens to equal the KV-head count, which is why SWA breaks.

Change

  1. _shard_fp8_qkv_proj takes ckpt_tp (= config.num_key_value_heads, i.e. the number of ranks the checkpoint was pre-sharded into — 4 for MiMo-V2.5, 8 for Pro) and derives the chunk geometry from the layer's own heads/dims.
    • tp_size == ckpt_tp → plain chunk of weight and scales (the chunk already is [Q_r|K_r|V_r]; scale rows line up with ceil(rows/128));
    • otherwise gather each rank's Q/K/V head rows from the chunks that hold them, dequantize with the per-chunk scale mapping (row // rows_per_chunk) * ceil(rows_per_chunk/128) + (row % rows_per_chunk) // 128, reorder and requantize (zero-padding the 26.5-block tail, since scaled_quantize needs full blocks);
    • a scale tensor matching neither the per-chunk nor a continuous grid now raises instead of being dequantized with the wrong scale.
  2. TP > num_kv_heads (GA layers at TP=8) via KV replication, the same convention QKVParallelLinear uses for split checkpoints: rank r owns KV head r // (tp_size // num_kv_heads), so each Q head stays with the KV head it attends to.
  3. mimo_v2_mtp.py: the MTP draft loader sharded the fused qkv with a plain chunk(tp_size) for weight and scales. At TP=4 that is correct by coincidence, at TP=8 the scale chunks come out [15]*7 + [11] against a 15-row parameter (rank 7 asserts in default_weight_loader) and mid-block ranks take a neighbouring block's scale. It now buffers weight + weight_scale_inv per layer and shards them through _shard_fp8_qkv_proj with ckpt_tp = config.num_key_value_heads; non-fp8 fused checkpoints keep the old path.
  4. added tests/models/quantization/test_mimo_v2_qkv_shard.py: new CPU-only unit test. It builds GA, SWA and Pro checkpoints in the export's chunk layout with known fp32 weights and asserts, for TP = 1, 2, 4, 8, that every rank's dequantized rows match an independent reference; that tp_size == ckpt_tp returns the checkpoint chunk unchanged; and that reading the SWA scales as one slice per KV head is detectably wrong (relL2 > 5x tolerance).

For reference, #53242 fixes only the SWA symptom (global row map — exact for SWA, but it mis-scales 62.7% of GA rows and would mis-scale 81.4% of Pro's), and #46755 adds the TP > num_kv_heads case with per-KV-head scale arithmetic, which for V2.5's MTP tensors would compute 116 // 8 = 14 and break TP=4 spec decode that works today.

Test Plan

Non-spec, the reported configuration (TP=4) and TP=8 + EP:

vllm serve XiaomiMiMo/MiMo-V2.5 --trust-remote-code --generation-config vllm \
  --gpu-memory-utilization 0.9 --max-model-len auto --tensor-parallel-size 4 \
  --tool-call-parser mimo --enable-auto-tool-choice --reasoning-parser mimo

vllm serve XiaomiMiMo/MiMo-V2.5 --trust-remote-code --generation-config vllm \
  --gpu-memory-utilization 0.9 --max-model-len auto --tensor-parallel-size 8 \
  --enable-expert-parallel \
  --tool-call-parser mimo --enable-auto-tool-choice --reasoning-parser mimo

Spec decode (MTP), both TP sizes:

vllm serve XiaomiMiMo/MiMo-V2.5 --trust-remote-code --generation-config vllm \
  --gpu-memory-utilization 0.9 --max-model-len auto --tensor-parallel-size 4 \
  --speculative-config '{"method":"mimo_v2_mtp","num_speculative_tokens":1}' \
  --tool-call-parser mimo --enable-auto-tool-choice --reasoning-parser mimo
lm_eval --model local-chat-completions \
  --model_args model=XiaomiMiMo/MiMo-V2.5,base_url=http://127.0.0.1:8000/v1/chat/completions,num_concurrent=32,max_retries=10,max_length=32000,timeout=60000 \
  --gen_kwargs '{"max_tokens":16000,"until":[]}' --batch_size auto \
  --tasks gsm8k --num_fewshot 25 --apply_chat_template

Test Result

check before after
vllm serve ... --tensor-parallel-size 4 crash at load Server started, with sensible output
TP=8 (w/wo EP) AssertionError: TP size must evenly split the number of KV heads Server started, with sensible output
TP=4 + MTP spec (num_speculative_tokens=1) crash at load loads, draft acceptance ~95%
TP=8 + (w/wo) EP + MTP spec crash at load loads, draft acceptance 20703/21660 = 95.6%
GSM8K (TP=2/4/8) n/a (never loaded) ** around 0.9704 flex / 0.9712 strict ± 0.005**
real tensors at TP=4 (GA, SWA, MTP), relL2 vs independent reference crash 0.0000 (pure chunk); TP=1/2 ≤ 0.011; TP=8 GA 0.0000, SWA 0.008-0.011
TP=2 end-to-end crash Server started, with sensible output*
synthetic GA/SWA/Pro checkpoints, TP 1/2/4/8 crash / assert 0.026-0.028 (fp8 round-trip floor)
old reading (ckpt_tp = num_kv_heads) on SWA — detectably wrong: relL2 1.05

Essential Elements of an Effective PR Description Checklist
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.

… pre-shard count is num_key_value_heads

Signed-off-by: vllmellm <vllm.ellm@embeddedllm.com>
…qkv_proj

Signed-off-by: vllmellm <vllm.ellm@embeddedllm.com>
…c decode

Signed-off-by: vllmellm <vllm.ellm@embeddedllm.com>
…ometry checks

Signed-off-by: vllmellm <vllm.ellm@embeddedllm.com>
Signed-off-by: vllmellm <vllm.ellm@embeddedllm.com>

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@mergify mergify Bot added the bug Something isn't working label Sep 18, 2026

@tjtanaa tjtanaa left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

@tjtanaa tjtanaa added the ready ONLY add when PR is ready to merge/full CI is needed label Sep 18, 2026
@tjtanaa

tjtanaa commented Sep 18, 2026

Copy link
Copy Markdown
Member

/ci run

@github-actions

Copy link
Copy Markdown

✅ @vllmellm, CI is now available for this PR.

  • /ci run starts upstream CI; /amd-ci run starts AMD CI only.
  • Your branch must contain every commit currently on its upstream target branch. Merge or rebase onto the latest target branch, then rerun the command. Append --allow-stale to a run command to test an outdated branch at your own risk.
  • /ci retry retries failed jobs in the CI build for the current PR head. If the current head has no CI build, it starts a new CI build for the current head containing only jobs that failed in the latest earlier CI build for this PR.
  • /amd-ci retry retries failed jobs in AMD CI for the current PR head. Use /amd-ci run when the current head has no AMD CI build.
  • /ci cancel cancels scheduled or running CI builds for this PR branch; /amd-ci cancel does the same for AMD CI only.

@tjtanaa
tjtanaa enabled auto-merge (squash) September 18, 2026 08:07
@github-actions

Copy link
Copy Markdown

❌ This PR is 6 commits behind upstream main. Your branch must contain every commit currently on upstream main. No new CI build was started. Merge or rebase onto the latest main, then rerun /ci run. To test this branch at your own risk, use /ci run --allow-stale.

@vllmellm

Copy link
Copy Markdown
Contributor Author

/ci run

@github-actions

Copy link
Copy Markdown

✅ Triggered Buildkite CI #89804 for commit 6208e900bb43.

@vllmellm

Copy link
Copy Markdown
Contributor Author

/ci run

@github-actions

Copy link
Copy Markdown

✅ Triggered Buildkite CI #89847 for commit e27e1e602a73.

@vllmellm

Copy link
Copy Markdown
Contributor Author

/ci retry

@github-actions

Copy link
Copy Markdown

✅ Queued 6 failed job(s) for retry in Buildkite CI #89847.

@vllmellm

Copy link
Copy Markdown
Contributor Author

/ci retry

@github-actions

Copy link
Copy Markdown

✅ Queued 1 failed job(s) for retry in Buildkite CI #89847.

@vllm-bot
vllm-bot merged commit 211e252 into vllm-project:main Sep 19, 2026
136 of 138 checks passed
Malav-P pushed a commit to Malav-P/vllm that referenced this pull request Oct 1, 2026
…count is num_key_value_heads; MTP path too) (vllm-project#57508)

Signed-off-by: vllmellm <vllm.ellm@embeddedllm.com>
michael-gpu pushed a commit to practical-inference/vllm-ampere-extended that referenced this pull request Oct 20, 2026
…count is num_key_value_heads; MTP path too) (vllm-project#57508)

Signed-off-by: vllmellm <vllm.ellm@embeddedllm.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ready ONLY add when PR is ready to merge/full CI is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants