[Kernel] Gemma-4 FA4 FP8 Kernel (#48666)

Signed-off-by: Qixiang Lin <qixiangl@nvidia.com>
Signed-off-by: Jhao-Ting Chen <jhaotingc@nvidia.com>
Co-authored-by: Qixiang Lin <qixiangl@nvidia.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Yongye Zhu <zyy1102000@gmail.com>
This commit is contained in:
Jhao-Ting Chen
2026-08-13 17:42:00 -07:00
committed by GitHub
co-authored by Qixiang Lin Claude Opus 4.8 Yongye Zhu
parent 38f097fab8
commit 827a2af806
8 changed files with 152 additions and 29 deletions
+20 -3
View File
@@ -404,6 +404,22 @@ def flash_attn_varlen_func(
from vllm.vllm_flash_attn.cute.interface import _flash_attn_fwd
# SM90 FA4 fp8-KV path: fp8 e4m3 paged K/V dequantized and the K/V descale folded
# in-kernel; accepts bf16/fp16 Q and writes O in its native dtype (no Q cast, no
# output copy). Only the (batch, num_kv_heads) f32 K/V descales are forwarded.
fa4_fp8_kv_dequant = (
k.dtype == torch.float8_e4m3fn
and torch.cuda.get_device_capability()[0] == 9
)
if fa4_fp8_kv_dequant:
fa4_q_descale = None
fa4_k_descale = k_descale
fa4_v_descale = v_descale
else:
fa4_q_descale = None
fa4_k_descale = None
fa4_v_descale = None
out, softmax_lse, _, _ = _flash_attn_fwd(
q,
k,
@@ -428,10 +444,11 @@ def flash_attn_varlen_func(
block_sparse_tensors=block_sparse_tensors,
aux_tensors=aux_tensors,
aux_tensor_leading_dims=aux_tensor_leading_dims,
q_descale=q_descale,
k_descale=k_descale,
v_descale=v_descale,
q_descale=fa4_q_descale,
k_descale=fa4_k_descale,
v_descale=fa4_v_descale,
output_scale=output_scale,
fp8_kv_dequant=fa4_fp8_kv_dequant,
)
else:
raise ValueError(f"Unsupported FA version: {fa_version}")