← Back to Pull requests

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

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Oct 29, 2026 04:52 UTC
Author

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)

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: yeahdongcn Review duration: 16245m
    All Vouch review confidence checks passed
    Residual risk 0.30 = Change Risk (0.52) × (1 − Review Confidence (0.43)). 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%
    42%
    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 #314"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 43.0% 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: 43.0% · Lower = rushed or shallow review
    43.0%
    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: 29.7% · Safe to merge
    29.7%