← Back to Pull requests

feat(musa): enable DFlash2 and DSpark2 by sizing the separate attention pool from layout strides #303

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Oct 22, 2026 11:55 UTC
Author

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 KVCacheTensor per layer slot and
sized 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_tensors into 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 with compute_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_block instead 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. MambaSpec state groups plus a single attention group are the
shape 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-series PASS, verify PASS, 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-config shown below. DFlash2 and DSpark2 run
num_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 resolves
LBNHC 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 C for each steady-state cell.

Launch commands

DFlash2 (replace <TARGET_MODEL> and <DFLASH2_DRAFT>/<DSPARK2_DRAFT> with
the checkpoint paths):

export VLLM_WORKER_MULTIPROC_METHOD=spawn PYTHONUNBUFFERED=1
export TRANSFORMERS_OFFLINE=1 HF_HUB_OFFLINE=1
export VLLM_MUSA_DFLASH_FULL_WRAP=0
unset MUSA_VISIBLE_DEVICES
python3 -m vllm.entrypoints.cli.main serve <TARGET_MODEL> \
  --served-model-name qwen38-dflash2 \
  --host 0.0.0.0 \ 
  --port 23654 \
  --trust-remote-code \
  --tensor-parallel-size 2 \
  --gpu-memory-utilization 0.90 \
  --max-model-len 24576 \
  --max-num-batched-tokens 4096 \
  --max-num-seqs 32 \
  --no-enable-prefix-caching \
  --compilation-config '{"mode":3,"cudagraph_mode":"FULL_AND_PIECEWISE","cudagraph_capture_sizes":[8,16,32,64],"max_cudagraph_capture_size":64,"compile_ranges_endpoints":[4096]}' \
  --speculative-config '{"model":"<DFLASH2_DRAFT>","method":"dflash","num_speculative_tokens":7}'

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 the
default compilation config.

Server startup (real log output)

DFlash2:

(Worker_TP1 pid=21060) INFO 10-22 00:49:58 [kv_cache_utils.py:1735] MUSA separated pool: attention_groups=5 mamba_groups=10 attention_blocks=32
(Worker_TP0 pid=21059) INFO 10-22 00:49:58 [kv_cache_utils.py:1735] MUSA separated pool: attention_groups=5 mamba_groups=10 attention_blocks=32
(EngineCore pid=20781) INFO 10-22 00:50:02 [kv_cache_utils.py:1735] MUSA separated pool: attention_groups=5 mamba_groups=10 attention_blocks=4328
2026-10-22 00:50:15 | platform | 140010442946368 | INFO : dflash draft capture default-on; coerced cudagraph_mode=FULL, capture_sizes=[8, 16, 32, 64] (block=8)
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     127.0.0.1:49878 - "GET /health HTTP/1.1" 200 OK

DSpark2:

(Worker_TP0 pid=25192) INFO 10-22 02:44:53 [kv_cache_utils.py:1735] MUSA separated pool: attention_groups=5 mamba_groups=10 attention_blocks=32
(EngineCore pid=24914) INFO 10-22 02:45:17 [kv_cache_utils.py:1735] MUSA separated pool: attention_groups=5 mamba_groups=10 attention_blocks=2835
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     127.0.0.1:52538 - "GET /health HTTP/1.1" 200 OK

attention_groups=5 is the line this patch adds; both drafts take the
multi-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 AR is the same-concurrency
improvement 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 is
allocated; allocate_kv_cache runs on torch.device("cpu")):

$ MUSA_VISIBLE_DEVICES=1 python3 -m pytest tests/test_musa_separated_pool_branching.py -q
9 passed in 8.42s

| Test | What it proves |
|---|---|
| test_separate_pool_needs_mamba_and_attention | Eligibility requires both a MambaSpec group 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 with size == 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_groups never 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

  • MUSA resolves LBNHC for the validated models; the BLHNC construction is

  • covered by the new unit test, not by a hardware run.
  • The benchmark acceptance metric is token-weighted (vllm bench serve); at

  • c=1 it equals the per-request metric.
  • Accuracy uses a 2048-token cap; ~5% of samples still hit it and are almost

  • all wrong, so 90.6-91.0% is a lower bound.
  • DSpark2 uses the latest ModelScope weights (sha256 2aff025f...), not the

  • older DSpark1 checkpoint.
  • DFlash2 and DSpark2 run their own default speculative configuration; their

  • per-step verify width and graph coverage differ (DFlash2 FULL up to 64
    tokens, DSpark2 FULL_AND_PIECEWISE up to 512), so the c8 cross-arm ordering
    is a default-configuration result.
  • MTP-3 (3 speculative tokens) is vLLM's recommended multi-step configuration;

  • its acceptance length (3.06 over 3 draft tokens, 68.7% rate) is not
    comparable with the 7-draft arms' acceptance length.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: yeahdongcn Review duration: 2957m
    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
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 27.7% · Safe to merge
    27.7%