Merge remote-tracking branch 'upstream/main' into patches

Signed-off-by: MOVZX <movzx@yahoo.com>
This commit is contained in:
2026-10-03 21:59:03 +07:00
1012 changed files with 61873 additions and 14499 deletions
+21 -9
View File
@@ -410,17 +410,24 @@ def flashinfer_autotune(runner: "GPUModelRunner") -> None:
Without autotuning, FlashInfer will rely on heuristics, which may
be significantly slower.
Every rank profiles the same tactics. When distributed, per-tactic
timings are averaged over the world CPU group so all ranks select the
same tactic.
With PP > 1, stages run different layers and may profile different ops,
so each stage's TP group tunes separately with its own cache file;
otherwise the world group tunes together. Per-tactic timings are
averaged over the tuning group so all its ranks select the same tactic.
"""
from flashinfer.autotuner import AutoTuner, set_autotune_process_group
import vllm.utils.flashinfer as fi_utils
from vllm.distributed.parallel_state import get_world_group
from vllm.distributed.parallel_state import (
get_pp_group,
get_tp_group,
get_world_group,
)
world = get_world_group()
is_leader = world.rank_in_group == 0
pp_size = get_pp_group().world_size
tune_group = get_tp_group() if pp_size > 1 else world
is_leader = tune_group.rank_in_group == 0
tuner = AutoTuner.get()
autotune_kwargs: dict = {}
@@ -433,6 +440,11 @@ def flashinfer_autotune(runner: "GPUModelRunner") -> None:
autotune_kwargs["skip_ops"] = skip_ops
cache_path = resolve_flashinfer_autotune_file(runner)
if pp_size > 1:
ranks = "-".join(str(rank) for rank in tune_group.ranks)
cache_path = cache_path.with_name(
f"{cache_path.stem}_tp_{ranks}{cache_path.suffix}"
)
if is_leader:
logger.info_once("Using FlashInfer autotune cache file: %s", cache_path)
@@ -441,18 +453,18 @@ def flashinfer_autotune(runner: "GPUModelRunner") -> None:
# which lead to some EP ranks receiving no tokens and skipping their
# MoE kernel entirely, and cause hang due to all-reduce collective
# during synchronized autotuning.
# Read cached autotune results and broadcast to all ranks.
# Read cached autotune results and broadcast within the tuning group.
cached_results: bytes | None = None
if is_leader and cache_path.exists():
with open(cache_path, "rb") as f:
cached_results = f.read()
cached_results = world.broadcast_object(cached_results, src=0)
cached_results = tune_group.broadcast_object(cached_results, src=0)
if cached_results is not None:
write_flashinfer_autotune_cache(cache_path, cached_results)
world.barrier()
tune_group.barrier()
tuner.load_configs(str(cache_path))
group = world.cpu_group if world.world_size > 1 else None
group = tune_group.cpu_group if tune_group.world_size > 1 else None
set_autotune_process_group(group)
try:
with (
@@ -4,6 +4,7 @@
from __future__ import annotations
import sys
from typing import TYPE_CHECKING
import torch
@@ -19,7 +20,10 @@ logger = init_logger(__name__)
def _get_kda_layer(worker: Worker) -> KimiK3DeltaAttention | None:
from vllm.models.kimi_k3.nvidia.kda import KimiK3DeltaAttention
# Kimi model construction already imports kda. Avoid importing it here.
kda = sys.modules.get("vllm.models.kimi_k3.nvidia.kda")
if kda is None:
return None
compilation_config = getattr(
worker.model_runner,
@@ -33,7 +37,7 @@ def _get_kda_layer(worker: Worker) -> KimiK3DeltaAttention | None:
(
layer
for layer in static_context.values()
if isinstance(layer, KimiK3DeltaAttention)
if isinstance(layer, kda.KimiK3DeltaAttention)
),
None,
)
+30 -7
View File
@@ -21,6 +21,7 @@ logger = init_logger(__name__)
def _replayssm_autotune_kwargs(
runner: "GPUModelRunner",
max_token_prefill_kwargs: dict[str, Any],
) -> tuple[int, dict[str, Any]] | None:
config = runner.vllm_config
if not (
@@ -46,11 +47,16 @@ def _replayssm_autotune_kwargs(
runner.max_num_tokens // query_len,
runner.kv_cache_config.num_blocks - 1,
)
if max_num_reqs <= 0:
logger.warning_once(
"Skipping FlashInfer ReplaySSM autotuning because no non-padding "
"state slot is available."
)
return None
decode_kwargs = {
**max_token_prefill_kwargs,
"num_tokens": max_num_reqs * query_len,
"skip_eplb": True,
"is_profile": True,
"randomize_inputs": True,
"uniform_decode": True,
}
if config.use_v2_model_runner:
@@ -75,18 +81,22 @@ def _temporary_replayssm_autotune_state(
)
reset_tensors: dict[int, torch.Tensor] = {}
tracker_specs: dict[int, tuple[torch.Tensor, torch.Tensor, int, int]] = {}
tracker_specs: dict[
int, tuple[torch.Tensor, torch.Tensor, torch.Tensor, int, int]
] = {}
for module in runner.get_model().modules():
if not isinstance(module, MambaMixer2) or not module.use_replayssm:
continue
assert module.replayssm_buffer_len is not None
ring_start = module._replayssm_ring_start
prev_num_accepted = module._replayssm_prev_num_accepted
prev_query_len = module._replayssm_prev_query_len
tracker_specs.setdefault(
ring_start.data_ptr(),
(
ring_start,
prev_num_accepted,
prev_query_len,
module.replayssm_buffer_len,
module.kv_cache[2].size(2),
),
@@ -95,6 +105,7 @@ def _temporary_replayssm_autotune_state(
*module.kv_cache,
ring_start,
prev_num_accepted,
prev_query_len,
)
for tensor in tensors:
if tensor.numel():
@@ -121,20 +132,26 @@ def _temporary_replayssm_autotune_state(
for (
ring_start,
prev_num_accepted,
prev_query_len,
logical_window,
ring_buffer_len,
) in tracker_specs.values():
# Compile reset (prefill) and advance (decode) before inference.
# The final reset leaves the decode tuning run in a clean state.
reset_replayssm_ring_trackers(ring_start, prev_num_accepted, state_slots)
reset_replayssm_ring_trackers(
ring_start, prev_num_accepted, prev_query_len, state_slots
)
update_replayssm_ring_trackers(
ring_start,
prev_num_accepted,
prev_query_len,
state_slots,
logical_window,
ring_buffer_len,
)
reset_replayssm_ring_trackers(ring_start, prev_num_accepted, state_slots)
reset_replayssm_ring_trackers(
ring_start, prev_num_accepted, prev_query_len, state_slots
)
try:
yield
@@ -151,7 +168,13 @@ def _temporary_replayssm_autotune_state(
def replayssm_autotune_warmup(runner: "GPUModelRunner") -> None:
autotune = _replayssm_autotune_kwargs(runner)
max_token_prefill_kwargs = {
"num_tokens": runner.scheduler_config.max_num_batched_tokens,
"skip_eplb": True,
"is_profile": True,
"randomize_inputs": True,
}
autotune = _replayssm_autotune_kwargs(runner, max_token_prefill_kwargs)
if autotune is None:
return
max_num_reqs, decode_kwargs = autotune