[Attention] Decode an NVFP4 KV cache with XQA on SM12x (#60452)

Signed-off-by: lesj0610 <lesj0610@gmail.com>
Co-authored-by: Misha Goin <mgoin64@gmail.com>
This commit is contained in:
SeongJun Lee
2026-10-09 22:24:00 -06:00
committed by GitHub
co-authored by Misha Goin
parent 29e4d2d42e
commit 9bd074a996
3 changed files with 121 additions and 10 deletions
+12 -9
View File
@@ -878,12 +878,10 @@ class FlashInferMetadataBuilder(AttentionMetadataBuilder[FlashInferMetadata]):
# Prefer TRTLLM/XQA for decoding whenever supported. The decode kernel
# must be selected statically for FULL cudagraph capture.
can_use_xqa_or_trtllm_gen_decode = (
can_use_trtllm_attention(
self.num_qo_heads, self.num_kv_heads, is_prefill=False
)
and not self.nvfp4_fa2
)
# XQA reads an NVFP4 cache only on SM12x; SM90 decodes it with fa2.
can_use_xqa_or_trtllm_gen_decode = can_use_trtllm_attention(
self.num_qo_heads, self.num_kv_heads, is_prefill=False
) and (not self.nvfp4_fa2 or current_platform.is_device_capability_family(120))
# Page sizes >= 128 require the trtllm-gen GQA/MQA path (guaranteed by
# get_supported_kernel_block_sizes).
assert self.page_size <= 64 or (
@@ -1078,7 +1076,10 @@ class FlashInferMetadataBuilder(AttentionMetadataBuilder[FlashInferMetadata]):
) or (
is_xqa_arch
and (
spec.kv_quant_mode.is_nvfp4
(
spec.kv_quant_mode.is_nvfp4
and not current_platform.is_device_capability_family(120)
)
or not _is_xqa_head_dim_supported(spec.head_size)
)
):
@@ -2283,7 +2284,6 @@ class FlashInferImpl(AttentionImpl):
use_dcp = self.dcp_world_size > 1
if decode_with_xqa:
assert not use_dcp
assert not self.is_kvcache_nvfp4
assert self.o_sf_scale is None
assert output.dtype != FP4_DTYPE
@@ -2628,7 +2628,10 @@ class FlashInferImpl(AttentionImpl):
flashinfer_xqa_batch_decode_with_kv_cache(
query=decode_query,
kv_cache=kv_cache_tuple,
kv_cache=(
nvfp4_kv_data if self.is_kvcache_nvfp4 else kv_cache_tuple
),
kv_cache_sf=nvfp4_kv_block_scales,
workspace_buffer=workspace_buffer,
block_tables=block_tables_decode,
seq_lens=seq_lens_decode,