feat(musa): enable DFlash2 and DSpark2 by sizing the separate attention pool from layout strides #303
All Vouch review confidence checks passed
Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #303"
general
weight: 0.35
yeahdongcn
Summary
This change enables DFlash2 and DSpark2 speculative decoding on MUSA. Their
drafts own an attention cache, which the MUSA separate Mamba/attention pool
could not describe: it built one attention
KVCacheTensorper layer slot andsized every slot from a single uniform page. That is only well
defined when the whole model has one attention KV cache group.
A speculative-decoding draft that owns its own attention cache adds a second
attention group with a different page size. DFlash2 and DSpark2 on Qwen3.8
produce five attention groups (10 Mamba groups). The per-slot scheme then
listed several layers at one pool stride, the KV view ran past its tensor, and
startup failed with
setStorage: sizes [5, 8, 2, 64, 1024] ... requiring.65865728 ... storage 13484032
This change keeps the existing per-slot construction for the single-group case
and only switches to a layout-stride construction when more than one attention
group exists. Both drafts then start and serve on 0.32.0.
Changes
| File | Change | Why | Problem avoided |
|---|---|---|---|
|
vllm/v1/core/kv_cache_utils.py| Split_musa_separated_mamba_attn_tensorsinto a single-group branch and a multi-group branch | One uniform page per slot cannot describe groups with different page sizes | Startup failure from the KV view overrunning its storage (setStorage) || same | Single-group branch keeps the exact pre-change tensors (
size == layer_stride,offset = 0, one layer per tensor) | Every model that works today (no speculation, MTP, non-spec hybrid) must be byte-identical | Silent capacity or layout drift for the models already shipping || same | Multi-group branch:
validate_kv_cache_layout,_get_kv_cache_bytes_per_block, per-group tensor sized to the whole attention pool, groups aliasing from byte 0, layers bucketed by spec and laid out withcompute_layout_strides| Only the resolved layout strides can express several page sizes and several layers per tensor | Multi-group attention KV that is either too small (crash) or wrongly aliased (corrupt state) || same | Block-outermost stride uses
attn_bytes_per_blockinstead of the whole pool size | A block stride is the distance between blocks, not between pools | BLHNC views addressed past the first block; the new test caught it (MUSA resolves LBNHC today, so the live path was unaffected) || same | New log line
MUSA separated pool: attention_groups=%d mamba_groups=%d attention_blocks=%d| The branch decision and pool size must be visible in startup logs | Silent fallback to the wrong branch ||
vllm/v1/worker/utils.py|allocate_kv_cache: attention groups share one attention buffer, gated on the attention-group count (>1) rather than on layers per tensor; Mamba tensors and the single-group per-slot tensors keep their own buffers | Multi-group tensors alias one attention pool from byte 0; keying on layer count would give a one-layer-per-group model one full pool buffer per group | Duplicated attention pools (startup OOM when the second full pool is allocated), and block-id aliasing across groups ||
tests/test_musa_separated_pool_branching.py| Six CPU test functions (nine cases) pinning the dispatch and buffer-sharing decisions | The gating is the risky part; it needs executable proof | A future edit routing non-spec models into the new path, or spec models out of it |Why the single-group case is kept, not generalised
The layout-stride path is only needed when the attention layers do not all live
in one group.
MambaSpecstate groups plus a single attention group are theshape every MUSA hybrid model has today; rewriting that path would change
allocation for models with no reported problem. The narrow gate was validated
by comparing KV capacity against a pristine 0.32.0 tree:
| model / config | pristine 0.32.0 | this patch |
|---|---:|---:|
| MTP, 4096 blocks / max-num-seqs 8 | 140425 | 140425 |
| Qwen3.8, 24576 / 32 | 128214 | 128214 |
| Qwen3.5-4B, 24576 / 32 | 501056 | 501056 |
The multi-group path is taken only by a draft that owns its attention cache
(DFlash2/DSpark2), never by MTP or by a non-speculative model. Observed in the
four-arm run:
attention_groups= 1 (AR), 1 (MTP), 5 (DFlash2), 5 (DSpark2).Validation
Environment and protocol
Hardware: one node with 2x MTT S5000, driver 5.2.0-server; the MUSA vLLM image
(vLLM 0.32.0, torch 2.11.0.post2, MUSA SDK 5.2.0) with the 55-entry MUSA
series (
musa_sync check-seriesPASS,verifyPASS, cumulative replay 55/55).Server flags for every arm: TP2, Qwen3.8-27B FP8 target,
max-model-len 24576,max-num-batched-tokens 4096,max-num-seqs 32, prefix caching off, the--compilation-configshown below. DFlash2 and DSpark2 runnum_speculative_tokens 7; MTP runs vLLM's recommended multi-step configuration{"method":"mtp","num_speculative_tokens":3}.DSpark2 uses the latest ModelScope weights (sha256
2aff025f...). MUSA resolvesLBNHC for all of them.
Client:
vllm bench serve, GSM8K 128-prompt custom dataset(
reasoning_effort="xhigh"),temperature 1.0 / top_p 0.95 / top_k 20,max_tokens 512,--num-warmups Cfor each steady-state cell.Launch commands
DFlash2 (replace
<TARGET_MODEL>and<DFLASH2_DRAFT>/<DSPARK2_DRAFT>withthe checkpoint paths):
DSpark2 is the same command with two substitutions: the draft becomes
{"model":"<DSPARK2_DRAFT>","method":"dspark","num_speculative_tokens":7},and the compilation config keeps the default capture mode
{"mode":3,"cudagraph_mode":"FULL_AND_PIECEWISE","compile_ranges_endpoints":[4096],"max_cudagraph_capture_size":512}.MTP is the same command with vLLM's recommended multi-step setting
--speculative-config '{"method":"mtp","num_speculative_tokens":3}'and thedefault compilation config.
Server startup (real log output)
DFlash2:
DSpark2:
attention_groups=5is the line this patch adds; both drafts take themulti-group branch, and neither startup reports a storage overrun.
Performance by concurrency (GSM8K 128 prompts, steady state)
Steady-state cells (warmup = C for cells flagged by the first-wave audit,
1 otherwise).
vs ARis the same-concurrencyimprovement over the AR row; a negative latency percentage is an improvement.
Timing columns are mean / p99 in ms.
C = 1
| arm | tok/s | vs AR | TTFT mean / p99 | TPOT mean / p99 | TPOT vs AR | E2E mean / p99 | acc len | acc rate |
|---|---:|---|---:|---:|---|---:|---:|---:|
| AR | 47.6 | - | 140.9 / 132.0 | 20.47 / 20.53 | - | 4725 / 5359 | - | - |
| MTP-3 | 92.5 | 1.94x (+94%) | 114.7 / 158.5 | 10.25 / 12.50 | -49.9% (2.00x lower) | 2444 / 3372 (-48.3%) | 3.06 | 68.7% |
| DFlash2 | 116.0 | 2.44x (+144%) | 135.9 / 147.1 | 7.95 / 11.13 | -61.2% (2.57x lower) | 1942 / 2967 (-58.9%) | 4.42 | 48.9% |
| DSpark2 | 113.0 | 2.37x (+137%) | 102.8 / 194.1 | 8.30 / 12.59 | -59.5% (2.47x lower) | 2020 / 3311 (-57.2%) | 4.40 | 48.6% |
C = 8
| arm | tok/s | vs AR | TTFT mean / p99 | TPOT mean / p99 | TPOT vs AR | E2E mean / p99 | acc len | acc rate |
|---|---:|---|---:|---:|---|---:|---:|---:|
| AR | 283.0 | - | 163.9 / 257.0 | 26.74 / 27.82 | - | 6189 / 7215 | - | - |
| MTP-3 | 529.3 | 1.87x (+87%) | 189.9 / 498.2 | 13.93 / 17.70 | -47.9% (1.92x lower) | 3356 / 4698 (-45.8%) | 3.07 | 68.9% |
| DFlash2 | 513.3 | 1.81x (+81%) | 264.7 / 356.5 | 13.90 / 21.10 | -48.0% (1.92x lower) | 3399 / 5625 (-45.1%) | 4.41 | 48.7% |
| DSpark2 | 529.6 | 1.87x (+87%) | 222.1 / 383.9 | 13.63 / 19.99 | -49.0% (1.96x lower) | 3345 / 5340 (-45.9%) | 4.20 | 45.7% |
C = 32
| arm | tok/s | vs AR | TTFT mean / p99 | TPOT mean / p99 | TPOT vs AR | E2E mean / p99 | acc len | acc rate |
|---|---:|---|---:|---:|---|---:|---:|---:|
| AR | 741.0 | - | 325.3 / 578.9 | 38.94 / 44.52 | - | 9052 / 11075 | - | - |
| MTP-3 | 884.4 | 1.19x (+19%) | 371.4 / 552.4 | 32.24 / 52.57 | -17.2% (1.21x lower) | 7666 / 13363 (-15.3%) | 3.06 | 68.6% |
| DFlash2 | 1021.3 | 1.38x (+38%) | 457.8 / 620.7 | 26.54 / 37.06 | -31.8% (1.47x lower) | 6475 / 9971 (-28.5%) | 4.43 | 49.0% |
| DSpark2 | 1013.5 | 1.37x (+37%) | 449.9 / 585.5 | 26.93 / 45.21 | -30.8% (1.45x lower) | 6611 / 11959 (-27.0%) | 4.34 | 47.8% |
The gain at c1/c8 comes from a much lower TPOT; at c32 the extra verify work
also raises mean TTFT (+14% MTP, +41% DFlash2, +38% DSpark2) and p99 rises a
little for the drafts (DFlash2 +7%, DSpark2 +1%), while E2E still drops 15-29%.
Full GSM8K accuracy (1319, temperature 0, 2048-token cap)
| arm | correct / 1319 | accuracy | vs AR |
|---|---:|---:|---:|
| AR | 1195 | 90.60% | - |
| DFlash2 | 1200 | 90.98% | +0.38 pp |
| DSpark2 | 1196 | 90.67% | +0.07 pp |
Every run completed 1319/1319 requests. About 5% of samples still hit the cap
and are almost all wrong, so the table is a lower bound. MTP was not part of the
accuracy run.
Dispatch tests
tests/test_musa_separated_pool_branching.py, CPU only (no GPU tensor isallocated;
allocate_kv_cacheruns ontorch.device("cpu")):| Test | What it proves |
|---|---|
|
test_separate_pool_needs_mamba_and_attention| Eligibility requires both aMambaSpecgroup and an attention group: attention-only models and attention-free Mamba models never reach the MUSA split ||
test_single_attention_group_keeps_per_slot_tensors| One attention group (non-spec hybrid / MTP) keeps one layer per tensor withsize == layer_stride,offset == 0||
test_single_group_allocation_keeps_one_buffer_per_layer| The single-group path still gets one buffer per layer tensor ||
test_two_attention_groups_take_layout_path[BLHNC-2/BLHNC-4/LBNHC-2]| A second attention group takes the layout path in both layouts, with and without a page-size difference: whole-pool tensors, groups alias from byte 0, every layer view stays inside its tensor, one shared attention buffer, Mamba buffer separate ||
test_single_layer_attention_groups_share_one_buffer[BLHNC/LBNHC]| Two one-layer attention groups still alias one buffer (the gate counts groups, not layers), so a second group cannot allocate a second full pool ||
test_attention_only_model_never_reaches_musa_builder|get_kv_cache_config_from_groupsnever calls the MUSA builder without Mamba state (the builder is replaced by a raising stub) |The BLHNC case exposed the block-outermost stride defect; after the fix all
three variants pass. LBNHC is covered as well, which is the layout MUSA resolves
for these models, so the hardware path has an equivalent unit test.
Notes and limitations
LBNHCfor the validated models; theBLHNCconstruction iscovered by the new unit test, not by a hardware run.
vllm bench serve); atc=1 it equals the per-request metric.
all wrong, so 90.6-91.0% is a lower bound.
2aff025f...), not theolder DSpark1 checkpoint.
per-step verify width and graph coverage differ (DFlash2
FULLup to 64tokens, DSpark2
FULL_AND_PIECEWISEup to 512), so the c8 cross-arm orderingis a default-configuration result.
its acceptance length (3.06 over 3 draft tokens, 68.7% rate) is not
comparable with the 7-draft arms' acceptance length.