Repository navigation
[rl] vLLM generator: fp8 KV cache through FA4's fp8 forward, MTP verify steps included - #6479
Draft
liangel-02 wants to merge 3 commits into
Draft
liangel-02 wants to merge 3 commits into
liangel-02 wants to merge 3 commits into
Conversation
…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.
…-kv-cache # Conflicts: # torchtitan/rl/generator/vllm/engine.py
6 tasks
This was referenced Dec 2, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #6365 (originally by felipemello1).
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