Repository navigation
[MUSA] fa3: per-attention-window AOT scheduler metadata (opt-in) - #314
yeahdongcn wants to merge 3 commits into
Conversation
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.
|
Second validation round on isolated S5000 hardware (lease Review follow-ups
CorrectnessGreedy,
Per-window AOT under full graph capture works: the log line Performance, warm alternating A/B (production compiled path)gemma-3-270m-it, graphs on,
Default is parity within noise (≤3%), matching the earlier 3-rep bs32 run Two reachability findings (recorded, not fixed here)
Both deserve their own tickets; I left Not run, with reasons
|
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
left a comment
There was a problem hiding this comment.
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_buildleaves the mapNone, so spec-decode draft steps keepscheduler_metadata=None. - The
num_attention_windows == 1guard closes a real hole: on a hybrid modelaot_sliding_windowis(-1,-1), so the pre-existingaot_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) documentscommon_prefix_lenas "Deprecated and always 0" (vllm/v1/attention/backend.py:693) and the runner setscascade_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
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 andthe builder answers by disabling AOT scheduling model-wide:
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 adense 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 perattention 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 onelayout 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
FlashAttentionImplreads the slot thatmatches its own
sliding_window. A window that is missing from a populated map resolvesto
None, i.e. MATE derives a schedule inside the wrapper (slower, always correct) —never another window's plan.
before capture), so recorded FULL graphs read a fixed address exactly like the primary
slot does today.
_use_musa_qwen_direct_decode_schedule) hands everylayer the same prebuilt schedule, so it now requires a single-window model.
_forward_with_dcpbuilds one two-sidedschedule 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.
VLLM_MUSA_FA3_AOT_PER_WINDOW=1. The default isbit-for-bit the current behaviour (see the measurement below for why).
Evidence
Correctness (CPU, in the v0.32.0 prebuilt container)
The new suite covers window normalization, dedup + full-first ordering, encoder
exclusion, the opt-in gate, "one schedule per window" (distinct
data_ptrs), single-windowmodels 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-devfile andare unrelated:
test_flash_attn_dcp.py::test_forward_dispatches_to_dcp_path(test fixturebuilds an unpacked
kv_cache, the backend expects packed K/V) andtest_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 selectsTRITON_ATTNand never reaches FA3 (see Reachability below), sogoogle/gemma-3-270m-itis 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:FULL_AND_PIECEWISE, capture[1,2,4,8])base-eager == cand-eagerandbase-graph == cand-graphat 0.00000, and FULL graphs forboth 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):
v0.32.0-dev, AOT off by the multi-window rule)VLLM_MUSA_FA3_AOT_PER_WINDOW=1num_splits=1The refresh is not what costs. Instrumented over 4400 decode steps, building the extra
plan is 40-47 us for
get_scheduler_metadataplus 26-29 us for the copy into itspersistent 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-itandMiniMax-M2are bothon 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.000000everywhere:draft_model, graphsbge-small-en-v1.5,--runner poolingWarm 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-itruns onTRITON_ATTN, not FA3. Its startup log has noFlashAttention versionline andgrep -c flash_attnis 0, so the flagship hybrid archis unaffected by any FA3 metadata work — including the pre-existing model-wide AOT
disable this PR removes. Separate ticket.
-tp 2 -dcp 2fails backend selectionwith
FLASH_ATTN: [DCP not supported], for a sliding-window model and for an all-fullvariant alike. The DCP branch touched here is therefore defensive only; the comment in
the code says so.
Follow-ups (not in this PR)
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.
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_updatedo not exist inthis shadow, so spec-decode draft steps still run
fast_build=Truewith AOT off.cu_seqlens_kis computed but never read; the encoderpath silently drops softcap/sinks/ALiBi/
num_splits;supports_mm_prefix = Truewithoutan mm-prefix path;
supports_rswais not declared.Test plan
v0.32.0-dev(identical tokens,0.00000 logprob delta)
construction, see the code comments)