Repository navigation
[rl] vLLM generator: fp8 KV cache through FA4's fp8 forward, MTP verify steps included - #6365
felipemello1 wants to merge 3 commits into
Conversation
|
Reply from claude: @claude please review |
|
Claude finished @felipemello1's task in 2m 55s —— View job Approve -- please address the 5 items before merging (a maintainer still needs to review): review |
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging. The design is opt-in and the default path is unchanged. The remaining items are small local edits: a config-time check, an upstream issue link, a test fold, and a refusal for paths nobody has run. A maintainer still needs to review.
What this PR does. It adds VLLMEngine.Config.kv_cache_dtype: Literal["auto", "fp8"] and passes it to vLLM's EngineArgs. With "fp8", vLLM writes K/V as e4m3 and quantizes the query. The TorchTitan attention impl views the uint8 cache as e4m3, takes per-layer _q/_k/_v_scale expanded to (batch, num_kv_heads), and paged_varlen_attention_out(descales=...) calls FA4's private _flash_attn_fwd with TensorwiseScales. supports_combination and __init__ hide fp8 from FlashAttentionBackend's own check, and non-SM100 GPUs are refused. fp8 is refused together with batch-invariant mode or MTP drafts.
Example.
VLLMEngine.Config(kv_cache_dtype="fp8"), Qwen3.8-27B, GB300
before: AssertionError "FP8 KV cache not supported yet." in impl.forward
after: cache 2.90M -> 5.81M tokens; decode/prefill rows -> _flash_attn_fwd(q_e4m3, k_e4m3, v_e4m3, scales=...)
trainer/generator logprob mean |diff| 0.0096 -> 0.0217 (opt-in; "auto" path unchanged)
VLLMEngine.Config(kv_cache_dtype="fp8", num_speculative_tokens=3) -> ValueError (verify rows pass no descales yet)
Must fix
- The PR description's Summary (human-written) section is empty. The author needs to fill it in.
torchtitan/rl/generator/vllm/engine.py:308-- the fp8 + drafts check reads only Config fields, so it should move toConfig.__post_init__(inline).torchtitan/rl/generator/attention/attention.py:61-- the private_flash_attn_fwdcall has a TODO but no upstream issue link ("no torch issue filed yet") (inline).tests/rl/unit_tests/gpu/test_paged_attention_fp8.py:128-- this test mostly duplicates the new fp8 cases oftest_vllm_verify_attention.py. Put a leading 1-token row in itsmixedcase, then delete this file and its workflow line (inline).torchtitan/rl/generator/vllm/attention/attention.py:321-- fp8 reaches sliding-window, sink (out_transform/return_lse), and head-dim-64 configurations (gpt-oss) that no run covers. Refuse them or test them (inline).
Questions
- TP > 1 with fp8 is listed as untested. The descale shape uses the local
num_kv_heads, so it looks right. Is a TP2 run planned before this lands, or should TP > 1 be refused like the other untested combinations?
Details
- Gate: the problem is real (an assert on main), and vLLM already writes fp8. The gap is only in TorchTitan's backend, so the layer is right. Not one-sided: the trainer has no KV cache, and the PR refuses the one mode (batch-invariant) that needs trainer parity.
- Checked: descale batch dim =
query_start_loc.shape[0] - 1matchesblock_table/seqused_kin both the decode and prefill split calls (they keep the full batch and zero the other call's rows). Under FULL graphs the padded batch is fixed per graph, and the scales are static per-layer tensors, so replay is safe._verify_rows_as_decodepasses no descales, but it is only reachable with drafts, which fp8 refuses. - sglang's caller of
paged_varlen_attention_outis unaffected (descales=None).
Not verified: vLLM internals I couldn't import here (query_quant setup when the parent impl gets "auto", and the 2D query requirement). The FA4 fp8 forward behavior with windows or sinks also needs a GPU run.
|
Reply from claude: Round 1 fixes are in 3be3ff0 (see the threads). Two items have no thread: Must 4: the duplicate fp8 test. Done. # A leading 1-token row: FA4's decode call for it, the varlen call for the rest.
([1, 4, 4], [257, 130, 30_000], False),Q: TP > 1. No TP2 run: the GPU host has one GPU. The descales are per-layer scalars expanded over the local KV heads, so TP only changes that count. The body keeps the NOTE "not tested with fp8: TP > 1". Refusing it is the author's call; I flagged it to him. |
|
Reply from claude: @claude please review |
|
Claude finished @felipemello1's task in 2m 6s —— View job Approve -- please address the 5 items before merging (a maintainer still needs to review): review |
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging. The round-1 code fixes are in at 3be3ff0. What's left is small and local: one more refusal, a link, the summary, the description, and one test run. A maintainer still needs to review.
What this PR does. It adds VLLMEngine.Config.kv_cache_dtype: Literal["auto", "fp8"] and passes it to vLLM's EngineArgs. With fp8, TorchTitan's CUSTOM backend views the cache as e4m3 and expands the layer's _q/_k/_v_scale to (batch, num_kv_heads). It then calls FA4's private _flash_attn_fwd with TensorwiseScales for both the decode call and the prefill call. fp8 is refused with drafts (at config time), with batch-invariant mode, and on models with sliding-window layers.
Example.
VLLMEngine.Config(kv_cache_dtype="fp8"), Qwen3.8-27B (varlen, full causal), GB300
before: AssertionError "FP8 KV cache not supported yet."
after: 2.90M -> 5.81M KV tokens; both split calls -> _flash_attn_fwd(..., scales=TensorwiseScales(q, k, v))
VLLMEngine.Config(kv_cache_dtype="fp8", num_speculative_tokens=3) -> ValueError at config time
fp8 + gpt-oss / muse_glimmer / muse_spark (windowed layers) -> ValueError at engine start
fp8 + a FlexInnerAttention model -> reaches vLLM's flex backend (see inline)
Round 1 status
- Resolved: the drafts check is in
__post_init__; the duplicate fp8 test is gone (the mixed case's leading 1-token row now sends descales through both FA4 calls); windowed models are refused. - Still open: the human-written summary (item 1) and the upstream issue link for
_flash_attn_fwd(item 3,torchtitan/rl/generator/attention/attention.py:61).
Must fix
- The PR description's Summary (human-written) section is still empty. The author needs to fill it in.
torchtitan/rl/generator/attention/attention.py:61-- the TODO on the private_flash_attn_fwdcall still says "no torch issue filed yet". It needs the pytorch/pytorch issue link (CLAUDE.md principle 3).torchtitan/rl/generator/vllm/engine.py:316-- fp8 isn't refused for flex-attention models, which bypass the FA4 fp8 path this PR adds (inline).- Description: "gpt-oss is the one such model here" (the sliding-window refusal) is not accurate. muse_glimmer (
flavors.py:242) and muse_spark (flavors.py:427) also have windowed layers, and both have RL recipes. The check refuses them throughgetattr, so the code is right. Fix the sentence, because a maintainer reading it would conclude only gpt-oss loses fp8. - Test plan: the GPU test ran only on an unreleased FA4 branch (fp8 SwapAB), and the run on a released FA4 is "pending for this head". On a released FA4, fp8 decode takes a different kernel (the standard one), so that path has no correctness run at this head. Run
test_vllm_verify_attention.pyon FA4 4.0.0b39 or b40 and record the result before merging.
Details
- Gate (unchanged from round 1): the problem is real on the base branch (an assert). The fix lives in TorchTitan's backend, which is the right layer, and it is opt-in. "auto" runs the same code as before.
- Checked at HEAD:
descalesgoes through both entries ofcalls(vllm/attention/attention.py:423-437), and each call keeps the full batch, so the(batch, num_kv_heads)shape matchesblock_table/seqused_k._verify_rows_as_decodedoesn't pass descales, but it is reachable only with drafts, which the config refuses. Compressed MLA refuses fp8 itself (mla.py:147). - Minor, not blocking: when torch's flash impl is not FA4,
current_flash_attention_impl() == "FA4"is false. fp8 then skips the decode/prefill split but still calls FA4 directly. That only costs performance on mixed batches.
Not verified: whether vLLM's FlexAttention backend refuses fp8 during backend selection (vLLM isn't importable here).
|
Reply from claude: Round 2 is in 8c367cd and the body. Must 1 and 2 (the Summary, the torch issue link) wait on the author.
Before/after for the docstring: |
|
Reply from claude: @claude please review |
|
Claude finished @felipemello1's task in 54s —— View job Approve -- please address the 2 items before merging (the human-written Summary and the upstream issue link; a maintainer still needs to review): review |
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging. The code fixes from rounds 1 and 2 are in at 8c367cd, and the new commit only changes a docstring. The two items left are edits only the author can make. A maintainer still needs to review.
What this PR does. It adds VLLMEngine.Config.kv_cache_dtype: Literal["auto", "fp8"] and passes it to vLLM's EngineArgs. With fp8, TorchTitan's CUSTOM backend views the cache as e4m3, expands the layer's _q/_k/_v_scale to (batch, num_kv_heads), and calls FA4's private _flash_attn_fwd with TensorwiseScales. fp8 is refused in three cases: with drafts (at config time), with batch-invariant mode, and on models with sliding-window layers. On flex-attention models, vLLM's backend validation refuses it.
Example.
VLLMEngine.Config(kv_cache_dtype="fp8"), Qwen3.8-27B, GB300
before: AssertionError "FP8 KV cache not supported yet."
after: 2.90M -> 5.81M KV tokens; decode + prefill calls -> _flash_attn_fwd(..., scales=TensorwiseScales(q, k, v))
VLLMEngine.Config(kv_cache_dtype="fp8", num_speculative_tokens=3) -> ValueError at config time
fp8 + gpt-oss / muse_glimmer / muse_spark -> ValueError at engine start
fp8 + a FlexInnerAttention model -> vLLM: "kv_cache_dtype not supported"
Round 2 status
- Resolved: flex models (vLLM refuses fp8 through
AttentionConfig(backend=...), and the docstring now scopes fp8 to varlen attention). The sliding-window sentence in the description now names all three models. The test plan now has a released-FA4 run (4.0.0b40: 5 passed, 1 skipped). - Still open: items 1 and 2 below.
Must fix
- The PR description's Summary (human-written) section is still empty. The author needs to fill it in.
torchtitan/rl/generator/attention/attention.py:61-- the TODO on the private_flash_attn_fwdcall still says "no torch issue filed yet". It needs a pytorch/pytorch issue link (CLAUDE.md principle 3).
Details
- Gate (unchanged): the problem is real on the base branch (an assert), and vLLM already writes fp8. The gap is only in TorchTitan's backend, which is the right layer. The change is opt-in, and "auto" runs the same code as before.
- 8c367cd changes only the
kv_cache_dtypedocstring. The new wording is consistent with the backend routing inregistry.pyand the engine-side checks. - The window check reads
getattr(layer.attention, "sliding_window_size", None), the same fieldmodel_wrapper.py:118passes to vLLM, so the refusal and the wrapper can't disagree about which layers are windowed.
Not verified: vLLM's flex-backend refusal of fp8 (vLLM isn't importable here; I took it from the author's cited source lines).
|
Reply from claude: @claude please review |
|
Claude finished @felipemello1's task in 40s —— View job Approve -- please address the 2 items before merging (the human-written Summary and the upstream issue link; a maintainer still needs to review): review |
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging. The only new commit since round 3, e5678e9, refuses fp8 with TP > 1, which answers the round-1 question about TP. The two items left are edits only the author can make. A maintainer still needs to review.
What this PR does. It adds VLLMEngine.Config.kv_cache_dtype: Literal["auto", "fp8"]. With fp8, TorchTitan's CUSTOM backend views the cache as e4m3 and calls FA4's private _flash_attn_fwd with TensorwiseScales built from the layer's _q/_k/_v_scale. fp8 is refused with MTP drafts (at config time), with batch-invariant mode, with tensor_parallel_degree > 1, and on models with sliding-window layers. On flex-attention models, vLLM's own backend validation refuses it.
Example.
VLLMEngine.Config(kv_cache_dtype="fp8") + InferenceParallelismConfig(tensor_parallel_degree=2)
before (8c367cda7): builds; each rank expands the scales over its local KV heads, a path no run has checked
after (e5678e9a6): ValueError "kv_cache_dtype='fp8' is untested with tensor parallelism, but tensor_parallel_degree=2; ..."
Round 3 status
- New: the TP refusal (
engine.py:318) comes before the window check and readsparallelism.tensor_parallel_degree, the fieldInferenceParallelismConfigdefines (parallelism.py:21). It has a TODO that says what to check before lifting it (TP2 logprobs vs TP1). The test is a third id in the existingtest_fp8_kv_cache_refusals, not a new test. - Still open: items 1 and 2 below.
Must fix
- The PR description's Summary (human-written) section is still empty. The author needs to fill it in.
torchtitan/rl/generator/attention/attention.py:61-- the TODO on the private_flash_attn_fwdcall still says "no torch issue filed yet". It needs a pytorch/pytorch issue link (CLAUDE.md principle 3).
Not verified: the TP refusal only runs at engine start, and no GPU test reaches it (the CPU test covers it).
…fy steps included VLLMEngine.Config.kv_cache_dtype="fp8" stores K/V in e4m3 at scale 1 and runs FA4's fp8 forward; paged_varlen_attention_out picks it from the cache dtype. MTP verify steps make one varlen call. Refused: debug.batch_invariant, tensor parallelism, sliding windows, and GPUs outside SM100.
0e7ce67 to
4bf200c
Compare
|
Reply from claude: @claude please review |
|
Claude finished @felipemello1's task in 3m 14s —— View job Approve, no must-fix items left; three open questions are in the review (vLLM's dynamic KV scales, fp8 on MLA-shaped layers, an fp8 + MTP engine run): review |
There was a problem hiding this comment.
Verdict: Approve -- the rewrite (4bf200c) is smaller than the round-3 version. It drops the descale plumbing and runs fp8 MTP verify steps through the existing varlen call. Both round-3 must-fix items are cleared. A maintainer still needs to review.
What this PR does. It adds VLLMEngine.Config.kv_cache_dtype: Literal["auto", "fp8"] and forwards it to EngineArgs. With fp8, TorchTitanVarlenInnerAttentionImpl views vLLM's uint8 cache as e4m3. paged_varlen_attention_out then sees an e4m3 key_cache and calls FA4's private _flash_attn_fwd with every scale left at 1. fp8 verify steps skip _verify_rows_as_decode and make one varlen call with max_seqlen_q = 1 + k. fp8 is refused with batch-invariant mode, with TP > 1, on models with sliding-window layers, and on non-SM100 GPUs (in supports_combination).
Example.
Qwen3.8-27B, VLLMEngine.Config(kv_cache_dtype="fp8", num_speculative_tokens=3), GB300
round 3 (e5678e9a6): ValueError at config time (verify rows passed no descales)
4bf200c: verify step, 26 rows x 4 tokens -> one _flash_attn_fwd(q_e4m3, k_e4m3, v_e4m3,
cu_seqlens_q=query_start_loc, max_seqlen_q=4); no decode call, no fp32 tail
kv_cache_dtype="auto": the same code as before (`not is_fp8` only adds a term to the verify-path condition)
Round 3 status
- Resolved: the upstream link. The TODO now points at pytorch/pytorch#206590 and Dao-AILab/flash-attention#3217 (
torchtitan/rl/generator/attention/attention.py:58). - Moot: the config-time drafts check. fp8 + drafts is supported now, and
VLLMEngine.Configno longer refuses it.
Should consider
- #6413 (SGLang fp8, based on
main) adds the samepaged_varlen_attention_outhunk (blob4c9896ee28). #6366 (a draft based on this branch) adds fp8 verify rows with descales, which this PR now covers in a different way. Land the shared hunk once and rebase the other PR onto it. Close #6366 or say what it still adds.
Questions
- Scales of 1 are assumed but never checked. vLLM's
Attentioncomputes dynamic q/k/v scales whencache_config.calculate_kv_scalesis set.add_extra_vllm_engine_argsdoes not block that key (engine.py:89). If vLLM still honors it, the cache write and the query quantization would use those scales while FA4 assumes 1, and the logprobs would be silently wrong. Is that reachable? If so, add"calculate_kv_scales"to the refused keys, or raise when fp8 is set together with it. Unverified: whether the pinned vLLM still has the field. - Uncompressed MLA layers (head dim 192, V head dim 128) go through
TorchTitanVarlenInnerAttentionDiffKVBackend. It does not overridesupports_combination(vllm/attention/attention.py:168), andVLLMInnerAttentionpasses it asattn_backend(:670). If vLLM doesn't re-validate a backend passed this way, fp8 runs FA4's fp8 forward at 192/128, and no test or run covers that. The TP and sliding-window cases are refused for the same reason. Does vLLM refuse this at engine start? If not, a refusal next to the window check would fit, raised when any full-attention layer's value head dim differs from its head dim. Unverified: vLLM isn't importable here. - There is no engine run for the one-call fp8 verify path (body NOTE). A short MTP-3 + fp8 engine run would show that it composes with FULL graphs for steps with prefill (the PR below this one). Is one planned before merge?
Details
- Gate: unchanged from earlier rounds. The problem is real (an assert on the base branch). The fix is in TorchTitan's backend, which is the right layer. It is opt-in. Dropping the descales removes the
(batch, num_kv_heads)expansion and the scale reads from forward, and the TODO atVLLMInnerAttention.__init__names what calibrated scales would need. - Checked at HEAD: in the fp8 mixed-batch split, both calls write
out=output[:num_actual_tokens]with clampedcu_seqlens_q, so each call writes only its own rows, as in the bf16 path. The fp8num_splitsfollowstorch.are_deterministic_algorithms_enabled(), and batch-invariant mode is refused for fp8 anyway. The window and TP checks needmodelandparallelism, so engine init is the right place for them. - The GPU test count stays the same for fp8 verify: one call through
_verify_rows_as_decode(bf16) and one varlen call (fp8). The new asserts onmax_seqlen_q == 4andcu_seqlens_q is query_start_locpin the one-call path. - Overlap search:
fp8 kv cache-> #6413, #6366;paged_varlen_attention_out-> #6413.
Not verified: GPU behavior; vLLM internals (query_quant setup, validation of a backend passed as attn_backend, calculate_kv_scales).
Before merge: fill in the human-written summary.
…-kv-cache # Conflicts: # torchtitan/rl/generator/vllm/engine.py
|
Reply from claude: The review's three questions. Fixed in 6348be1: MLA layers are refused.
mla_layers = [
layer_id
for layer_id, layer in enumerate(model.layers)
if hasattr(layer.attention, "qk_nope_head_dim")
]
if mla_layers:
# TODO: test fp8 with MLA (DeepSeek-V3, Kimi K3), then lift this. Its K and V head dims
# differ, and vLLM runs the attention backend TorchTitan passes for it unchecked.
raise ValueError(
"kv_cache_dtype='fp8' is untested with MLA attention, but layers "
f"{mla_layers[:2]} use it; set kv_cache_dtype='auto'"
)
|
|
Reply from claude: @claude please review |
|
Claude finished @felipemello1's task in 1m 38s —— View job Approve, no must-fix items. The new MLA refusal (6348be1) settles the last open question, and two optional suggestions are in the review. |
There was a problem hiding this comment.
Verdict: Approve -- since my last full review (4bf200c) there is one new commit, 6348be1, which refuses fp8 on MLA layers. I have no must-fix items. A maintainer still needs to review.
What changed since the last review. The merge commit 05a15fe only brings in the base branch. I compared this PR's diff on the 5 changed files before and after the merge, and the MLA commit is the only difference. 6348be1 adds a refusal at engine start, next to the sliding-window check, and adds an mla case to the existing test_fp8_kv_cache_refusals.
Example.
VLLMEngine.Config(kv_cache_dtype="fp8"), a DeepSeek-V3 / Kimi K2.7 / Kimi K3 model
4bf200c: builds; FA4's fp8 forward would run at qk 192 / v 128, which no run has covered
6348be1: ValueError "kv_cache_dtype='fp8' is untested with MLA attention, but layers [0, 1] use it; ..."
Answers to the round-4 questions
calculate_kv_scales: the author says the pinned vLLM (9f03b510c) has no such field, soEngineArgsrejects the key. That rules out the silent scale mismatch I asked about.- MLA: resolved by the refusal. It uses the same discriminator as
get_attention_dimensions(model.py:54), and every MLA attention config hasqk_nope_head_dim:deepseek_v3/attention.py:44, which kimi_k2_7 reuses, andkimi_k3_1/flavors.py:117. - fp8 + MTP engine run: an 8-request smoke run with k = 3 and FULL graphs finished. The body says it has no throughput or logprob check, which is enough for an opt-in path.
Should consider
torchtitan/rl/generator/vllm/engine.py:401-- the check could callget_attention_dimensionsinstead of repeating itshasattrtest (inline). Optional.- Still open from round 4: #6413 (SGLang fp8) adds the same
paged_varlen_attention_outhunk, and #6366 (a draft based on this branch) adds fp8 verify rows that this PR already covers in another way. Land the shared hunk once, and close #6366 or say what it still adds.
Details
- Gate: unchanged. The problem is real on the base branch (an assert). The fix is in TorchTitan's backend, which is the right layer, and it is opt-in: "auto" runs the same code as before.
- The new refusal reads the model config, so engine init is the right place for it, as for the window and TP checks. The test adds an id to the existing parametrize, not a new test.
- Overlap search:
fp8 kv cache-> #6413, #6366 (unchanged).
Not verified: the pinned vLLM has no calculate_kv_scales field. vLLM isn't importable here, so this rests on the author's reply.
Before merge: fill in the human-written summary.
| mla_layers = [ | ||
| layer_id | ||
| for layer_id, layer in enumerate(model.layers) | ||
| if hasattr(layer.attention, "qk_nope_head_dim") | ||
| ] |
There was a problem hiding this comment.
hasattr(layer.attention, "qk_nope_head_dim") copies the duck-type test inside get_attention_dimensions (torchtitan/rl/generator/model.py:54). The TODO gives the reason for the refusal as "K and V head dims differ". If a second attention type ever gets a different V head dim, get_attention_dimensions will learn about it, but this check will not. You could ask the function for the fact itself, which keeps one definition:
mla_layers = [
layer_id
for layer_id, layer in enumerate(model.layers)
if len(set(get_attention_dimensions(layer.attention, model.dim)[2:])) > 1
]Today it refuses the same layers. The error message could then say "different K and V head dims" instead of "MLA". This is optional; the current check is correct for every model in the repo.
…pytorch#6366 on pytorch#6365's head) Port of pytorch#6366 (ad1774b; its own delta e5678e9..ad1774b) onto pytorch#6365's head 6348be1, which dropped the descales: fp8 is now told by the cache dtype. As r8 (597ebff) ran it: - paged_varlen_attention_out takes query_len_in_heads on the fp8 path; fa4_takes_query_len_in_heads(). - Uniform fp8 verify steps go to _verify_rows_as_decode at any row count, which makes one decode call over every key; FA4 hides each token's later keys. V head dims unlike K's keep the varlen call. - The engine refuses fp8 with drafts on an FA4 without query_len_in_heads. Needs an FA4 with query_len_in_heads (Dao-AILab/flash-attention#3217); the r11 run puts r8's copy fa4_b40_fp8swapab first on PYTHONPATH. Per layer on the r11 venv (runshared:46): verify 1.436 -> 0.973 ms, decode 1.433 -> 0.953 ms.
|
Superseded by #6479 |
Summary (human-written)
Agent details
Needs retesting on B200 (SM100): every number below is from one GB300 (SM103). FA4's split heuristics are tuned per GPU, so B200 timings can differ.
Stack, bottom to top:
The stack lands after the vLLM 0.33 PRs ("[rl] generator: vLLM 0.33 API fixes and TP padding in the model wrapper", "[rl] Install vLLM 0.33.0 on the torch nightly"). "[rl] generator: run on vLLM's model runner V2 (vLLM 0.34)" rebases on it.
TLDR:
VLLMEngine.Config.kv_cache_dtype = "fp8"stores K and V in e4m3 and runs FA4's fp8 forward for decode and prefill rows. "auto" (bf16) stays the default and keeps the trainer's kernel. Qwen3.8-27B on one GB300: 2x the KV tokens (5.81M vs 2.90M), and 1,043 vs 902 output tok/s at 32 sessions with 27k-135k contexts. With fp8 SwapAB decode (an open FA4 PR), the same code gives 1,170. MTP drafts work with fp8 too: each verify step is one FA4 varlen call.Problem
"FP8 KV cache not supported yet.".FlashAttentionBackendis about vLLM's own FlashAttention build, which has no fp8 kernel at head dim 256. TorchTitan's backend subclasses it, so the check would refuse fp8 too.Solution
kv_cache_dtype: Literal["auto", "fp8"], passed to vLLM'sEngineArgs. vLLM's cache write needed no change.VLLMInnerAttentionbuilds vLLM'sAttentionwithout a quant_config.paged_varlen_attention_outpicks the fp8 path from the cache dtype. It calls FA4's private_flash_attn_fwdwith the arguments torch's FA4 bridge passes.num_splitsis 1 under deterministic algorithms, as torch's bridge sets it for the bf16 call.supports_combinationhides fp8 fromFlashAttentionBackend's check, and refuses a non-SM100 GPU with a reason. The impl passes "auto" toFlashAttentionImpl.__init__for the same reason.debug.batch_invariant: the trainer runs bf16.out_transform), so this covers sinks too.tensor_parallel_degree> 1: untested.max_seqlen_q = 1 + k, at any row count. They skip the verify-steps PR's decode call + fp32 tail, which has no fp8 path.Results
When KV is full (46 sessions, 80 GiB CPU KV offload, FA4 with fp8 SwapAB): fp8 gives 1,303 output tok/s with KV at 51-54% and no request waiting, vs 788 for bf16 with KV at 89-92%. Not a controlled pair: fp8 ran at gpu memory 0.9, bf16 at 0.85.
Where fp8 does not gain: on FA4 4.0.0b40, SwapAB takes only bf16/fp16, so fp8 decode runs FA4's standard kernel, which gets almost nothing from L2 on shared prompt pages. One layer, 26 requests in 3 groups sharing 27k / 55k / 77k prompts: 0.685 ms in fp8 vs 0.581 ms for bf16 SwapAB. With the FA4 fp8 SwapAB PR: 0.346 ms.
NOTE:
vllm/attention/attention.py; the one that lands second rebases: the vLLM V2 model runner PR and the ROCm paged-KV gather PR.You may ask: why FA4's private
_flash_attn_fwd? torch's varlen attention takes no fp8 inputs, and FA4's publicflash_attn_varlen_funchas noout=to write into vLLM's output buffer. An open PyTorch PR adds fp8 descales tovarlen_attn. TODO at the site to switch to torch's call once it lands.Follow up / TODO (each has a
# TODOat its site)paged_varlen_attention_out. The gain is not measured.varlen_attn_outonce the open PyTorch PR lands, instead of FA4's private call.FlashAttentionBackend's check if this backend stops subclassing it.prefix_match_unitor a smallermamba_block_size.Test plan