[MRV2][SD] Make Dynamic SD comatible with Full Cuda Graphs (#45953)

Signed-off-by: Ekagra Ranjan <3116519+ekagra-ranjan@users.noreply.github.com>
Co-authored-by: Benjamin Chislett <chislett.ben@gmail.com>
Co-authored-by: Nick Hill <nickhill123@gmail.com>
This commit is contained in:
Ekagra Ranjan
2026-07-03 23:58:27 -04:00
committed by GitHub
co-authored by Benjamin Chislett Nick Hill
parent 67ff0ae30f
commit 07516fda67
8 changed files with 436 additions and 36 deletions
+6 -2
View File
@@ -1321,6 +1321,7 @@ class CompilationConfig:
min_cg_support: "AttentionCGSupport",
min_cg_attn_backend: str | None,
uniform_decode_query_len: int = 1,
use_v2_model_runner: bool = False,
tensor_parallel_size: int = 1,
kv_cache_config: "KVCacheConfig | None" = None,
max_num_reqs: int | None = None,
@@ -1421,13 +1422,16 @@ class CompilationConfig:
"and make sure compilation mode is VLLM_COMPILE"
)
# Adjust cudagraph sizes to be a multiple of uniform_decode_query_len
# MRV1 adjusts cudagraph sizes to be a multiple of uniform_decode_query_len
# to avoid: https://github.com/vllm-project/vllm/issues/28207 and temp-fix:
# https://github.com/vllm-project/vllm/issues/28207#issuecomment-3504004536
# Will be removed in the near future when we have separate cudagraph capture
# sizes for decode and mixed prefill-decode.
# MRV2 handles cudagraph capture sizing in cudagraph_utils.py
# and doesn't need below: https://github.com/vllm-project/vllm/pull/45953
if (
cudagraph_mode.decode_mode() == CUDAGraphMode.FULL
not use_v2_model_runner
and cudagraph_mode.decode_mode() == CUDAGraphMode.FULL
and uniform_decode_query_len > 1
):
self.adjust_cudagraph_sizes_for_spec_decode(
+3 -4
View File
@@ -774,13 +774,15 @@ class VllmConfig:
speculative_config is None
or not speculative_config.uses_dynamic_speculative_decoding()
or not self.compilation_config.cudagraph_mode.has_full_cudagraphs()
or self.use_v2_model_runner
):
return
logger.warning_once(
"Dynamic speculative decoding changes the target verification "
"length at runtime. Overriding cudagraph_mode from %s to "
"PIECEWISE for reliability.",
"PIECEWISE for reliability. Use VLLM_USE_V2_MODEL_RUNNER=1 "
"if you want to use full CUDA graphs.",
self.compilation_config.cudagraph_mode.name,
)
self.compilation_config.cudagraph_mode = CUDAGraphMode.PIECEWISE
@@ -2062,9 +2064,6 @@ class VllmConfig:
):
unsupported.append(f"speculative method '{speculative_config.method}'")
if speculative_config.uses_dynamic_speculative_decoding():
unsupported.append("dynamic speculative decoding")
# V2 EagleSpeculator does not support parallel_drafting (for P-Eagle).
# DFlash and DSpark use parallel drafting natively in V2 via their
# own speculators.
+58 -19
View File
@@ -27,6 +27,7 @@ from vllm.logger import init_logger
from vllm.model_executor.offloader.base import get_offloader
from vllm.platforms import current_platform
from vllm.sequence import IntermediateTensors
from vllm.utils.math_utils import round_up
from vllm.v1.kv_cache_interface import KVCacheConfig
from vllm.v1.worker.gpu.attn_utils import build_slot_mappings_by_layer
from vllm.v1.worker.gpu.block_table import BlockTables
@@ -141,10 +142,7 @@ class CudaGraphManager:
self._candidates: dict[tuple[int, int], list[BatchExecutionDescriptor]] = {}
self._capture_descs: dict[CUDAGraphMode, list[BatchExecutionDescriptor]] = {}
# adjust the cudagraph sizes to be a multiple of the uniform decode query length
self.compilation_config.adjust_cudagraph_sizes_for_spec_decode(
self.decode_query_len, self.tp_size
)
self._init_candidates()
# Breakable CUDA graph (PW CUDA graph without torch.compile)
@@ -191,31 +189,72 @@ class CudaGraphManager:
decode_mode = self.cudagraph_mode.decode_mode()
mixed_mode = self.cudagraph_mode.mixed_mode()
separate_decode_routine = self.cudagraph_mode.separate_routine()
max_cg_capture_size = self.compilation_config.max_cudagraph_capture_size
descs_by_token_lora: dict[tuple[int, int], list[BatchExecutionDescriptor]] = (
defaultdict(list)
)
descs_by_mode = defaultdict(list)
descs_by_mode: defaultdict[CUDAGraphMode, list[BatchExecutionDescriptor]] = (
defaultdict(list)
)
# When using Dynamic SD, num_speculative_tokens is the max number of
# draft tokens. The scheduler might use a smaller number so we need
# to capture graphs for all possible values during decode.
speculative_config = self.vllm_config.speculative_config
if (
speculative_config
and speculative_config.uses_dynamic_speculative_decoding()
):
num_spec_per_batch_size = (
speculative_config.num_speculative_tokens_per_batch_size
)
# uses_dynamic_speculative_decoding() guarantees this is set.
assert num_spec_per_batch_size is not None
# decode_query_len = num_speculative_steps + num_new_sampled_tokens
# _per_step. Recover num_new_sampled_tokens_per_step
# from the values the manager already has.
num_new_sampled_tokens_per_step = (
self.decode_query_len - self.vllm_config.num_speculative_tokens
)
# Each entry is (range_start, range_end, num_speculative_tokens).
decode_query_lens = [
x[2] + num_new_sampled_tokens_per_step for x in num_spec_per_batch_size
]
else:
decode_query_lens = [self.decode_query_len]
for num_tokens, num_active_loras in product(
capture_sizes, self.lora_capture_cases
):
# Capture uniform decode specfifc graphs if required
# (i.e. separate decode routine)
if (
separate_decode_routine
and decode_mode
and self.decode_query_len <= num_tokens <= max_decode_tokens
):
desc = BatchExecutionDescriptor(
cg_mode=decode_mode,
num_tokens=num_tokens,
num_reqs=num_tokens // self.decode_query_len,
uniform_token_count=self.decode_query_len,
num_active_loras=num_active_loras,
)
descs_by_mode[decode_mode].append(desc)
descs_by_token_lora[(num_tokens, num_active_loras)].append(desc)
if separate_decode_routine and decode_mode:
for decode_query_len in decode_query_lens:
rounded_num_tokens = round_up(num_tokens, decode_query_len)
rounded_num_reqs = rounded_num_tokens // decode_query_len
if (
rounded_num_tokens > max_decode_tokens
or rounded_num_tokens > max_cg_capture_size
or rounded_num_reqs > self.max_num_reqs
):
continue
desc = BatchExecutionDescriptor(
cg_mode=decode_mode,
num_tokens=rounded_num_tokens,
num_reqs=rounded_num_reqs,
uniform_token_count=decode_query_len,
num_active_loras=num_active_loras,
)
# avoid duplicate graphs
if desc not in descs_by_mode[decode_mode]:
descs_by_mode[decode_mode].append(desc)
descs_by_token_lora[
(rounded_num_tokens, num_active_loras)
].append(desc)
if mixed_mode:
# for PIECEWISE graphs there is no limit on requests when replaying
+4 -3
View File
@@ -454,9 +454,10 @@ class GPUModelRunner(LoRAModelRunnerMixin):
attn_cg_support.min_cg_support,
attn_cg_support.min_cg_attn_backend,
self.decode_query_len,
self.parallel_config.tensor_parallel_size,
self.kv_cache_config,
self.max_num_reqs,
use_v2_model_runner=True,
tensor_parallel_size=self.parallel_config.tensor_parallel_size,
kv_cache_config=self.kv_cache_config,
max_num_reqs=self.max_num_reqs,
)
self.cudagraph_manager = ModelCudaGraphManager(
self.vllm_config,
+4 -3
View File
@@ -6930,9 +6930,10 @@ class GPUModelRunner(
min_cg_support,
min_cg_attn_backend,
self.uniform_decode_query_len,
self.parallel_config.tensor_parallel_size,
self.kv_cache_config,
self.max_num_reqs,
use_v2_model_runner=False,
tensor_parallel_size=self.parallel_config.tensor_parallel_size,
kv_cache_config=self.kv_cache_config,
max_num_reqs=self.max_num_reqs,
is_profiling=is_profiling,
)
# Trigger cudagraph dispatching keys initialization after