Skip to content

[MUSA] fa3: per-attention-window AOT scheduler metadata (opt-in) - #314

Draft
yeahdongcn wants to merge 3 commits into
v0.32.0-devfrom
feat/musa-fa3-capability-align
Draft

yeahdongcn wants to merge 3 commits into
v0.32.0-devfrom
feat/musa-fa3-capability-align

Conversation

@yeahdongcn

@yeahdongcn yeahdongcn commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Why

MUSA's FA3 builder can hold only one AOT scheduler-metadata tensor, so a model that
mixes full attention with sliding-window attention loses the prebuilt split plan
for every layer. _get_sliding_window_configs() sees more than one config and
the builder answers by disabling AOT scheduling model-wide:

elif len(sliding_window_configs) > 1:
    self.aot_schedule = False

That hits every hybrid full + SWA checkpoint we support: gemma2 / gemma3 / gemma4,
gpt-oss, llama4 iRoPE, minimax_m2, plamo3 (arbitrary window list), modernbert. A
gemma4 layer whose window is (-1, -1) runs exactly the same attention problem as a
dense model's layer, but it still pays the wrapper-side heuristic because a different
layer in the same model has a window.

The two schedules are genuinely not interchangeable — the window bounds the visible KV
blocks, hence num_n_blocks, hence the split count — so the fix is one slot per
attention kind, not one slot for all of them. This mirrors what SGLang did for MUSA FA3
in sgl-project/sglang#46834 (per-kind scheduler-metadata slots, fail-fast instead of
fallback, per-window graph buffers) and is the first step of aligning our backend with
that capability set.

What

  • _normalize_attention_window() / _get_attention_window_layouts(): enumerate one
    layout per distinct paged-KV attention window, full attention first, normalized and
    de-duplicated. Encoder-only / encoder layers are excluded: they never read a KV-cache
    schedule, and their per-layer window would otherwise look like a distinct decoder kind.
  • FlashAttentionMetadata.kind_scheduler_metadata + scheduler_metadata_for(window):
    the builder fills one schedule per window; each FlashAttentionImpl reads the slot that
    matches its own sliding_window. A window that is missing from a populated map resolves
    to None, i.e. MATE derives a schedule inside the wrapper (slower, always correct) —
    never another window's plan.
  • CUDA graph: one persistent buffer per window, allocated on the first AOT build (i.e.
    before capture), so recorded FULL graphs read a fixed address exactly like the primary
    slot does today.
  • Qwen direct-decode-schedule path (_use_musa_qwen_direct_decode_schedule) hands every
    layer the same prebuilt schedule, so it now requires a single-window model.
  • DCP keeps its previous single-slot behaviour: _forward_with_dcp builds one two-sided
    schedule for one window and every layer reads it, so a window-mixed batch still keeps
    AOT off rather than silently feeding SWA layers a full-attention plan.
  • The per-window path is opt-in via VLLM_MUSA_FA3_AOT_PER_WINDOW=1. The default is
    bit-for-bit the current behaviour (see the measurement below for why).

Evidence

Correctness (CPU, in the v0.32.0 prebuilt container)

tests/test_flash_attn_scheduler_metadata_kinds.py    25 passed   (new)
+ tests/test_flash_attn_scheduler_fast_path.py
+ tests/jit_kernel/test_fa3_metadata.py               93 passed, 60 skipped

The new suite covers window normalization, dedup + full-first ordering, encoder
exclusion, the opt-in gate, "one schedule per window" (distinct data_ptrs), single-window
models keeping the upstream fast path, DCP, cascade, fast/spec builds, per-window graph
buffers (device address preserved, tail zeroed, rewritten in place), the selection matrix,
and the three forward paths that consume a schedule (decode fast path, paged varlen,
layer whose window is absent).

Two pre-existing failures reproduce identically with the pristine v0.32.0-dev file and
are unrelated: test_flash_attn_dcp.py::test_forward_dispatches_to_dcp_path (test fixture
builds an unpacked kv_cache, the backend expects packed K/V) and
test_attention_backend_capabilities.py::...supports_rswa.

Functional (S5000, gemma-3-270m-it: 18 layers, 5 sliding : 1 full, window 512)

The shared model store does carry gemma-4-31B-it, but on this build it selects
TRITON_ATTN and never reaches FA3 (see Reachability below), so google/gemma-3-270m-it
is the only FA3 hybrid available in either round — it alternates full and sliding layers
exactly like gemma4 does. With the opt-in flag on, the builder logs
MUSA FA3 AOT scheduling across 2 attention windows: ((-1, -1), (511, 0)).

Greedy completion, 3 prompts × 24 tokens, temperature=0, logprobs captured:

run tokens max abs dlogprob vs
baseline eager 72/72 —
candidate eager (flag on) 72/72 identical baseline eager 0.00000
baseline graph (FULL_AND_PIECEWISE, capture [1,2,4,8]) 72/72 identical baseline eager 0.66630 (pre-existing eager-vs-graph delta)
candidate graph (flag on) 72/72 identical candidate eager 0.66630 (same delta)

base-eager == cand-eager and base-graph == cand-graph at 0.00000, and FULL graphs for
both capture sets were recorded and replayed, so the per-window persistent buffers survive
capture. Cold start: the first flag-on graph run paid one-time MATE scheduler JIT for the
extra window (210 s to ready vs 63 s); with warm caches both are 62-63 s.

Performance — why the flag defaults off

Decode-heavy workload, vllm bench serve, random 512-in / 128-out, batch 32, same GPU,
3 reps each, medians (TPOT ms):

variant TPOT output tok/s
baseline (v0.32.0-dev, AOT off by the multi-window rule) 4.49 5960
this PR, default (flag off) 4.37 6187
this PR, VLLM_MUSA_FA3_AOT_PER_WINDOW=1 8.96 1709
flag on, window plan with num_splits=1 7.47 3915
flag on, primary plan only (window self-schedules) 57.47 2402

The refresh is not what costs. Instrumented over 4400 decode steps, building the extra
plan is 40-47 us for get_scheduler_metadata plus 26-29 us for the copy into its
persistent buffer, i.e. ~65 us/step, ~1.5% of a 4.4 ms step. The cost is on the device
side: consuming a prebuilt plan in a sliding-window layer loses to letting MATE
self-schedule that layer. The split budget explains only a third of the gap, and the
per-layer compromise is unusable - a graph that plans the full window while the sliding
window self-schedules runs at 57 ms/step - which is why the choice has to stay model-wide,
the way upstream shapes it. Prefill agrees: 4096-token prompts at batch 8 are ~8% slower
with the extra plan (TTFT 2627 ms vs 2440 ms).

So: the capability ships, the default does not change, and the blocker is not a Python-side
cache we forgot to write - it is MATE's scheduled sliding-window path losing to
self-scheduling on this shape. A model where the better split plan saves more than it
costs would win, but 270M parameters with 640-token sequences is not that model.

Hence: the capability ships, the default does not change. Flipping the default needs a
measurement on a hybrid model big enough to amortize the refresh (gemma4-31B, gpt-oss,
MiniMax-M2). The blocker is not availability — gemma-4-31B-it and MiniMax-M2 are both
on the shared store — it is that neither reaches this backend today (see Reachability).

Second round: long context, speculative decoding, embedding

Same host class, greedy, chat endpoint, base vs this PR's default, token-identical with
max |Δlogprob| = 0.000000 everywhere:

scenario run result
32K max-len, 24,460-token prompt graphs, prefix cache on 9/9 tokens, 0.000000
same, prefix cache off graphs identical to cache-on
same, eager vs graph - 9/9 tokens, 0.056 Δlogprob (pre-existing numeric delta)
speculative decoding, 3 draft tokens draft_model, graphs 31/31 tokens, 0.000000
embedding / encoder-only bge-small-en-v1.5, --runner pooling 384-dim, cosine 1.00000000

Warm alternating A/B on the same compiled path (each variant warmed, 2 reps, medians):
concurrency 1 → TTFT 19.00 vs 19.49 ms, TPOT 2.79 vs 2.81 ms, 342 vs 340 tok/s;
concurrency 32 → TTFT 108.4 vs 100.3 ms, TPOT 4.43 vs 4.55 ms, 6075 vs 6010 tok/s.
Default is parity within noise.

Reachability: two scenarios this PR cannot reach

  • gemma-4-31B-it runs on TRITON_ATTN, not FA3. Its startup log has no
    FlashAttention version line and grep -c flash_attn is 0, so the flagship hybrid arch
    is unaffected by any FA3 metadata work — including the pre-existing model-wide AOT
    disable this PR removes. Separate ticket.
  • FA3 rejects context parallel in this build. -tp 2 -dcp 2 fails backend selection
    with FLASH_ATTN: [DCP not supported], for a sliding-window model and for an all-full
    variant alike. The DCP branch touched here is therefore defensive only; the comment in
    the code says so.

Follow-ups (not in this PR)

  • MATE's scheduled sliding-window path is slower than self-scheduling it. Measured here:
    forcing the window plan down to one split recovers about a third of the gap, and mixing
    a planned full window with a self-scheduled sliding window is far worse than either, so
    the fix has to make the planned path win rather than move the choice per layer.
  • SGLang does not cache a schedule: it refreshes the metadata on every replay and copies
    the fresh values into the captured tensor addresses, which is the same thing this
    backend already gets from its persistent buffer. There is no Python-side cache to port.
  • update_draft_decode_metadata / supports_draft_decode_metadata_update do not exist in
    this shadow, so spec-decode draft steps still run fast_build=True with AOT off.
  • Pre-existing and untouched here: cu_seqlens_k is computed but never read; the encoder
    path silently drops softcap/sinks/ALiBi/num_splits; supports_mm_prefix = True without
    an mm-prefix path; supports_rswa is not declared.

Test plan

  • new CPU suite + the two existing FA3 metadata suites (container, 93 passed)
  • hybrid model eager + FULL-graph greedy parity vs v0.32.0-dev (identical tokens,
    0.00000 logprob delta)
  • default-vs-baseline decode TPOT parity
  • flag-on decode TPOT, with a diagnostic run isolating AOT
  • hybrid model ≥ 8B with long context (blocked: no such checkpoint on the model store)
  • DCP / cascade / MLA / encoder / embedding paths (not exercised; unchanged by
    construction, see the code comments)

Xiaodong Ye added 2 commits October 29, 2026 12:51
A model that mixes full attention with sliding-window attention has one
AOT scheduler-metadata slot today: `_get_sliding_window_configs()` returns
more than one config and the builder reacts by disabling AOT scheduling for
the whole model. Every hybrid checkpoint (gemma2/3/4, gpt-oss, llama4 iRoPE,
minimax_m2, plamo3, ...) therefore runs FA3 decode with no prebuilt split
plan on any layer, including the layers whose window never changed.

The two schedules are not interchangeable: the attention window bounds the
visible KV blocks, hence `num_n_blocks`, hence MATE's split count. So make
the scheduler-metadata slot a function of the layer's window instead of
disabling the feature:

- `_normalize_attention_window()` and `_get_attention_window_layouts()`:
  one layout per distinct paged-KV attention window, full attention first,
  encoder-only/encoder layers excluded (they never read a KV schedule).
- `FlashAttentionMetadata.kind_scheduler_metadata` plus
  `scheduler_metadata_for(window)`: the builder fills one schedule per
  window, each `FlashAttentionImpl` reads the slot for its own window. A
  window missing from a populated map resolves to `None` (MATE then derives
  a schedule in the wrapper) rather than borrowing another window's plan.
- CUDA-graph capture keeps one persistent buffer per window, so recorded
  FULL graphs read a fixed address like they do for the primary slot.
- The Qwen direct-decode-schedule path hands every layer the same prebuilt
  schedule, so it now requires a single-window model.
- DCP keeps the previous single-slot behaviour: its two-sided schedule is
  built for one window and every layer reads that slot.

Measured on gemma-3-270m (18 layers, 5 sliding : 1 full, window 512,
512+128 tokens, batch 32) the per-window refresh costs ~1 ms/step/window:
decode TPOT 4.4 ms with AOT off vs 8.9 ms with a schedule per window, and a
single-window variant of the same checkpoint shows the refresh alone is
4.1 ms -> 5.0 ms. The capability is therefore opt-in behind
VLLM_MUSA_FA3_AOT_PER_WINDOW until a model large enough shows the better
split plan outweighing the refresh, which keeps the default byte-for-byte
equal to the current behaviour (verified: 4.4 ms vs 4.4-4.5 ms baseline).

Tests: new tests/test_flash_attn_scheduler_metadata_kinds.py covers the
selection matrix, the opt-in gate, graph buffers, and the three forward
paths that consume a schedule.
Review follow-ups on the per-attention-window scheduler metadata:

- `_normalize_attention_window()` now maps only `None` onto full attention.
  `(-1, 0)` is unbounded on the left but bounded on the right: identical
  visible KV under a causal mask, different without one, so it stays its own
  kind instead of sharing the full-attention slot.
- `scheduler_metadata` is documented as the primary-window slot rather than
  the full-attention slot; single-window sliding-window models use it too.
- New `tests/test_fa3_aot_window_source.py` runs in the series CI job (the
  only job that has no vLLM/torch): it guards the deleted model-wide kill
  switch, the per-window slot contract, the None-on-miss lookup, the opt-in
  default, the DCP single-slot branch, and the regenerated tripwire.
@yeahdongcn

Copy link
Copy Markdown
Collaborator Author

Second validation round on isolated S5000 hardware (lease lease-8f8a12162bc8,
host 10.20.36.18), against the pushed head 95f4519445. This round adds
review follow-ups, the scenarios the first round could not cover, and two
reachability findings that change what this PR can claim.

Review follow-ups

  1. _normalize_attention_window() now maps only None onto full attention.
    (-1, 0) is unbounded on the left but bounded on the right, so it coincides
    with full attention only under a causal mask; it keeps its own slot and its
    own schedule.
  2. scheduler_metadata is documented as the primary-window slot rather than
    the full-attention slot (single-window sliding-window models use it too).
  3. tests/test_fa3_aot_window_source.py — 6 source-contract tests that run in
    the series CI job, since that job has no vLLM/torch and cannot import the
    backend. They guard the deleted model-wide kill switch, the per-window slot
    contract, the None-on-miss lookup, the opt-in default, the DCP single-slot
    branch, and the regenerated module-drift tripwire. patch-series.yml already
    runs tests/test_*source.py, so the glob picks them up; the behavioural
    suite still needs a MUSA runner.

Correctness

Greedy, /v1/chat/completions, --generation-config vllm, base vs this PR's
default (flag off), token-identical with max |Δlogprob| = 0.000000 in every
pairing:

scenario model result
hybrid eager gemma-3-270m-it (5 sliding : 1 full, window 512) 72/72 tokens, 0.000000
hybrid FULL graphs same 72/72, 0.000000
long context, 24,460-token prompt same, 32K --max-model-len 9/9, 0.000000
long context, prefix cache off same identical to cache-on
speculative decoding, 3 draft tokens same, draft_model, graphs 31/31, 0.000000
embedding / encoder-only bge-small-en-v1.5, --runner pooling 384-dim, cosine 1.00000000, Δ=0
eager vs graph (same build) same 9/9 tokens, 0.056 Δlogprob — pre-existing numeric difference, identical for base and candidate

Per-window AOT under full graph capture works: the log line
MUSA FA3 AOT scheduling across 2 attention windows: ((-1, -1), (511, 0))
appears and all 51 capture sizes succeed.

Performance, warm alternating A/B (production compiled path)

gemma-3-270m-it, graphs on, vllm bench serve, random 512-in / 128-out; each
variant warmed with 16 requests before measuring; 2 reps, medians:

concurrency metric v0.32.0-dev this PR (default)
1 TTFT / TPOT 19.00 ms / 2.79 ms 19.49 ms / 2.81 ms
1 output throughput 342.5 tok/s 340.2 tok/s
32 TTFT / TPOT 108.36 ms / 4.43 ms 100.34 ms / 4.55 ms
32 output throughput 6075 tok/s 6010 tok/s

Default is parity within noise (≤3%), matching the earlier 3-rep bs32 run
(4.36/4.43 vs 4.47/4.75 ms). The opt-in flag stays a regression on small models
(8.88 ms TPOT, 2.0x), and its cold start is worse than previously measured:
graph capture grows from ~60 s to ~8 min for 51 capture sizes (first capture
157 s) because each window's first schedule pays a MATE scheduler JIT.

Two reachability findings (recorded, not fixed here)

  • gemma-4-31B-it does not use FA3. It is the flagship hybrid arch this PR
    targets (60 layers, 5 sliding : 1 full, window 1024, 262144 ctx), but
    attention-backend selection picks TRITON_ATTN — grep -c flash_attn over
    the startup log is 0. So no amount of FA3 metadata work reaches it today.
  • FA3 rejects context parallel in this build. -tp 2 -dcp 2 fails selection
    with FLASH_ATTN: [DCP not supported] for both a sliding-window model and an
    all-full variant. The DCP branch here is therefore defensive only; it cannot
    be exercised from this backend.

Both deserve their own tickets; I left _forward_with_dcp unchanged and say so
in the code comment rather than implying it is covered.

Not run, with reasons

  • gemma-4-31B-it / Qwen3-8B parity: no FA3 (see above); Qwen3 is single-window,
    so it cannot exercise the feature beyond the regression check already covered
    by the gemma-3 full-attention variant.
  • CP with a window-mixed model: unreachable (see above).
  • MLA and cross/encoder attention: not FA3 on this build.

Instrumenting the per-call cost shows the extra window's refresh is ~65 us per
step (40 us build + 26 us copy), not the ~1 ms the earlier comment claimed: that
figure came from the first JIT compile of the local-window metadata kernel
landing inside the measurement window. With MATE's cache warm, the opt-in starts
in the same 69-73 s as the default.

The 2x decode pessimization is real and device-side: consuming a prebuilt plan in
a sliding-window layer loses to letting MATE self-schedule it (4.4 -> 9.0 ms
TPOT; one split recovers only 1.5 ms), and the per-layer compromise - planned
full window plus self-scheduled sliding window - runs at 57 ms/step. The opt-in
default therefore stays, and the reason recorded here is the one the numbers
support.
@yeahdongcn
yeahdongcn marked this pull request as draft October 29, 2026 10:09

@yeahdongcn yeahdongcn left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Merge verdict: 1 blocking finding — not ready to merge.

2a005c1b3666 fails the repository's own pre-commit gate; the only CI check, offline-series, passed.

Findings: 1 blocking · 5 nit

Gate: pre-commit run --files <6 changed file(s)> @ 2a005c1: 12/14 hooks passed in 3.7s. Failed don't commit to branch and black; black printed reformatted tests/test_flash_attn_scheduler_metadata_kinds.py and reformatted vllm_musa/v1/attention/backends/flash_attn.py.

nit location problem fix
nit vllm_musa/v1/attention/backends/flash_attn.py:77 10-line benchmark narration shipped to users one line: opt-in, default off
nit vllm_musa/v1/attention/backends/flash_attn.py:87 != "0" lets =false enable it accept {"1","true"}
nit .github/workflows/patch-series.yml:81 new 627-line suite runs in no job register it in a MUSA job
What changed · what I could not verify

Diff map (6 files): vllm_musa/v1/attention/backends/flash_attn.py plus the regenerated vllm_musa/patches/module-drift/v1.attention.backends.flash_attn.diff carry all runtime behaviour; the rest are tests (new 627-line CPU suite, new 93-line source-contract suite, two one-line fixture updates).

Earlier rounds: pulls/314/reviews and pulls/314/comments both return [] at this head — there is no earlier P0/P1 to re-check and no undelivered inline finding. The PR has one author issue comment, not a review.

Checks: gh pr checks 314 → offline-series pass 1m17s (job 123375143136); no other check reported.

Verified by reading the head commit (never the local checkout):

  • Builder and impl key the map through the same _normalize_attention_window, so a layer cannot miss its own slot by normalisation mismatch.
  • All four consumers are consistent: decode fast path (:1422), paged varlen (:1582), DCP single slot (:1740), cascade single slot (:1615). fast_build leaves the map None, so spec-decode draft steps keep scheduler_metadata=None.
  • The num_attention_windows == 1 guard closes a real hole: on a hybrid model aot_sliding_window is (-1,-1), so the pre-existing aot_sliding_window == (-1,-1) test alone would still have let the Qwen direct builder hand every SWA layer a full-attention plan.
  • Cascade is not a live per-window hole: pinned upstream v0.32.0 (5df63a72) documents common_prefix_len as "Deprecated and always 0" (vllm/v1/attention/backend.py:693) and the runner sets cascade_attn_enabled = False, so that branch is unreachable.
  • logger.info_once(..., scope="local") exists at the pin (vllm/logger.py:171).

Assumed / not verified: I ran no MUSA hardware. The 93-test CPU result, the TPOT table, and the logprob-parity rows are the author's numbers, quoted not checked. I could not reproduce the black output locally (the sandbox black entry point fails on import), so the gate line is the evidence. The default-is-bit-identical claim is consistent with the diff: flag off plus a window-mixed model sets aot_schedule = False, exactly upstream's outcome, and the flag-on path is the only one that changes behaviour.

nit-4 tests/test_fa3_aot_window_source.py:69-73: the contract tests assert exact source substrings ('VLLM_MUSA_FA3_AOT_PER_WINDOW", "0"', "dcp_world_size > 1 or not _AOT_PER_WINDOW_ENABLED"), so a harmless reformat — including the black run above — breaks CI; keep the AST assertions and drop the literal ones.

nit-5 tests/test_flash_attn_scheduler_metadata_kinds.py:353: test_cascade_batch_keeps_single_slot pins a branch the pinned upstream can no longer enter, so it asserts an assumption rather than behaviour.

Context for nit-1: the same comment block is duplicated into vllm_musa/patches/module-drift/v1.attention.backends.flash_attn.diff:157, and the new block also adds # ===== MUSA ADAPTATION ===== / # ===== END ===== banners, so the reword has to be made in the source and the patch regenerated.

auto-review round 3/3 · verdict: blockers

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant