[2/N][Feat][Perf] Add new warmup infrastructure for JITs. Add predicate filtering for JIT warmup, and migrate Inkling FA4 (#49315)

Signed-off-by: LopezCastroRoberto <rocastro@redhat.com>
Signed-off-by: Roberto L. Castro <38211239+LopezCastroRoberto@users.noreply.github.com>
Co-authored-by: Lucas Wilkinson <LucasWilkinson@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
Roberto L. Castro
2026-08-11 07:46:07 -04:00
committed by GitHub
co-authored by Lucas Wilkinson mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent d8f840071e
commit 6c95a641e9
12 changed files with 739 additions and 386 deletions
@@ -13,7 +13,7 @@ import vllm.envs as envs
from vllm.model_executor.layers.quantization.utils.quant_utils import (
kFp8StaticTensorSym,
)
from vllm.model_executor.warmup.jit_warmup import VllmJitKernel
from vllm.model_executor.warmup.jit_warmup import VllmJitKernel, zip_inputs
from vllm.platforms import current_platform
from vllm.v1.attention.backends.fa_utils import (
compile_flash_attn_varlen_func_from_specs,
@@ -57,12 +57,6 @@ FA4_MLA_PREFILL_CAUSAL_OPTIONS = (False, True)
FA4_MLA_PREFILL_LSE_OPTIONS = (False, True)
@dataclass(frozen=True)
class _FA4MLAPrefillShapeProbe:
max_seqlen_q: int
max_seqlen_k: int
class FA4MLAPrefillKernel(VllmJitKernel["FA4MLAPrefillKernel.CompileKey"]):
"""FA4 MLA prefill compile-key wrapper used by generic JIT warmup."""
@@ -92,6 +86,16 @@ class FA4MLAPrefillKernel(VllmJitKernel["FA4MLAPrefillKernel.CompileKey"]):
return_softmax_lse: bool = False
num_splits: int = 0
@staticmethod
def kernel(
*args: Any,
runtime_kernel: Callable[..., Any] | None = None,
**kwargs: Any,
) -> Any:
kernel = flash_attn_varlen_func if runtime_kernel is None else runtime_kernel
assert kernel is not None
return kernel(*args, **kwargs)
def dispatch( # type: ignore[override]
self,
*,
@@ -99,7 +103,8 @@ class FA4MLAPrefillKernel(VllmJitKernel["FA4MLAPrefillKernel.CompileKey"]):
dtype: torch.dtype,
num_heads: int,
mla_dims: "MLADims",
shape_probe: _FA4MLAPrefillShapeProbe,
max_seqlen_q: int,
max_seqlen_k: int,
requires_v_padding: bool,
causal: bool,
fa_version: int,
@@ -109,17 +114,17 @@ class FA4MLAPrefillKernel(VllmJitKernel["FA4MLAPrefillKernel.CompileKey"]):
) -> CompileKey:
return self.CompileKey(
q_shape=(
batch_size * shape_probe.max_seqlen_q,
batch_size * max_seqlen_q,
num_heads,
mla_dims.qk_nope_head_dim + mla_dims.qk_rope_head_dim,
),
k_shape=(
batch_size * shape_probe.max_seqlen_k,
batch_size * max_seqlen_k,
num_heads,
mla_dims.qk_nope_head_dim + mla_dims.qk_rope_head_dim,
),
v_shape=(
batch_size * shape_probe.max_seqlen_k,
batch_size * max_seqlen_k,
num_heads,
(
mla_dims.qk_nope_head_dim + mla_dims.qk_rope_head_dim
@@ -128,8 +133,8 @@ class FA4MLAPrefillKernel(VllmJitKernel["FA4MLAPrefillKernel.CompileKey"]):
),
),
q_dtype=dtype,
max_seqlen_q=shape_probe.max_seqlen_q,
max_seqlen_k=shape_probe.max_seqlen_k,
max_seqlen_q=max_seqlen_q,
max_seqlen_k=max_seqlen_k,
softmax_scale=(mla_dims.qk_nope_head_dim + mla_dims.qk_rope_head_dim)
** -0.5,
causal=causal,
@@ -150,6 +155,28 @@ class FA4MLAPrefillKernel(VllmJitKernel["FA4MLAPrefillKernel.CompileKey"]):
num_splits=num_splits,
)
def _is_valid_warmup_shape_probe(
self,
*,
max_seqlen_k: int,
num_splits: int,
is_sm90: bool,
qk_head_dim: int,
effective_v_head_dim: int,
) -> bool:
long_k = FA4_MLA_PREFILL_LONG_K_BLOCKS * FA4_MLA_PREFILL_K_TILE
very_long_k = FA4_MLA_PREFILL_VERY_LONG_K_BLOCKS * FA4_MLA_PREFILL_K_TILE
return (
max_seqlen_k < long_k
or (num_splits != 1 and max_seqlen_k == long_k)
or (
num_splits != 1
and max_seqlen_k == very_long_k
and not is_sm90
and qk_head_dim != effective_v_head_dim
)
)
def get_warmup_keys(self, vllm_config: "VllmConfig") -> list[CompileKey]:
from vllm.model_executor.layers.attention.mla_attention import (
get_mla_dims,
@@ -185,58 +212,49 @@ class FA4MLAPrefillKernel(VllmJitKernel["FA4MLAPrefillKernel.CompileKey"]):
effective_v_head_dim = (
qk_head_dim if requires_v_padding else mla_dims.v_head_dim
)
shape_probes = [
_FA4MLAPrefillShapeProbe(1, FA4_MLA_PREFILL_K_TILE),
_FA4MLAPrefillShapeProbe(
FA4_MLA_PREFILL_Q_TILE + 1,
4 * FA4_MLA_PREFILL_K_TILE,
shape_probes = (
dict(max_seqlen_q=1, max_seqlen_k=FA4_MLA_PREFILL_K_TILE),
dict(
max_seqlen_q=FA4_MLA_PREFILL_Q_TILE + 1,
max_seqlen_k=4 * FA4_MLA_PREFILL_K_TILE,
),
]
if num_splits != 1:
shape_probes.extend(
(
_FA4MLAPrefillShapeProbe(
1,
FA4_MLA_PREFILL_LONG_K_BLOCKS * FA4_MLA_PREFILL_K_TILE,
),
_FA4MLAPrefillShapeProbe(
FA4_MLA_PREFILL_Q_TILE + 1,
FA4_MLA_PREFILL_LONG_K_BLOCKS * FA4_MLA_PREFILL_K_TILE,
),
)
)
if not is_sm90 and qk_head_dim != effective_v_head_dim:
shape_probes.extend(
(
_FA4MLAPrefillShapeProbe(
1,
FA4_MLA_PREFILL_VERY_LONG_K_BLOCKS * FA4_MLA_PREFILL_K_TILE,
),
_FA4MLAPrefillShapeProbe(
FA4_MLA_PREFILL_Q_TILE + 1,
FA4_MLA_PREFILL_VERY_LONG_K_BLOCKS * FA4_MLA_PREFILL_K_TILE,
),
)
)
dict(
max_seqlen_q=1,
max_seqlen_k=FA4_MLA_PREFILL_LONG_K_BLOCKS * FA4_MLA_PREFILL_K_TILE,
),
dict(
max_seqlen_q=FA4_MLA_PREFILL_Q_TILE + 1,
max_seqlen_k=FA4_MLA_PREFILL_LONG_K_BLOCKS * FA4_MLA_PREFILL_K_TILE,
),
dict(
max_seqlen_q=1,
max_seqlen_k=FA4_MLA_PREFILL_VERY_LONG_K_BLOCKS
* FA4_MLA_PREFILL_K_TILE,
),
dict(
max_seqlen_q=FA4_MLA_PREFILL_Q_TILE + 1,
max_seqlen_k=FA4_MLA_PREFILL_VERY_LONG_K_BLOCKS
* FA4_MLA_PREFILL_K_TILE,
),
)
return self._trace_dispatch(self.dispatch)(
zip_inputs(*shape_probes),
batch_size=FA4_MLA_PREFILL_COMPILE_BATCH_SIZE,
dtype=dtype,
num_heads=num_heads,
mla_dims=mla_dims,
shape_probe=shape_probes,
requires_v_padding=requires_v_padding,
is_sm90=is_sm90,
qk_head_dim=qk_head_dim,
effective_v_head_dim=effective_v_head_dim,
causal=FA4_MLA_PREFILL_CAUSAL_OPTIONS,
return_lse=FA4_MLA_PREFILL_LSE_OPTIONS,
num_splits=num_splits,
fa_version=fa_version,
_when=self._is_valid_warmup_shape_probe,
)
@staticmethod
def kernel(*args: Any, **kwargs: Any) -> Any:
assert flash_attn_varlen_func is not None
return flash_attn_varlen_func(*args, **kwargs)
def compile(self, compile_key: CompileKey) -> None:
assert compile_flash_attn_varlen_func_from_specs is not None
window_size = (
@@ -271,11 +289,13 @@ class FA4MLAPrefillKernel(VllmJitKernel["FA4MLAPrefillKernel.CompileKey"]):
runtime_kernel: Callable[..., Any] | None = None,
**kwargs: Any,
) -> Any:
kernel = self.kernel if runtime_kernel is None else runtime_kernel
return kernel(q=q, k=k, v=v, **kwargs)
FA4_MLA_PREFILL_KERNEL = FA4MLAPrefillKernel()
return self.kernel(
q=q,
k=k,
v=v,
runtime_kernel=runtime_kernel,
**kwargs,
)
class FlashAttnPrefillBackend(MLAPrefillBackend):
@@ -470,3 +490,6 @@ class FlashAttnPrefillBackend(MLAPrefillBackend):
causal=False, # Context is unmasked
return_softmax_lse=True,
)
FA4_MLA_PREFILL_KERNEL = FA4MLAPrefillKernel()