Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions tests/model_executor/test_jit_warmup.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,38 @@ def test_trace_dispatch_combines_zipped_rows_with_independent_values() -> None:
]


def test_trace_dispatch_filters_with_traced_predicate() -> None:
class PredicateKernel(ToyKernel):
def _is_valid_warmup_dispatch(
self,
*,
tokens: int,
lanes: int,
max_work: int,
) -> bool:
block_size = _next_power_of_2(tokens)
return block_size * lanes <= max_work

def get_warmup_keys(
self, max_tokens: int, cfg: Any
) -> list[ToyKernel.CompileKey]:
return self._trace_dispatch(self.dispatch)(
tokens=WarmupIntRange(1, max_tokens + 1),
lanes=(1, 2),
cfg=cfg,
max_work=4,
_when=self._is_valid_warmup_dispatch,
)

assert PredicateKernel().get_warmup_keys(5, _config()) == [
ToyKernel.CompileKey(1, 1, 1, ("base", "default", -1, 1, 1), True),
ToyKernel.CompileKey(1, 2, 1, ("base", "default", -1, 1, 1), True),
ToyKernel.CompileKey(2, 2, 1, ("base", "default", -2, 2, 4), True),
ToyKernel.CompileKey(2, 4, 1, ("base", "default", -2, 2, 4), True),
ToyKernel.CompileKey(4, 4, 1, ("base", "default", -4, 1, 16), True),
]


def test_zip_inputs_validates_input_rows() -> None:
with pytest.raises(ValueError, match="requires at least one"):
zip_inputs()
Expand Down
58 changes: 53 additions & 5 deletions tests/models/inkling/test_fa4_warmup.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,51 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project

from types import SimpleNamespace

import torch

from vllm.models.inkling.configs import InklingMMConfig, InklingModelConfig
from vllm.models.inkling.nvidia.ops import fa4_warmup
from vllm.models.inkling.nvidia.ops.fa4_rel_attention import (
bucket_max_seqlen_q,
inkling_fa4_num_splits,
)
from vllm.models.inkling.nvidia.ops.fa4_warmup import (
InklingFA4WarmupConfig,
_iter_compile_units,
InklingFA4RelAttentionKernel,
_num_warps_bucket,
)


def _vllm_config_from_reference_config(config: SimpleNamespace) -> SimpleNamespace:
return SimpleNamespace(
model_config=SimpleNamespace(
hf_config=InklingMMConfig(
text_config=InklingModelConfig(
num_attention_heads=config.num_heads,
num_key_value_heads=config.num_kv_heads,
head_dim=config.head_dim,
rel_extent=config.rel_extent,
swa_num_attention_heads=config.num_heads,
swa_num_key_value_heads=config.num_kv_heads,
swa_head_dim=config.head_dim,
sliding_window_size=config.rel_extent,
)
),
max_model_len=config.max_kv_len,
dtype=config.dtype,
),
cache_config=SimpleNamespace(
cache_dtype="auto",
block_size=config.block_size,
),
scheduler_config=SimpleNamespace(
max_num_seqs=config.max_num_reqs,
max_num_batched_tokens=config.max_num_batched_tokens,
),
)


def test_bucket_max_seqlen_q():
assert [bucket_max_seqlen_q(n) for n in range(1, 10)] == [
1,
Expand All @@ -28,8 +60,13 @@ def test_bucket_max_seqlen_q():
]


def test_warmup_enumerates_every_runtime_compile_class():
config = InklingFA4WarmupConfig(
def test_warmup_enumerates_every_runtime_compile_class(monkeypatch):
monkeypatch.setattr(
fa4_warmup,
"get_tensor_model_parallel_world_size",
lambda: 1,
)
config = SimpleNamespace(
num_heads=16,
num_kv_heads=2,
head_dim=128,
Expand All @@ -43,7 +80,18 @@ def test_warmup_enumerates_every_runtime_compile_class():
max_num_reqs=64,
max_num_batched_tokens=192,
)
warmed_keys = {unit.key[-1] for unit in _iter_compile_units(config)}
vllm_config = _vllm_config_from_reference_config(config)
kernel = InklingFA4RelAttentionKernel()
warmed_keys = {
(
key.max_seqlen_q,
key.num_splits,
key.num_warps_bucket,
key.large_num_reqs,
)
for key in kernel.get_warmup_keys(vllm_config)
if key.is_local == config.is_local
}

for query_len in range(1, config.max_num_batched_tokens + 1):
max_seqlen_q = bucket_max_seqlen_q(query_len)
Expand Down
8 changes: 0 additions & 8 deletions vllm/config/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,6 @@ class KernelConfig:
enable_flashinfer_autotune: bool = None # type: ignore[assignment]
"""If True, run FlashInfer autotuning during kernel warmup."""

# TODO(roberto): Remove after registered CuTeDSL warmups are migrated
# to the shared JIT warmup infrastructure.
# https://github.com/vllm-project/vllm/pull/47451
enable_cutedsl_warmup: bool = True
"""If True, run CuTeDSL compile warmup during kernel warmup."""

enable_jit_warmup: bool = True
"""If True, run JIT compile warmup during kernel warmup."""

Expand Down Expand Up @@ -255,7 +249,6 @@ def compute_hash(self) -> str:
Any future fields that don't affect compilation should be excluded.
"""
ignored_factors = {
"enable_cutedsl_warmup",
"enable_jit_warmup",
"enable_flashinfer_autotune",
"ir_op_priority", # handled separately below
Expand All @@ -266,7 +259,6 @@ def compute_hash(self) -> str:

@field_validator(
"enable_flashinfer_autotune",
"enable_cutedsl_warmup",
"enable_jit_warmup",
mode="wrap",
)
Expand Down
121 changes: 0 additions & 121 deletions vllm/model_executor/warmup/cutedsl_warmup.py

This file was deleted.

23 changes: 21 additions & 2 deletions vllm/model_executor/warmup/fa4_cutedsl_warmup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
"""Warm up FA4 CuTeDSL MLA prefill compile keys."""
"""Warm up FA4 CuTeDSL kernels."""

from __future__ import annotations

Expand All @@ -12,7 +12,7 @@
from vllm.v1.worker.gpu_worker import Worker


def fa4_cutedsl_warmup(worker: Worker) -> None:
def _warm_fa4_mla_prefill(worker: Worker) -> None:
runner = worker.model_runner
if runner.is_pooling_model:
return
Expand All @@ -28,3 +28,22 @@ def fa4_cutedsl_warmup(worker: Worker) -> None:
from vllm.v1.attention.backends.mla.prefill import flash_attn

flash_attn.FA4_MLA_PREFILL_KERNEL.warmup(vllm_config)


def _warm_inkling_fa4_rel_attention(worker: Worker) -> None:
from vllm.models.inkling.configs import InklingMMConfig, InklingModelConfig
from vllm.models.inkling.nvidia.ops.fa4_warmup import (
INKLING_FA4_REL_ATTENTION_KERNEL,
)

vllm_config = worker.vllm_config
hf_config = vllm_config.model_config.hf_config
if not isinstance(hf_config, (InklingMMConfig, InklingModelConfig)):
return

INKLING_FA4_REL_ATTENTION_KERNEL.warmup(vllm_config)


def fa4_cutedsl_warmup(worker: Worker) -> None:
_warm_fa4_mla_prefill(worker)
_warm_inkling_fa4_rel_attention(worker)
Loading
Loading