Repository navigation
Description
Problem
On vLLM 0.26, Granite Switch (Shadow-Residual / MultiSwitch) emits wrong tokens only when cudagraph_mode=FULL and prefix caching are both on. Disabling either one makes outputs match vLLM 0.19 exactly.
- A token outside the adapter's allowed set (token 0) is produced, raising a
KeyErrordownstream — observed on 99.8% of decisions in the failing environment. - Even where no token is out of range, distributions diverge from the reference environment.
Same 12 batches of 1–5 adapters on one growing game history, per setting:
| vLLM 0.26 setting | Outputs outside allowed set | Style adapters matching exactly (ref: 9) |
|---|---|---|
ours: cudagraph_mode=FULL, prefix caching on |
6 of 33 | 4 |
FULL_AND_PIECEWISE (vLLM default) |
0 | 9 |
| eager (no CUDA graphs) | 0 | 9 |
| prefix caching off | 0 | 9 |
| async scheduling off | 6 of 33 | 4 |
| old environment, vLLM 0.19 (reference) | 0 | 9 |
Read as an interaction test: turning off either FULL or prefix caching matches 0.19 exactly, and turning off async scheduling changes nothing — so only FULL + prefix caching is broken, and async scheduling is ruled out.
Root cause (validated against pinned v0.26.0 source)
FA3's ahead-of-time schedule is sized from the model config (vllm/v1/attention/backends/flash_attn.py:370-375), not the group's real layers. The Shadow-Residual decoder builds Attention(2 * self.num_heads, ...) (src/granite_switch/vllm/decoder/shadow_residual/decoder.py:138) — query heads are doubled — but num_heads_q comes from the un-doubled model_config.get_num_attention_heads(). So FA3 schedules for half the real query heads. (headdim is already correct via the repo's get_head_size() override.)
KV-cache groups are keyed by the frozen KVCacheSpec, whose AttentionSpec carries head_size/num_kv_heads (vllm/v1/kv_cache_interface.py:99,175-178; grouping at vllm/v1/core/kv_cache_utils.py:1205), so the switch counting/memory heads land in separate single-shape groups. The dominant failure is therefore a single-shape group whose shape disagrees with the model config (SR doubled-Q), not a mixed group.
Why FULL + prefix caching specifically: under FULL the mis-sized partition is frozen into the persistent scheduler_metadata buffer and reused by the captured graph (flash_attn.py:400-419,641-649); a 1-token prefix-cached decode (max_seqlen_q=1, large max_seqlen_k, one request) is where the wrong partition produces token-0 / out-of-set garbage. Non-FULL recomputes a fresh split each call (max_num_splits=0) and self-corrects; fresh-prompt batches mask it because the prefill shape dominates.
Not an FA3 bug — FA3 is handed the wrong shape and has no way to know the SR decoder doubles its query heads. The fix is ours.
Fix
Re-introduce fa3_schedule.py on the 0.26 line (branch fix/fa3-aot-schedule-0.26 off feature/vllm-0.26-to-0.30), keeping the wrap-__init__-after-original structure:
- Single-shape group — overwrite
num_heads_q/num_heads_kv/headdimfrom the group's own layers (corrects SR doubled-Q, keeps AOT on; the FULL buffer is shape-independent so stays valid). This is the latency-preserving win. - Genuinely mixed group (rare) — disable AOT consistently:
aot_schedule=False,scheduler_metadata=None,max_num_splits=0, so the builder state is self-consistent whatever pathbuild()takes. - Version safety — never set
_PATCHEDon a missing/renamed symbol; assert the builder/layer attribute contract afteroriginal(...); prefer a loud failure over a silent no-op (today's_PATCHED=Trueonbuilder is Nonehides breakage and reintroduces wrong tokens).
Files: src/granite_switch/vllm/fa3_schedule.py (create), src/granite_switch/vllm/__init__.py (call patch_flash_attn_schedule() in register()), tests/vllm/test_fa3_schedule.py + tests/vllm/_fa3_schedule_worker.py (create — zero existing coverage).
Verification
vLLM is not installable locally; GPU tests run via the gsw-tests MCP tool.
- Reproduction / regression (authoritative): serve a composed SR MultiSwitch checkpoint on vLLM 0.26 with
enable_prefix_caching=True; run the toggle matrix{FULL, non-FULL} × {prefix on, off}. One game served alone + a 1-token prefix-cached decode fails pre-fix (token-0 / KeyError), passes post-fix (tokens in the allowed set, distributions match the non-FULL / 0.19 baseline). Re-run the 12-batch experiment: expect 0 out-of-set and 9/9 style matches. - Patch unit test (vLLM-26 CI leg): instantiate
FlashAttentionMetadataBuilderwith the patch installed on a group reporting the doubled SRnum_heads; assertnum_heads_qequals the layer (doubled) value, the mixed-group teardown is applied, idempotency, and version-safety (missing symbol → log/raise, no_PATCHED). - Note (CLAUDE.md gotcha Add a Colab notebook/script for experimenting with Granite Switch and Mellea on Google Colab #11): the FULL-cudagraph GPU test runs real graphs, so assert on generated tokens/logprobs, not on
enforce_eager-only debug attributes.
Full writeup: docs/FA3_SCHEDULE_FULL_CUDAGRAPH_BUG.md.
Activity
yairallouche commentedon Oct 7, 2026
Update — reproduction is blocked on FlashAttention 3, not on the diagnosis
Posting what we've learned since the issue was opened. Short version: the root-cause
analysis still holds, the fix is designed, regression tests are written — but we have
not yet been able to reproduce the bug on a GPU, because the one condition that
triggers it (FlashAttention 3 driving a FULL CUDA graph) has not loaded in the
environments we tried.
Status at a glance
tests/vllm/test_fa3_schedule.py+ worker) on branchbugfix/139-fa3-schedule-full-cudagraph-prefix-caching.The key finding: the bug cannot appear without FlashAttention 3
cudagraph_mode=FULLis only honored when the attention backend is FA3. With FA2,vLLM reports the backend only supports
UNIFORM_BATCHcudagraphs and silentlydowngrades FULL to FULL_AND_PIECEWISE — which is the correct setting. So on FA2 you
get correct output and learn nothing.
installed
vllm_flash_attnhas a loadable FA3 kernel for the running torch/CUDA.What happened on Vela
Ran the tests on an H100 (SM90 ✓) under vLLM 0.26 and again under 0.30. In both cases the
probe reported:
So FULL downgraded and the bug could not appear. Correcting a common wrong guess: this
is not a torch version mismatch — vLLM 0.26 pins
torch==2.11and the pod had exactlythat. The remaining suspect is the compiled CUDA of the bundled
vllm_flash_attnkernel vs the pod's CUDA (the FA3 kernel is present but won't load for that CUDA build).
What we validated anyway
The full test pipeline works end to end: the SR MultiSwitch checkpoint composes and loads
on GPU, and the harness runs. We also added an
FA_VERSIONprobe so an inconclusive(no-FA3) run is obvious instead of a misleading pass/fail, and the tests now skip
(rather than fail) when
FA_VERSION != 3— so a red result always means a realregression, never just a missing-FA3 environment.
Open question
Where did the original experiment get FA3? The table in the issue was observed with
FA3 active, so some environment loads it. Knowing that image /
vllm_flash_attnbuild /CUDA would let us reproduce directly. Next step otherwise: a tiny probe job that prints
fa_version_unsupported_reason(3)(fromvllm.vllm_flash_attn.flash_attn_interface),which states exactly why FA3 is rejected on a given box.
Full writeup kept current in
docs/FA3_SCHEDULE_FULL_CUDAGRAPH_BUG.md.Add fa3_schedule patch: size FA3's AOT schedule for the switch's own …
Update FA3 schedule doc: FA3 needs Hopper, add status + reproduction …
Skip FA3 schedule tests when FlashAttention 3 is not active (#139)
Add FA3 AOT-schedule regression tests for FULL cudagraph + prefix cac…
Serve the universal-classifier switch on FlashAttention 2
#139: FA3 FULL-cudagraph fix — report UNIFORM_BATCH for granite_switch
Add FA3 AOT-schedule regression tests for FULL cudagraph + prefix cac…
Add fa3_schedule patch: size FA3's AOT schedule for the switch's own …
Update FA3 schedule doc: FA3 needs Hopper, add status + reproduction …
Skip FA3 schedule tests when FlashAttention 3 is not active (#139)
#139: FA3 FULL-cudagraph fix — report UNIFORM_BATCH for granite_switch
Drop local-only docs/scripts and the dev-latest alias regression
Drop local-only docs/scripts and the dev-latest alias regression
#139: FA3 FULL-cudagraph fix — report UNIFORM_BATCH for granite_switch
Drop local-only docs/scripts and the dev-latest alias regression
Bugfix/139 fa3 schedule full cudagraph prefix caching fa3 fixing (#146)
Bugfix/139 fa3 schedule full cudagraph prefix caching fa3 fixing (gen…