Skip to content

FA3 AOT schedule wrong under FULL CUDA graphs + prefix caching (vLLM 0.26) #139

Open

Description

@yairallouche

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 KeyError downstream — 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:

  1. Single-shape group — overwrite num_heads_q/num_heads_kv/headdim from 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.
  2. 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 path build() takes.
  3. Version safety — never set _PATCHED on a missing/renamed symbol; assert the builder/layer attribute contract after original(...); prefer a loud failure over a silent no-op (today's _PATCHED=True on builder is None hides 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 FlashAttentionMetadataBuilder with the patch installed on a group reporting the doubled SR num_heads; assert num_heads_q equals 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

  1. added
    bug
    vllm
    prio:medium
    on Oct 6, 2026
  2. yairallouche commented on Oct 7, 2026

    @yairallouche
    CollaboratorAuthor

    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

    Item State
    Root-cause mechanism Traced from pinned vLLM 0.26 source + our attention shapes. Not yet reproduced on GPU.
    The fix Designed, not yet written.
    Regression tests Written (tests/vllm/test_fa3_schedule.py + worker) on branch bugfix/139-fa3-schedule-full-cudagraph-prefix-caching.
    Reproduction on Vela Blocked — FA3 did not load, so FULL silently downgraded (details below).

    The key finding: the bug cannot appear without FlashAttention 3

    • cudagraph_mode=FULL is only honored when the attention backend is FA3. With FA2,
      vLLM reports the backend only supports UNIFORM_BATCH cudagraphs and silently
      downgrades FULL to FULL_AND_PIECEWISE
      — which is the correct setting. So on FA2 you
      get correct output and learn nothing.
    • FA3 is selected only when both: the GPU is SM90/Hopper (e.g. H100) and the
      installed vllm_flash_attn has 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:

    FA_VERSION=2  (FULL cudagraph requires FA_VERSION=3)
    CUDAGraphMode.FULL is not supported with FlashAttentionBackend (UNIFORM_BATCH);
      setting cudagraph_mode=FULL_AND_PIECEWISE
    

    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.11 and the pod had exactly
    that. The remaining suspect is the compiled CUDA of the bundled vllm_flash_attn
    kernel
    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_VERSION probe 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 real
    regression, 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_attn build /
    CUDA would let us reproduce directly. Next step otherwise: a tiny probe job that prints
    fa_version_unsupported_reason(3) (from vllm.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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugprio:mediumvllm

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions