[Dependency] Upgrade FlashInfer version to 0.7.0 (#58069)

Signed-off-by: wzhao18 <wzhao18.sz@gmail.com>
Co-authored-by: Codex <noreply@openai.com>
Co-authored-by: Yongye Zhu <zyy1102000@gmail.com>
Co-authored-by: Kevin H. Luu <khluu000@gmail.com>
This commit is contained in:
Wei Zhao
2026-09-23 22:45:23 -07:00
committed by GitHub
co-authored by Codex Yongye Zhu Kevin H. Luu
parent a1b6763df6
commit 44bf011f44
15 changed files with 197 additions and 31 deletions
@@ -227,6 +227,7 @@ def fi_chunk_gated_delta_rule(
initial_state=fi_state,
output_final_state=output_final_state,
cu_seqlens=cu_seqlens,
backend="flashinfer",
)
# FlashInfer returns (output, state) when output_final_state=True,
# or just output when output_final_state=False.
@@ -1234,7 +1234,7 @@ def build_flashinfer_mixed_sparse_indices(
def _remap_flashinfer_index(values, block_size, block_span):
# FlashInfer's DSv4 kernel indexes sparse KV by physical token stride, so
# packed pages (#44577) need block*block_size+off -> block*block_span+off.
# TODO: remove once flashinfer-ai/flashinfer#3856 is fixed.
# The launcher declares these indices with sparse_indices_are_storage_offsets=True.
is_valid = values >= 0
safe_values = tl.where(is_valid, values, 0)
values = (safe_values // block_size) * block_span
@@ -521,6 +521,7 @@ class DeepseekV4FlashInferMLAAttention(DeepseekV4Attention):
swa_kv_cache=swa_k_cache,
workspace_buffer=workspace,
sparse_indices=sparse_indices[:num_decode_tokens],
sparse_indices_are_storage_offsets=True,
compressed_kv_cache=compressed_kv_cache,
sparse_topk_lens=sparse_topk_lens[:num_decode_tokens],
seq_lens=seq_lens[:num_decodes],
@@ -546,6 +547,7 @@ class DeepseekV4FlashInferMLAAttention(DeepseekV4Attention):
swa_kv_cache=swa_k_cache,
workspace_buffer=workspace,
sparse_indices=sparse_indices[num_decode_tokens:num_tokens],
sparse_indices_are_storage_offsets=True,
compressed_kv_cache=compressed_kv_cache,
sparse_topk_lens=sparse_topk_lens[num_decode_tokens:num_tokens],
seq_lens=seq_lens[num_decodes:num_reqs],
@@ -1266,7 +1266,7 @@ def build_flashinfer_mixed_sparse_indices(
def _remap_flashinfer_index(values, block_size, block_span):
# FlashInfer's DSv4 kernel indexes sparse KV by physical token stride, so
# packed pages (#44577) need block*block_size+off -> block*block_span+off.
# TODO: remove once flashinfer-ai/flashinfer#3856 is fixed.
# The launcher declares these indices with sparse_indices_are_storage_offsets=True.
is_valid = values >= 0
safe_values = tl.where(is_valid, values, 0)
values = (safe_values // block_size) * block_span
@@ -560,6 +560,7 @@ class DeepseekV4FlashInferMLAAttention(DeepseekV4Attention):
swa_kv_cache=swa_k_cache,
workspace_buffer=workspace,
sparse_indices=sparse_indices[:num_decode_tokens],
sparse_indices_are_storage_offsets=True,
compressed_kv_cache=compressed_kv_cache,
sparse_topk_lens=decode_topk_lens,
seq_lens=decode_seq_lens,
@@ -585,6 +586,7 @@ class DeepseekV4FlashInferMLAAttention(DeepseekV4Attention):
swa_kv_cache=swa_k_cache,
workspace_buffer=workspace,
sparse_indices=sparse_indices[num_decode_tokens:num_tokens],
sparse_indices_are_storage_offsets=True,
compressed_kv_cache=compressed_kv_cache,
sparse_topk_lens=sparse_topk_lens[num_decode_tokens:num_tokens],
seq_lens=seq_lens[num_decodes:num_reqs],
@@ -43,6 +43,7 @@ from vllm.model_executor.layers.attention.sparse_mla_attention import (
SparseMLACommonImpl,
)
from vllm.platforms.interface import DeviceCapability
from vllm.triton_utils import tl, triton
from vllm.utils.flashinfer import has_flashinfer_sm90_nope_mla
from vllm.v1.attention.backend import (
AttentionBackend,
@@ -64,6 +65,23 @@ _FP8_KV_DTYPES = ("fp8", "fp8_e4m3")
_WORKSPACE_BYTES = 128 * 1024 * 1024
@triton.jit
def _pack_topk_indices(
slots,
indptr,
indices,
WIDTH: tl.constexpr,
BLOCK_SIZE: tl.constexpr,
):
row = tl.program_id(0).to(tl.int64)
cols = tl.program_id(1) * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)
start = tl.load(indptr + row)
end = tl.load(indptr + row + 1)
mask = (cols < end - start) & (cols < WIDTH)
values = tl.load(slots + row * WIDTH + cols, mask=mask, other=0)
tl.store(indices + start + cols, tl.maximum(values, 0), mask=mask)
class FlashInferMLASparseSM90Backend(AttentionBackend):
supported_dtypes: ClassVar[list[torch.dtype]] = [torch.bfloat16]
supported_kv_cache_dtypes: ClassVar[list[CacheDType]] = [
@@ -192,10 +210,11 @@ class _SM90State:
self.kv_len_arr = torch.full(
(max_tokens,), topk_width, dtype=torch.int32, device=device
)
self.kv_indptr = torch.zeros(max_tokens + 1, dtype=torch.int32, device=device)
self.wrapper = BatchMLAPagedAttentionWrapper(
self.workspace,
qo_indptr=torch.zeros(max_tokens + 1, dtype=torch.int32, device=device),
kv_indptr=torch.zeros(max_tokens + 1, dtype=torch.int32, device=device),
kv_indptr=self.kv_indptr,
kv_indices=self.kv_indices,
kv_len_arr=self.kv_len_arr,
use_cuda_graph=True,
@@ -234,12 +253,13 @@ class _SM90State:
# fixed (max_tokens+1)-sized buffers with exact-size copy_, so the
# indptr must always be full-size. Rows past num_tokens are padded
# empty (qo_indptr flat at num_tokens) — zero-query rows read no q
# and schedule no work. Padded rows keep the full width lens; the
# value is never dereferenced.
# and schedule no work. FlashInfer 0.7 requires packed CSR offsets
# matching the exact lengths, including zero-length padded rows.
torch.clamp(self._arange_cpu, max=num_tokens, out=self._qo_cpu)
torch.mul(self._qo_cpu, self.topk_width, out=self._kv_cpu)
self._lens_cpu.fill_(self.topk_width)
self._lens_cpu.zero_()
self._lens_cpu[:num_tokens] = kv_lens.to(torch.int32)
self._kv_cpu[0] = 0
torch.cumsum(self._lens_cpu, dim=0, out=self._kv_cpu[1:])
self.wrapper.plan(
self._qo_cpu,
self._kv_cpu,
@@ -255,6 +275,12 @@ class _SM90State:
kv_data_type=self.kv_dtype,
)
def pack_indices(self, topk_slots: torch.Tensor) -> None:
num_tokens, width = topk_slots.shape
_pack_topk_indices[(num_tokens, triton.cdiv(width, 256))](
topk_slots, self.kv_indptr, self.kv_indices, width, 256
)
@dataclass
class FlashInferMLASparseSM90Metadata(FlashInferMLASparseMetadata):
@@ -462,12 +488,8 @@ class FlashInferMLASparseSM90Impl(SparseMLACommonImpl[FlashInferMLASparseSM90Met
)
state = attn_metadata.state
assert state is not None
# Refresh top-k rows in graph and clamp masked tails to a valid slot;
# per-row lengths are already baked into the host-side plan.
width = topk_slots.shape[1]
state.kv_indices[: num_tokens * width].copy_(
topk_slots.reshape(-1).clamp_(min=0).to(torch.int32)
)
# Pack valid prefixes at the offsets refreshed by plan() before replay.
state.pack_indices(topk_slots)
flat = (
kv_c_and_k_pe_cache.view(torch.float8_e4m3fn)
+13 -3
View File
@@ -79,9 +79,9 @@ def flashinfer_sampler_supported() -> bool:
Returns False (with appropriate logging) when ``VLLM_USE_FLASHINFER_SAMPLER``
is 0, when the platform isn't CUDA, when the GPU's compute capability is
unsupported, or when FlashInfer cannot JIT-compile for the current
GPU/CUDA toolchain. Raises ``RuntimeError`` if the user explicitly opted in
via the env var but FlashInfer is unavailable.
unsupported, when the GPU has 16 or fewer SMs, or when FlashInfer cannot
JIT-compile for the current GPU/CUDA toolchain. Raises ``RuntimeError`` if
the user explicitly opted in via the env var but FlashInfer is unavailable.
Assumes flashinfer is installed, as guaranteed by ``requirements/cuda.txt``;
otherwise importing the FlashInfer backend below raises ``ImportError``.
@@ -107,6 +107,16 @@ def flashinfer_sampler_supported() -> bool:
unsupported_reason = (
f"unsupported compute capability {capability.as_version_str()}"
)
elif (
num_sms := current_platform.num_compute_units(
torch.accelerator.current_device_index()
)
) <= 16:
# FlashInfer 0.7+ rejects multi-CTA top-k masking on <=16 SMs because
# its cross-CTA software barrier cannot guarantee forward progress.
unsupported_reason = (
f"top-k masking requires more than 16 SMs; device has {num_sms}"
)
else:
unsupported_reason = _flashinfer_jit_unsupported_reason(capability)