Merge branch 'main' into patches
Signed-off-by: MOVZX <movzx@yahoo.com>
This commit is contained in:
@@ -262,7 +262,7 @@ class AsyncPoolingOutput(AsyncModelRunnerOutput):
|
||||
|
||||
|
||||
def async_copy_to_np(x: torch.Tensor) -> np.ndarray:
|
||||
return x.to("cpu", non_blocking=True).numpy()
|
||||
return x.to("cpu", non_blocking=True, copy=True).numpy()
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
|
||||
@@ -8,6 +8,7 @@ from typing import TYPE_CHECKING, Any, cast
|
||||
import numpy as np
|
||||
import torch
|
||||
|
||||
import vllm.envs as envs
|
||||
from vllm.config import (
|
||||
VllmConfig,
|
||||
get_layers_from_vllm_config,
|
||||
@@ -224,6 +225,14 @@ def init_attn_backend(
|
||||
|
||||
for layer_name in layer_names:
|
||||
attn_backend = attn_layers[layer_name].get_attn_backend()
|
||||
if (
|
||||
envs.VLLM_BATCH_INVARIANT
|
||||
and not attn_backend.supports_batch_invariance()
|
||||
):
|
||||
raise RuntimeError(
|
||||
"VLLM batch_invariant mode is not supported for "
|
||||
f"{attn_backend.get_name()}."
|
||||
)
|
||||
if layer_name in fast_prefill_eligible_layers:
|
||||
attn_backend = create_fast_prefill_custom_backend(
|
||||
"FastPrefill", attn_backend
|
||||
|
||||
@@ -54,8 +54,8 @@ class NonUvaBuffer:
|
||||
|
||||
def uva(self, n: int | None = None) -> torch.Tensor:
|
||||
if n is None:
|
||||
return self._uva.copy_(self.cpu)
|
||||
return self._uva[:n].copy_(self.cpu[:n])
|
||||
return self._uva.copy_(self.cpu, non_blocking=True)
|
||||
return self._uva[:n].copy_(self.cpu[:n], non_blocking=True)
|
||||
|
||||
|
||||
class UvaBufferPool:
|
||||
|
||||
@@ -272,6 +272,7 @@ class CudaGraphManager:
|
||||
if (
|
||||
speculative_config
|
||||
and speculative_config.uses_dynamic_speculative_decoding()
|
||||
and self.decode_query_len > self.vllm_config.num_speculative_tokens
|
||||
):
|
||||
# decode_query_len = num_speculative_steps + num_new_sampled_tokens
|
||||
# _per_step. Recover num_new_sampled_tokens_per_step
|
||||
|
||||
@@ -150,9 +150,12 @@ class EncoderRunner:
|
||||
def execute_mm_encoder(
|
||||
self, mm_kwargs: list[tuple[str, MultiModalKwargsItem]]
|
||||
) -> list[torch.Tensor]:
|
||||
# Stable-sort items by modality so each modality is encoded in as few
|
||||
# batches as possible. The returned outputs are restored to input order.
|
||||
order = sorted(range(len(mm_kwargs)), key=lambda i: mm_kwargs[i][0])
|
||||
encoder_outputs: list[torch.Tensor] = []
|
||||
for modality, num_items, mm_kwargs_batch in group_and_batch_mm_kwargs(
|
||||
mm_kwargs, device=self.device, pin_memory=PIN_MEMORY
|
||||
[mm_kwargs[i] for i in order], device=self.device, pin_memory=PIN_MEMORY
|
||||
):
|
||||
cg_manager = self.cudagraph_manager
|
||||
cudagraph_output = (
|
||||
@@ -169,7 +172,7 @@ class EncoderRunner:
|
||||
)
|
||||
sanity_check_mm_encoder_outputs(batch_outputs, expected_num_items=num_items)
|
||||
encoder_outputs.extend(batch_outputs)
|
||||
return encoder_outputs
|
||||
return [encoder_outputs[i] for i in np.argsort(order)]
|
||||
|
||||
@contextmanager
|
||||
def timed_encoder_operation(self, request_ids: Collection[str]):
|
||||
|
||||
@@ -6,6 +6,7 @@ import numpy as np
|
||||
|
||||
from vllm.lora.layers import LoRAMapping, LoRAMappingType
|
||||
from vllm.lora.worker_manager import WorkerLoRAManager
|
||||
from vllm.multimodal.inputs import MultiModalFeatureSpec
|
||||
from vllm.v1.worker.gpu.lora_utils import LoraState
|
||||
from vllm.v1.worker.gpu.mm.encoder_cache import EncoderCache
|
||||
|
||||
@@ -31,7 +32,7 @@ def set_active_mm_loras(
|
||||
encoder_token_counts: list[int] = []
|
||||
connector_token_counts: list[int] = []
|
||||
|
||||
# iterate through images
|
||||
mm_items: list[tuple[int, MultiModalFeatureSpec]] = []
|
||||
for req_id, encoder_input_ids in scheduled_encoder_inputs.items():
|
||||
req_idx = req_id_to_index.get(req_id)
|
||||
if req_idx is None:
|
||||
@@ -39,27 +40,29 @@ def set_active_mm_loras(
|
||||
|
||||
lora_id = int(lora_state.lora_ids[req_idx])
|
||||
mm_features = encoder_cache.mm_features[req_id]
|
||||
|
||||
# iterate through visual tokens
|
||||
for mm_input_id in encoder_input_ids:
|
||||
pos_info = mm_features[mm_input_id].mm_position
|
||||
|
||||
tower_tokens, connector_tokens = model.get_mm_lora_token_counts(
|
||||
modality=mm_features[mm_input_id].modality,
|
||||
mm_kwargs=mm_features[mm_input_id].data,
|
||||
num_mm_embeds=pos_info.get_num_embeds(),
|
||||
)
|
||||
|
||||
prompt_lora_mapping.append(lora_id)
|
||||
token_lora_mapping.extend([lora_id] * tower_tokens)
|
||||
encoder_token_counts.append(tower_tokens)
|
||||
connector_token_counts.append(connector_tokens)
|
||||
mm_items.extend((lora_id, mm_features[i]) for i in encoder_input_ids)
|
||||
|
||||
if lora_id > 0:
|
||||
lora_request = lora_state.lora_requests.get(req_id)
|
||||
if lora_request is not None:
|
||||
lora_requests.add(lora_request)
|
||||
|
||||
# Runs items sorted by modality.
|
||||
mm_items.sort(key=lambda x: x[1].modality)
|
||||
for lora_id, mm_feature in mm_items:
|
||||
pos_info = mm_feature.mm_position
|
||||
|
||||
tower_tokens, connector_tokens = model.get_mm_lora_token_counts(
|
||||
modality=mm_feature.modality,
|
||||
mm_kwargs=mm_feature.data,
|
||||
num_mm_embeds=pos_info.get_num_embeds(),
|
||||
)
|
||||
|
||||
prompt_lora_mapping.append(lora_id)
|
||||
token_lora_mapping.extend([lora_id] * tower_tokens)
|
||||
encoder_token_counts.append(tower_tokens)
|
||||
connector_token_counts.append(connector_tokens)
|
||||
|
||||
if not prompt_lora_mapping:
|
||||
return
|
||||
|
||||
|
||||
@@ -265,13 +265,32 @@ class GPUModelRunner(LoRAModelRunnerMixin):
|
||||
self.encoder_cache = EncoderCache()
|
||||
self.ec_connector = get_ec_connector(vllm_config, self.encoder_cache)
|
||||
|
||||
self.num_speculative_steps = vllm_config.num_speculative_tokens
|
||||
num_prefill_lookahead = max(1, vllm_config.num_prefill_lookahead_tokens)
|
||||
use_dense_all_token_ids = (
|
||||
self.speculative_config is not None and self.speculative_config.use_ngram()
|
||||
)
|
||||
|
||||
# General request states.
|
||||
self.req_states = RequestState(
|
||||
max_num_reqs=self.max_num_reqs,
|
||||
max_model_len=self.max_model_len,
|
||||
max_num_batched_tokens=self.max_num_tokens,
|
||||
num_speculative_steps=self.num_speculative_steps,
|
||||
vocab_size=self.vocab_size,
|
||||
device=self.device,
|
||||
num_prefill_lookahead=num_prefill_lookahead,
|
||||
use_dense_all_token_ids=use_dense_all_token_ids,
|
||||
)
|
||||
|
||||
# Speculative decoding.
|
||||
self.speculator = None
|
||||
self.use_aux_hidden_state_outputs = False
|
||||
self.num_speculative_steps = vllm_config.num_speculative_tokens
|
||||
if self.speculative_config is not None:
|
||||
if self.is_last_pp_rank:
|
||||
self.speculator = init_speculator(self.vllm_config, self.device)
|
||||
self.speculator = init_speculator(
|
||||
self.vllm_config, self.device, self.req_states
|
||||
)
|
||||
|
||||
if self.speculative_config.method in (
|
||||
"eagle3",
|
||||
@@ -291,20 +310,7 @@ class GPUModelRunner(LoRAModelRunnerMixin):
|
||||
self.is_pooling_model = self.model_config.runner_type == "pooling"
|
||||
self.pooling_runner: PoolingRunner | None = None
|
||||
|
||||
num_prefill_lookahead = max(1, vllm_config.num_prefill_lookahead_tokens)
|
||||
|
||||
self.step_timing = StepTimingCollector()
|
||||
|
||||
# General request states.
|
||||
self.req_states = RequestState(
|
||||
max_num_reqs=self.max_num_reqs,
|
||||
max_model_len=self.max_model_len,
|
||||
max_num_batched_tokens=self.max_num_tokens,
|
||||
num_speculative_steps=self.num_speculative_steps,
|
||||
vocab_size=self.vocab_size,
|
||||
device=self.device,
|
||||
num_prefill_lookahead=num_prefill_lookahead,
|
||||
)
|
||||
self.adaptive_verification: AdaptiveVerificationManager | None = None
|
||||
self.input_buffers = InputBuffers(
|
||||
max_num_reqs=self.max_num_reqs,
|
||||
@@ -482,7 +488,7 @@ class GPUModelRunner(LoRAModelRunnerMixin):
|
||||
custom = self.model_state.custom_sampler(self.sampler)
|
||||
|
||||
if custom:
|
||||
self.vllm_config._check_watermarking_unsupported(custom_sampler=True)
|
||||
self.vllm_config._check_supports_watermarking(custom_sampler=True)
|
||||
self.sampler, self.rejection_sampler = custom
|
||||
elif self.speculative_config is not None:
|
||||
self.rejection_sampler = RejectionSampler(
|
||||
@@ -724,7 +730,6 @@ class GPUModelRunner(LoRAModelRunnerMixin):
|
||||
attn_cg_support.min_cg_attn_backend,
|
||||
self.decode_query_len,
|
||||
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,
|
||||
is_profiling=is_profiling,
|
||||
@@ -772,6 +777,7 @@ class GPUModelRunner(LoRAModelRunnerMixin):
|
||||
self.kv_caches = [
|
||||
cache for cache in kv_caches_dict.values() if cache.device == self.device
|
||||
]
|
||||
self.model_state.initialize_kv_cache(self.kv_cache_config, self.block_tables)
|
||||
if is_profiling:
|
||||
self.kv_connector = NO_OP_KV_CONNECTOR
|
||||
else:
|
||||
@@ -813,7 +819,7 @@ class GPUModelRunner(LoRAModelRunnerMixin):
|
||||
"skip_attn must only be True for initial memory profiling."
|
||||
)
|
||||
|
||||
# Create a dummy scheduler output. Plain draft-model speculation adds
|
||||
# Create a dummy scheduler output. Standalone AR speculation adds
|
||||
# one correction slot per request during prefill. The scheduler
|
||||
# accounts for these slots, while dummy runs bypass the scheduler.
|
||||
# Adjust the dummy token count only when the expanded draft batch
|
||||
@@ -909,14 +915,7 @@ class GPUModelRunner(LoRAModelRunnerMixin):
|
||||
)
|
||||
mm_inputs = [], all_false
|
||||
|
||||
# Let the target override the hidden state fed to the drafter
|
||||
# (e.g. DeepSeek V4 MTP needs the pre-hc_head residual). The
|
||||
# target returns a persistent buffer sized at max_num_batched_tokens;
|
||||
# slice to the active token count that propose() expects.
|
||||
spec_hidden_states = hidden_states
|
||||
if hasattr(self.model, "get_mtp_target_hidden_states"):
|
||||
pre_hc_hidden_states = self.model.get_mtp_target_hidden_states()
|
||||
spec_hidden_states = pre_hc_hidden_states[: hidden_states.shape[0]] # type: ignore[union-attr]
|
||||
spec_hidden_states = self._get_drafter_hidden_states(hidden_states)
|
||||
if isinstance(self.sampler, GPUWatermarkSampler):
|
||||
self.speculator.prepare_watermarking(
|
||||
self.sampler, input_batch.idx_mapping
|
||||
@@ -1077,6 +1076,12 @@ class GPUModelRunner(LoRAModelRunnerMixin):
|
||||
self.lora_config, self
|
||||
),
|
||||
)
|
||||
self.model_state.capture_inner_cudagraphs(
|
||||
input_buffers,
|
||||
self.block_tables,
|
||||
self.attn_groups,
|
||||
self.kv_cache_config,
|
||||
)
|
||||
if self.speculator is not None:
|
||||
with use_workspace_lane(self._draft_workspace_lane):
|
||||
self.speculator.capture()
|
||||
@@ -2057,6 +2062,7 @@ class GPUModelRunner(LoRAModelRunnerMixin):
|
||||
finished_req_ids=finished_req_ids,
|
||||
ec_connector_output=ec_connector_output,
|
||||
cudagraph_stats=cudagraph_stats,
|
||||
num_spec_tokens_to_schedule=scheduler_output.num_spec_tokens_to_schedule,
|
||||
)
|
||||
|
||||
if not self.is_last_pp_rank:
|
||||
@@ -2068,6 +2074,24 @@ class GPUModelRunner(LoRAModelRunnerMixin):
|
||||
)
|
||||
return None
|
||||
|
||||
def _get_drafter_hidden_states(self, hidden_states: torch.Tensor) -> torch.Tensor:
|
||||
"""Hidden states fed to the drafter.
|
||||
|
||||
Targets such as DeepSeek V4 expose the pre-hc_head residual through
|
||||
get_mtp_target_hidden_states(). The buffer is sized at
|
||||
max_num_batched_tokens and only allocated for drafters that consume
|
||||
target hidden states, so None means "use the regular hidden states".
|
||||
"""
|
||||
get_target_hidden_states = getattr(
|
||||
self.model, "get_mtp_target_hidden_states", None
|
||||
)
|
||||
if get_target_hidden_states is None:
|
||||
return hidden_states
|
||||
target_hidden_states = get_target_hidden_states()
|
||||
if target_hidden_states is None:
|
||||
return hidden_states
|
||||
return target_hidden_states[: hidden_states.shape[0]]
|
||||
|
||||
@torch.inference_mode()
|
||||
@step_eplb_after()
|
||||
def sample_tokens(
|
||||
@@ -2086,6 +2110,7 @@ class GPUModelRunner(LoRAModelRunnerMixin):
|
||||
finished_req_ids = self.execute_model_state.finished_req_ids
|
||||
ec_connector_output = self.execute_model_state.ec_connector_output
|
||||
cudagraph_stats = self.execute_model_state.cudagraph_stats
|
||||
num_spec_tokens = self.execute_model_state.num_spec_tokens_to_schedule
|
||||
self.execute_model_state = None
|
||||
|
||||
if not self.is_last_pp_rank:
|
||||
@@ -2212,14 +2237,7 @@ class GPUModelRunner(LoRAModelRunnerMixin):
|
||||
self.speculator.observe_verification(
|
||||
input_batch.idx_mapping, num_sampled, num_rejected
|
||||
)
|
||||
# Let the target override the hidden state fed to the drafter
|
||||
# (e.g. DeepSeek V4 MTP needs the pre-hc_head residual). The
|
||||
# target returns a persistent buffer sized at max_num_batched_tokens;
|
||||
# slice to the active token count that propose() expects.
|
||||
spec_hidden_states = draft_hidden_states
|
||||
if hasattr(self.model, "get_mtp_target_hidden_states"):
|
||||
pre_hc_hidden_states = self.model.get_mtp_target_hidden_states()
|
||||
spec_hidden_states = pre_hc_hidden_states[: draft_hidden_states.size(0)]
|
||||
spec_hidden_states = self._get_drafter_hidden_states(draft_hidden_states)
|
||||
if isinstance(self.sampler, GPUWatermarkSampler):
|
||||
self.speculator.prepare_watermarking(
|
||||
self.sampler, input_batch.idx_mapping
|
||||
@@ -2237,9 +2255,12 @@ class GPUModelRunner(LoRAModelRunnerMixin):
|
||||
self.req_states.next_prefill_tokens,
|
||||
self.sampler.sampling_states.temperature.gpu,
|
||||
self.sampler.sampling_states.seeds.gpu,
|
||||
num_speculative_tokens=num_spec_tokens,
|
||||
dp_sync=dp_sync,
|
||||
mm_inputs=mm_inputs,
|
||||
)
|
||||
if num_spec_tokens < self.num_speculative_steps:
|
||||
draft_tokens[:, num_spec_tokens:] = -1
|
||||
self.req_states.draft_tokens[input_batch.idx_mapping] = draft_tokens
|
||||
if self.adaptive_verification is not None:
|
||||
self.adaptive_verification.record_confidences(
|
||||
@@ -2251,7 +2272,7 @@ class GPUModelRunner(LoRAModelRunnerMixin):
|
||||
# not have a speculator (i.e. self.speculator is None)
|
||||
self.draft_tokens_handler.set_draft_tokens(
|
||||
input_batch,
|
||||
self.req_states.draft_tokens[input_batch.idx_mapping],
|
||||
self.req_states.draft_tokens[input_batch.idx_mapping, :num_spec_tokens],
|
||||
)
|
||||
if self.pp_handler is not None:
|
||||
self.pp_handler.broadcast_drafts(
|
||||
@@ -2396,6 +2417,7 @@ class ExecuteModelState(NamedTuple):
|
||||
finished_req_ids: set[str]
|
||||
ec_connector_output: ECConnectorOutput | None
|
||||
cudagraph_stats: CUDAGraphStat | None
|
||||
num_spec_tokens_to_schedule: int
|
||||
|
||||
|
||||
class BatchReqState(NamedTuple):
|
||||
|
||||
@@ -17,7 +17,8 @@ from vllm.v1.attention.backend import AttentionCGSupport
|
||||
from vllm.v1.core.sched.output import NewRequestData
|
||||
from vllm.v1.kv_cache_interface import KVCacheConfig
|
||||
from vllm.v1.worker.encoder_cudagraph import EncoderCudaGraphManager
|
||||
from vllm.v1.worker.gpu.input_batch import InputBatch
|
||||
from vllm.v1.worker.gpu.block_table import BlockTables
|
||||
from vllm.v1.worker.gpu.input_batch import InputBatch, InputBuffers
|
||||
from vllm.v1.worker.gpu.mm.encoder_cache import EncoderCache
|
||||
from vllm.v1.worker.gpu.mm.encoder_runner import EncoderRunner
|
||||
from vllm.v1.worker.gpu.states import RequestState
|
||||
@@ -126,6 +127,22 @@ class ModelState(ABC):
|
||||
def apply_staged_writes(self) -> None:
|
||||
return None
|
||||
|
||||
def initialize_kv_cache(
|
||||
self, kv_cache_config: KVCacheConfig, block_tables: BlockTables
|
||||
) -> None:
|
||||
"""Hook run after the KV cache tensors are allocated and bound."""
|
||||
return None
|
||||
|
||||
def capture_inner_cudagraphs(
|
||||
self,
|
||||
input_buffers: InputBuffers,
|
||||
block_tables: BlockTables,
|
||||
attn_groups: list[list[AttentionGroup]],
|
||||
kv_cache_config: KVCacheConfig,
|
||||
) -> None:
|
||||
"""Capture the CUDA graphs this state runs inside the model's forward."""
|
||||
return None
|
||||
|
||||
def get_additional_cg_support(self) -> tuple[AttentionCGSupport, str | None]:
|
||||
"""Cudagraph support of attention groups this ModelState builds outside
|
||||
``init_attn_backend`` (e.g. encoder-only layers).
|
||||
|
||||
@@ -21,6 +21,7 @@ from vllm.v1.core.sched.output import NewRequestData
|
||||
from vllm.v1.kv_cache_interface import KVCacheConfig, MambaSpec
|
||||
from vllm.v1.utils import CpuGpuBuffer
|
||||
from vllm.v1.worker.gpu.attn_utils import build_attn_metadata
|
||||
from vllm.v1.worker.gpu.block_table import BlockTables
|
||||
from vllm.v1.worker.gpu.input_batch import InputBatch
|
||||
from vllm.v1.worker.gpu.mm.encoder_cache import EncoderCache
|
||||
from vllm.v1.worker.gpu.model_states.default import DefaultModelState
|
||||
@@ -114,8 +115,13 @@ class MambaHybridModelState(DefaultModelState):
|
||||
self.num_accepted_tokens_gpu[req_index].fill_(1)
|
||||
if self._align_mode:
|
||||
# Seed the running state block from the resumed/prefilled position.
|
||||
# The column is in mamba blocks. cache_config.block_size is the
|
||||
# min over prefix-cacheable groups, so a drafter group with its own
|
||||
# smaller block (e.g. DFlash) pulls it below mamba_block_size.
|
||||
mamba_block_size = self.cache_config.mamba_block_size
|
||||
assert mamba_block_size is not None
|
||||
self._mamba_state_idx_gpu[req_index].fill_(
|
||||
(new_req_data.num_computed_tokens - 1) // self.cache_config.block_size
|
||||
(new_req_data.num_computed_tokens - 1) // mamba_block_size
|
||||
)
|
||||
|
||||
def _get_mamba_group_info(
|
||||
@@ -134,47 +140,42 @@ class MambaHybridModelState(DefaultModelState):
|
||||
self._mamba_spec = mamba_spec
|
||||
return self._mamba_group_ids, self._mamba_spec
|
||||
|
||||
def _ensure_align_ctx(
|
||||
self,
|
||||
kv_cache_config: KVCacheConfig,
|
||||
mamba_group_ids: list[int],
|
||||
block_tables: tuple[torch.Tensor, ...],
|
||||
) -> MambaSpecDecodeGPUContext:
|
||||
def initialize_kv_cache(
|
||||
self, kv_cache_config: KVCacheConfig, block_tables: BlockTables
|
||||
) -> None:
|
||||
if not self._align_mode:
|
||||
return
|
||||
mamba_group_ids, _ = self._get_mamba_group_info(kv_cache_config)
|
||||
if self._mamba_state_copy_funcs is None:
|
||||
mamba_groups = get_mamba_groups(kv_cache_config)
|
||||
mamba_types = {spec.mamba_type for spec in mamba_groups}
|
||||
copy_funcs = self.model.get_mamba_state_copy_funcs(mamba_types)
|
||||
validate_mamba_state_copy_funcs(mamba_groups, copy_funcs)
|
||||
self._mamba_state_copy_funcs = copy_funcs
|
||||
copy_funcs = self._mamba_state_copy_funcs
|
||||
if self._mamba_ctx is None:
|
||||
# Both SD and DS conv layouts support a >0 spec-decode shift: the
|
||||
# fused pre-copy kernel (``_copy_mamba_state_block``) applies the
|
||||
# ``token_bias = num_accepted - 1`` window shift per conv layout
|
||||
# (SD: contiguous slice; DS: per-dim-row strided slice), matching
|
||||
# the V1 ``get_conv_copy_spec`` semantics.
|
||||
self._mamba_ctx = MambaSpecDecodeGPUContext.create(
|
||||
max_num_reqs=self.max_num_reqs,
|
||||
kv_cache_config=kv_cache_config,
|
||||
copy_funcs=copy_funcs,
|
||||
device=self.device,
|
||||
make_buffer=lambda n, dtype: CpuGpuBuffer(
|
||||
n, dtype=dtype, device=self.device
|
||||
),
|
||||
)
|
||||
ctx = self._mamba_ctx
|
||||
if not ctx.is_initialized:
|
||||
forward_context = self.vllm_config.compilation_config.static_forward_context
|
||||
# block_tables are batch-order slices of the persistent
|
||||
# input_block_tables (stable data_ptr), so the metadata is captured
|
||||
# once here and reused across steps.
|
||||
ctx.initialize_from_forward_context(
|
||||
kv_cache_config,
|
||||
forward_context,
|
||||
copy_funcs,
|
||||
[block_tables[gid] for gid in mamba_group_ids],
|
||||
)
|
||||
return ctx
|
||||
# Both SD and DS conv layouts support a >0 spec-decode shift: the
|
||||
# fused pre-copy kernel (``_copy_mamba_state_block``) applies the
|
||||
# ``token_bias = num_accepted - 1`` window shift per conv layout
|
||||
# (SD: contiguous slice; DS: per-dim-row strided slice), matching
|
||||
# the V1 ``get_conv_copy_spec`` semantics.
|
||||
self._mamba_ctx = MambaSpecDecodeGPUContext.create(
|
||||
max_num_reqs=self.max_num_reqs,
|
||||
kv_cache_config=kv_cache_config,
|
||||
copy_funcs=self._mamba_state_copy_funcs,
|
||||
device=self.device,
|
||||
make_buffer=lambda n, dtype: CpuGpuBuffer(
|
||||
n, dtype=dtype, device=self.device
|
||||
),
|
||||
)
|
||||
# Under PP a step's postprocess runs after later steps re-gathered the
|
||||
# batch-ordered input tables, so state copies read the per-request-slot
|
||||
# tables. Aligned state indices are for the current batch only.
|
||||
self._mamba_ctx.initialize_from_forward_context(
|
||||
kv_cache_config,
|
||||
self.vllm_config.compilation_config.static_forward_context,
|
||||
self._mamba_state_copy_funcs,
|
||||
[block_tables.block_tables[gid].gpu for gid in mamba_group_ids],
|
||||
[block_tables.input_block_tables[gid] for gid in mamba_group_ids],
|
||||
)
|
||||
|
||||
def preprocess_state(
|
||||
self,
|
||||
@@ -194,8 +195,9 @@ class MambaHybridModelState(DefaultModelState):
|
||||
num_reqs = input_batch.num_reqs
|
||||
if num_reqs == 0:
|
||||
return
|
||||
mamba_group_ids, mamba_spec = self._get_mamba_group_info(kv_cache_config)
|
||||
ctx = self._ensure_align_ctx(kv_cache_config, mamba_group_ids, block_tables)
|
||||
_, mamba_spec = self._get_mamba_group_info(kv_cache_config)
|
||||
ctx = self._mamba_ctx
|
||||
assert ctx is not None
|
||||
|
||||
# The state-advance + pre-copy kernels run every step; they fast-exit per
|
||||
# request when src_col < 0 or src_col == dst_col, so no copy happens on
|
||||
@@ -277,18 +279,19 @@ class MambaHybridModelState(DefaultModelState):
|
||||
]
|
||||
|
||||
# GDN uses >= 0 to select spec-decode rows, so non-decode rows
|
||||
# need the -1 sentinel rather than a raw zero draft count.
|
||||
# need the -1 sentinel. Decode rows without drafts stay spec rows:
|
||||
# only that path applies the previous step's accepted offset.
|
||||
num_decode_draft_tokens_np = np.full(num_reqs, -1, dtype=np.int32)
|
||||
num_draft_tokens_per_req = input_batch.num_draft_tokens_per_req
|
||||
if num_draft_tokens_per_req is not None:
|
||||
# Test request state, not num_scheduled_tokens == draft_count+1:
|
||||
# adaptive rewrites num_scheduled_tokens to an even split, so that
|
||||
# equality rarely holds and would demote every verify row to decode.
|
||||
is_decode = ~is_prefilling_np & (input_batch.num_scheduled_tokens > 0)
|
||||
spec_decode_mask = (num_draft_tokens_per_req > 0) & is_decode
|
||||
num_decode_draft_tokens_np[: input_batch.num_reqs] = np.where(
|
||||
spec_decode_mask, num_draft_tokens_per_req, -1
|
||||
)
|
||||
if num_draft_tokens_per_req is None:
|
||||
num_draft_tokens_per_req = np.zeros(input_batch.num_reqs, np.int32)
|
||||
# Test request state, not num_scheduled_tokens == draft_count+1:
|
||||
# adaptive rewrites num_scheduled_tokens to an even split, so that
|
||||
# equality rarely holds and would demote every verify row to decode.
|
||||
is_decode = ~is_prefilling_np & (input_batch.num_scheduled_tokens > 0)
|
||||
num_decode_draft_tokens_np[: input_batch.num_reqs] = np.where(
|
||||
is_decode, num_draft_tokens_per_req, -1
|
||||
)
|
||||
num_decode_draft_tokens_cpu = torch.from_numpy(num_decode_draft_tokens_np)
|
||||
|
||||
if self._align_mode:
|
||||
@@ -300,10 +303,8 @@ class MambaHybridModelState(DefaultModelState):
|
||||
if hasattr(builder, "mamba_aligned_state_indices"):
|
||||
aligned_index_builders.append((group_idx, builder))
|
||||
if aligned_index_builders:
|
||||
ctx = self._ensure_align_ctx(
|
||||
kv_cache_config, mamba_group_ids, block_tables
|
||||
)
|
||||
all_group_indices = ctx.compute_aligned_state_indices(
|
||||
assert self._mamba_ctx is not None
|
||||
all_group_indices = self._mamba_ctx.compute_aligned_state_indices(
|
||||
input_batch.seq_lens, num_reqs
|
||||
)
|
||||
for group_idx, builder in aligned_index_builders:
|
||||
|
||||
@@ -1,11 +1,21 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import torch
|
||||
|
||||
from vllm.config import VllmConfig
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from vllm.v1.worker.gpu.states import RequestState
|
||||
|
||||
def init_speculator(vllm_config: VllmConfig, device: torch.device):
|
||||
|
||||
def init_speculator(
|
||||
vllm_config: VllmConfig,
|
||||
device: torch.device,
|
||||
req_states: "RequestState",
|
||||
):
|
||||
"""Build the speculator for this config."""
|
||||
speculative_config = vllm_config.speculative_config
|
||||
assert speculative_config is not None
|
||||
if speculative_config.method == "extract_hidden_states":
|
||||
@@ -61,10 +71,16 @@ def init_speculator(vllm_config: VllmConfig, device: torch.device):
|
||||
|
||||
return EagleSpeculator(vllm_config, device)
|
||||
elif speculative_config.uses_draft_model():
|
||||
from vllm.v1.worker.gpu.spec_decode.draft_model.speculator import (
|
||||
PlainDraftModelSpeculator,
|
||||
from vllm.v1.worker.gpu.spec_decode.standalone_ar.speculator import (
|
||||
StandaloneARSpeculator,
|
||||
)
|
||||
|
||||
return PlainDraftModelSpeculator(vllm_config, device)
|
||||
return StandaloneARSpeculator(vllm_config, device)
|
||||
elif speculative_config.use_ngram():
|
||||
from vllm.v1.worker.gpu.spec_decode.ngram.speculator import (
|
||||
NgramGPUSpeculator,
|
||||
)
|
||||
|
||||
return NgramGPUSpeculator(vllm_config, device, req_states)
|
||||
else:
|
||||
raise NotImplementedError(f"{speculative_config.method} is not supported yet.")
|
||||
|
||||
@@ -360,6 +360,7 @@ class DFlashSpeculator(DraftModelSpeculator):
|
||||
skip_attn_for_dummy_run: bool = False,
|
||||
mm_inputs: tuple[list[torch.Tensor], torch.Tensor] | None = None,
|
||||
is_profile: bool = False,
|
||||
num_speculative_tokens: int | None = None,
|
||||
) -> torch.Tensor:
|
||||
num_reqs = input_batch.num_reqs
|
||||
num_target_tokens = input_batch.num_tokens
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
|
||||
import torch.nn as nn
|
||||
|
||||
from vllm.v1.worker.gpu.spec_decode.autoregressive.speculator import (
|
||||
AutoRegressiveSpeculator,
|
||||
)
|
||||
from vllm.v1.worker.gpu.spec_decode.eagle.utils import load_eagle_model
|
||||
from vllm.v1.worker.gpu.spec_decode.target_dependent_ar.speculator import (
|
||||
TargetDependentARSpeculator,
|
||||
)
|
||||
|
||||
|
||||
class EagleSpeculator(AutoRegressiveSpeculator):
|
||||
class EagleSpeculator(TargetDependentARSpeculator):
|
||||
def load_draft_model(
|
||||
self,
|
||||
target_model: nn.Module,
|
||||
|
||||
@@ -103,6 +103,7 @@ class ExtractHiddenStatesSpeculator(DraftModelSpeculator):
|
||||
skip_attn_for_dummy_run: bool = False,
|
||||
mm_inputs: tuple[list[torch.Tensor], torch.Tensor] | None = None,
|
||||
is_profile: bool = False,
|
||||
num_speculative_tokens: int | None = None,
|
||||
) -> torch.Tensor:
|
||||
del (
|
||||
last_hidden_states,
|
||||
|
||||
@@ -17,8 +17,8 @@ from vllm.distributed.parallel_state import get_pp_group
|
||||
from vllm.logger import init_logger
|
||||
from vllm.model_executor.model_loader import get_model
|
||||
from vllm.model_executor.model_loader.utils import get_draft_load_config
|
||||
from vllm.v1.worker.gpu.spec_decode.autoregressive.speculator import (
|
||||
AutoRegressiveSpeculator,
|
||||
from vllm.v1.worker.gpu.spec_decode.target_dependent_ar.speculator import (
|
||||
TargetDependentARSpeculator,
|
||||
)
|
||||
|
||||
logger = init_logger(__name__)
|
||||
@@ -45,7 +45,7 @@ def _copy_target_kv_scales(attn: nn.Module, target_attn: nn.Module) -> None:
|
||||
getattr(attn, scale_name).copy_(getattr(target_attn, scale_name))
|
||||
|
||||
|
||||
class Gemma4Speculator(AutoRegressiveSpeculator):
|
||||
class Gemma4Speculator(TargetDependentARSpeculator):
|
||||
@property
|
||||
def advance_draft_positions(self) -> bool:
|
||||
# Gemma4 MTP is Q-only and reads K/V from the target's existing cache.
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
|
||||
import torch.nn as nn
|
||||
|
||||
from vllm.v1.worker.gpu.spec_decode.autoregressive.speculator import (
|
||||
AutoRegressiveSpeculator,
|
||||
)
|
||||
from vllm.v1.worker.gpu.spec_decode.eagle.utils import load_eagle_model
|
||||
from vllm.v1.worker.gpu.spec_decode.target_dependent_ar.speculator import (
|
||||
TargetDependentARSpeculator,
|
||||
)
|
||||
|
||||
|
||||
class MTPSpeculator(AutoRegressiveSpeculator):
|
||||
class MTPSpeculator(TargetDependentARSpeculator):
|
||||
share_mtp_topk_indices: bool = False
|
||||
|
||||
def load_draft_model(
|
||||
|
||||
@@ -14,11 +14,11 @@ from vllm.v1.attention.backends.utils import PAD_SLOT_ID
|
||||
from vllm.v1.worker.gpu.attn_utils import build_slot_mappings_by_layer
|
||||
from vllm.v1.worker.gpu.dp_utils import DPSyncState, dispatch_cg_and_sync_dp
|
||||
from vllm.v1.worker.gpu.input_batch import InputBatch, InputBuffers
|
||||
from vllm.v1.worker.gpu.spec_decode.autoregressive.cudagraph_utils import (
|
||||
SpeculatorCudaGraphManager,
|
||||
)
|
||||
from vllm.v1.worker.gpu.spec_decode.eagle.utils import load_eagle_model
|
||||
from vllm.v1.worker.gpu.spec_decode.speculator import DraftModelSpeculator
|
||||
from vllm.v1.worker.gpu.spec_decode.target_dependent_ar.cudagraph_utils import (
|
||||
SpeculatorCudaGraphManager,
|
||||
)
|
||||
from vllm.v1.worker.utils import get_uniform_decode_token_count
|
||||
|
||||
logger = init_logger(__name__)
|
||||
@@ -155,6 +155,7 @@ class MultiModuleMTPSpeculator(DraftModelSpeculator):
|
||||
skip_attn_for_dummy_run: bool = False,
|
||||
mm_inputs: tuple[list[torch.Tensor], torch.Tensor] | None = None,
|
||||
is_profile: bool = False,
|
||||
num_speculative_tokens: int | None = None,
|
||||
) -> torch.Tensor:
|
||||
num_reqs = input_batch.num_reqs
|
||||
seq_lens_cpu_upper_bound = input_batch.seq_lens_cpu_upper_bound
|
||||
|
||||
@@ -0,0 +1,279 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
import torch
|
||||
|
||||
from vllm.config import VllmConfig
|
||||
from vllm.triton_utils import HAS_TRITON, tl, triton
|
||||
from vllm.v1.worker.gpu.input_batch import InputBatch
|
||||
from vllm.v1.worker.gpu.spec_decode.speculator import BaseSpeculator
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from vllm.config.compilation import CUDAGraphMode
|
||||
from vllm.v1.worker.gpu.dp_utils import DPSyncState
|
||||
from vllm.v1.worker.gpu.states import RequestState
|
||||
|
||||
|
||||
@triton.jit
|
||||
def _ngram_scan_kernel(
|
||||
token_ids_ptr, # *int32 [max_num_reqs, token_ids_stride]
|
||||
token_ids_stride,
|
||||
idx_mapping_ptr, # *int64 [B] batch_idx -> req_state_idx
|
||||
total_len_ptr, # *int32 [max_num_reqs]
|
||||
num_sampled_ptr, # *int32 [B]
|
||||
scratch_ptr, # *int64 [B, scratch_stride] (output)
|
||||
scratch_stride,
|
||||
L, # int64 scalar (= max_model_len)
|
||||
MIN_N: tl.constexpr,
|
||||
MAX_N: tl.constexpr,
|
||||
MAX_N_PO2: tl.constexpr,
|
||||
BLOCK_L: tl.constexpr,
|
||||
):
|
||||
b = tl.program_id(0).to(tl.int64)
|
||||
blk = tl.program_id(1).to(tl.int64)
|
||||
Lp1 = tl.cast(L, tl.int64) + 1
|
||||
|
||||
req_state_idx = tl.load(idx_mapping_ptr + b).to(tl.int64)
|
||||
seq_len = tl.load(total_len_ptr + req_state_idx).to(tl.int64)
|
||||
num_sampled = tl.load(num_sampled_ptr + b)
|
||||
eligible_row = (num_sampled > 0) & (seq_len >= MIN_N)
|
||||
|
||||
scratch_off = b * scratch_stride + blk
|
||||
|
||||
# Ineligible rows, and blocks fully past the last candidate match
|
||||
# position, write 0 and exit.
|
||||
if not (eligible_row & (blk * BLOCK_L <= seq_len - MIN_N - 1)):
|
||||
tl.store(scratch_ptr + scratch_off, tl.zeros((), tl.int64))
|
||||
return
|
||||
|
||||
row_off = req_state_idx * token_ids_stride
|
||||
|
||||
# Load the length-MAX_N suffix once into registers.
|
||||
suf_iota = tl.arange(0, MAX_N_PO2).to(tl.int64)
|
||||
suf_pos = seq_len - MAX_N + suf_iota
|
||||
suf_in_range = (suf_iota < MAX_N) & (suf_pos >= 0) & (suf_pos < seq_len)
|
||||
suffix = tl.load(
|
||||
token_ids_ptr + row_off + suf_pos,
|
||||
mask=suf_in_range,
|
||||
other=-1,
|
||||
).to(tl.int32)
|
||||
|
||||
pos_iota = tl.arange(0, BLOCK_L).to(tl.int64)
|
||||
pos = blk * BLOCK_L + pos_iota # ascending
|
||||
|
||||
best_score = tl.zeros([BLOCK_L], dtype=tl.int64)
|
||||
|
||||
for n_iter in tl.static_range(MIN_N, MAX_N + 1):
|
||||
max_pos_n = seq_len - n_iter - 1
|
||||
match = (pos >= 0) & (pos <= max_pos_n)
|
||||
for j in tl.static_range(0, n_iter):
|
||||
tok = tl.load(
|
||||
token_ids_ptr + row_off + (pos + j),
|
||||
mask=match,
|
||||
other=0,
|
||||
).to(tl.int32)
|
||||
suf_idx = (MAX_N - n_iter) + j
|
||||
suf_val = tl.sum(tl.where(suf_iota == suf_idx, suffix, 0))
|
||||
match = match & (tok == suf_val)
|
||||
|
||||
# Pack (n, pos) so a single max yields longest-n, rightmost-pos.
|
||||
cand = n_iter * Lp1 + pos + 1
|
||||
best_score = tl.where(match, cand, best_score)
|
||||
|
||||
block_best = tl.max(best_score, axis=0)
|
||||
tl.store(scratch_ptr + scratch_off, block_best)
|
||||
|
||||
|
||||
@triton.jit
|
||||
def _ngram_finalize_kernel(
|
||||
token_ids_ptr, # *int32 [max_num_reqs, token_ids_stride]
|
||||
token_ids_stride,
|
||||
idx_mapping_ptr, # *int64 [B]
|
||||
total_len_ptr, # *int32 [max_num_reqs]
|
||||
num_sampled_ptr, # *int32 [B]
|
||||
last_sampled_ptr, # *int64 [max_num_reqs]
|
||||
scratch_ptr, # *int64 [B, scratch_stride]
|
||||
scratch_stride,
|
||||
drafts_ptr, # *int64 [B, K] (output)
|
||||
L,
|
||||
N_BLOCKS,
|
||||
K: tl.constexpr,
|
||||
K_PO2: tl.constexpr,
|
||||
N_BLOCKS_PO2: tl.constexpr,
|
||||
):
|
||||
b = tl.program_id(0).to(tl.int64)
|
||||
Lp1 = tl.cast(L, tl.int64) + 1
|
||||
NB = tl.cast(N_BLOCKS, tl.int64)
|
||||
|
||||
req_state_idx = tl.load(idx_mapping_ptr + b).to(tl.int64)
|
||||
|
||||
nb_iota = tl.arange(0, N_BLOCKS_PO2).to(tl.int64)
|
||||
nb_in_range = nb_iota < NB
|
||||
block_scores = tl.load(
|
||||
scratch_ptr + b * scratch_stride + nb_iota,
|
||||
mask=nb_in_range,
|
||||
other=0,
|
||||
)
|
||||
score = tl.max(block_scores, axis=0)
|
||||
|
||||
seq_len = tl.load(total_len_ptr + req_state_idx).to(tl.int64)
|
||||
num_sampled = tl.load(num_sampled_ptr + b)
|
||||
last_tok = tl.load(last_sampled_ptr + req_state_idx)
|
||||
|
||||
has_match = score > 0
|
||||
s1 = score - 1
|
||||
best_n = tl.where(has_match, s1 // Lp1, tl.zeros_like(s1))
|
||||
best_pos = tl.where(has_match, s1 - best_n * Lp1, tl.zeros_like(s1))
|
||||
draft_start = tl.where(has_match, best_pos + best_n, tl.zeros_like(s1))
|
||||
|
||||
tokens_avail = tl.maximum(seq_len - draft_start, 0)
|
||||
write_ok = (num_sampled > 0) & has_match
|
||||
|
||||
row_off = req_state_idx * token_ids_stride
|
||||
k_iota = tl.arange(0, K_PO2).to(tl.int64)
|
||||
k_in_range = k_iota < K
|
||||
gather_idx = tl.minimum(draft_start + k_iota, tl.cast(L, tl.int64) - 1)
|
||||
slot_valid = (k_iota < tokens_avail) & write_ok & k_in_range
|
||||
gathered = tl.load(
|
||||
token_ids_ptr + row_off + gather_idx,
|
||||
mask=slot_valid,
|
||||
other=0,
|
||||
).to(tl.int64)
|
||||
# Invalid slots fall back to the last sampled token; they are verified as
|
||||
# ordinary (rejectable) drafts, so the fill value only affects efficiency.
|
||||
out = tl.where(slot_valid, gathered, last_tok)
|
||||
tl.store(drafts_ptr + b * K + k_iota, out, mask=k_in_range)
|
||||
|
||||
|
||||
class NgramGPUSpeculator(BaseSpeculator):
|
||||
"""V2-compatible GPU n-gram speculator."""
|
||||
|
||||
supports_mm_inputs = False
|
||||
draft_logits = None
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
vllm_config: VllmConfig,
|
||||
device: torch.device,
|
||||
req_states: RequestState,
|
||||
):
|
||||
if not HAS_TRITON:
|
||||
raise RuntimeError("ngram_gpu speculative decoding requires Triton.")
|
||||
spec = vllm_config.speculative_config
|
||||
assert spec is not None
|
||||
assert spec.prompt_lookup_min is not None, (
|
||||
"prompt_lookup_min must be configured for ngram_gpu"
|
||||
)
|
||||
assert spec.prompt_lookup_max is not None, (
|
||||
"prompt_lookup_max must be configured for ngram_gpu"
|
||||
)
|
||||
assert 1 <= spec.prompt_lookup_min <= spec.prompt_lookup_max
|
||||
|
||||
self.vllm_config = vllm_config
|
||||
self.device = device
|
||||
self.req_states = req_states
|
||||
self.speculative_config = spec
|
||||
self.num_speculative_steps: int = spec.num_speculative_tokens
|
||||
|
||||
self.min_n: int = spec.prompt_lookup_min
|
||||
self.max_n: int = spec.prompt_lookup_max
|
||||
|
||||
self.max_num_reqs: int = vllm_config.scheduler_config.max_num_seqs
|
||||
self.max_model_len: int = vllm_config.model_config.max_model_len
|
||||
|
||||
L = self.max_model_len
|
||||
if L >= 1024:
|
||||
self.block_l = 256
|
||||
elif L >= 256:
|
||||
self.block_l = 128
|
||||
elif L >= 64:
|
||||
self.block_l = 64
|
||||
else:
|
||||
self.block_l = max(16, triton.next_power_of_2(max(L, 1)))
|
||||
self.n_blocks = triton.cdiv(L, self.block_l)
|
||||
|
||||
self.scratch = torch.zeros(
|
||||
(self.max_num_reqs, self.n_blocks), dtype=torch.int64, device=device
|
||||
)
|
||||
# Batch-ordered draft output, scattered into RequestState.draft_tokens
|
||||
# by the model runner (same contract as the model-based speculators).
|
||||
self.drafts = torch.zeros(
|
||||
(self.max_num_reqs, self.num_speculative_steps),
|
||||
dtype=torch.int64,
|
||||
device=device,
|
||||
)
|
||||
|
||||
def init_cudagraph_manager(self, cudagraph_mode: CUDAGraphMode) -> None:
|
||||
del cudagraph_mode
|
||||
|
||||
def capture(self) -> None:
|
||||
return None
|
||||
|
||||
@torch.inference_mode()
|
||||
def propose(
|
||||
self,
|
||||
input_batch: InputBatch,
|
||||
attn_metadata: Any,
|
||||
slot_mappings: Any,
|
||||
last_hidden_states: torch.Tensor,
|
||||
aux_hidden_states: list[torch.Tensor] | None,
|
||||
num_sampled: torch.Tensor,
|
||||
num_rejected: torch.Tensor,
|
||||
last_sampled: torch.Tensor,
|
||||
next_prefill_tokens: torch.Tensor,
|
||||
temperature: torch.Tensor,
|
||||
seeds: torch.Tensor,
|
||||
dp_sync: DPSyncState | None = None,
|
||||
dummy_run: bool = False,
|
||||
skip_attn_for_dummy_run: bool = False,
|
||||
mm_inputs: tuple[list[torch.Tensor], torch.Tensor] | None = None,
|
||||
is_profile: bool = False,
|
||||
num_speculative_tokens: int | None = None,
|
||||
) -> torch.Tensor:
|
||||
num_reqs = input_batch.num_reqs
|
||||
if dummy_run:
|
||||
return self.drafts[:num_reqs]
|
||||
|
||||
req_states = self.req_states
|
||||
token_ids = req_states.all_token_ids.gpu
|
||||
idx_mapping = input_batch.idx_mapping
|
||||
|
||||
_ngram_scan_kernel[(num_reqs, self.n_blocks)](
|
||||
token_ids,
|
||||
token_ids.stride(0),
|
||||
idx_mapping,
|
||||
req_states.total_len.gpu,
|
||||
num_sampled,
|
||||
self.scratch,
|
||||
self.scratch.stride(0),
|
||||
self.max_model_len,
|
||||
self.min_n,
|
||||
self.max_n,
|
||||
max(1, triton.next_power_of_2(self.max_n)),
|
||||
self.block_l,
|
||||
num_warps=4,
|
||||
num_stages=2,
|
||||
)
|
||||
|
||||
_ngram_finalize_kernel[(num_reqs,)](
|
||||
token_ids,
|
||||
token_ids.stride(0),
|
||||
idx_mapping,
|
||||
req_states.total_len.gpu,
|
||||
num_sampled,
|
||||
last_sampled.view(-1),
|
||||
self.scratch,
|
||||
self.scratch.stride(0),
|
||||
self.drafts,
|
||||
self.max_model_len,
|
||||
self.n_blocks,
|
||||
self.num_speculative_steps,
|
||||
max(1, triton.next_power_of_2(self.num_speculative_steps)),
|
||||
max(1, triton.next_power_of_2(self.n_blocks)),
|
||||
num_warps=2,
|
||||
num_stages=1,
|
||||
)
|
||||
return self.drafts[:num_reqs]
|
||||
@@ -97,6 +97,7 @@ class BaseSpeculator(ABC):
|
||||
skip_attn_for_dummy_run: bool = False,
|
||||
mm_inputs: tuple[list[torch.Tensor], torch.Tensor] | None = None,
|
||||
is_profile: bool = False,
|
||||
num_speculative_tokens: int | None = None,
|
||||
) -> torch.Tensor:
|
||||
pass
|
||||
|
||||
@@ -561,3 +562,19 @@ class DraftModelSpeculator(BaseSpeculator):
|
||||
causal=causal,
|
||||
dcp_local_seq_lens=dcp_local_seq_lens,
|
||||
)
|
||||
|
||||
def _update_draft_decode_metadata(
|
||||
self, attn_metadata: dict[str, Any], num_reqs: int
|
||||
) -> None:
|
||||
if self.block_tables.cp_size > 1:
|
||||
prepare_dcp_local_seq_lens(
|
||||
self.input_buffers.dcp_local_seq_lens,
|
||||
self.input_buffers.seq_lens,
|
||||
num_reqs,
|
||||
self.block_tables.cp_size,
|
||||
self.block_tables.cp_rank,
|
||||
self.block_tables.cp_interleave,
|
||||
)
|
||||
for groups in self.attn_groups:
|
||||
for group in groups:
|
||||
group.update_draft_decode_metadata(attn_metadata)
|
||||
|
||||
+8
-7
@@ -26,22 +26,22 @@ from vllm.v1.worker.utils import AttentionGroup
|
||||
logger = init_logger(__name__)
|
||||
|
||||
|
||||
class PlainDraftModelSpeculator(DraftModelSpeculator):
|
||||
"""Speculative decoding using a separate smaller draft LM.
|
||||
class StandaloneARSpeculator(DraftModelSpeculator):
|
||||
"""Standalone autoregressive (AR) drafting with a separate smaller LM.
|
||||
|
||||
Unlike Eagle, the draft model runs fully independently of the target model.
|
||||
Step 0 builds an expanded buffer (accepted + correction token + rejected
|
||||
slots) via a Triton kernel; steps 1..k-1 are single-token decode steps.
|
||||
"""
|
||||
|
||||
# Plain draft model needs one extra slot per request for correction.
|
||||
# Standalone AR drafting needs one extra slot per request for correction.
|
||||
num_extra_query_per_req = 1
|
||||
|
||||
def __init__(self, vllm_config: VllmConfig, device: torch.device):
|
||||
super().__init__(vllm_config, device)
|
||||
|
||||
# draft_max_seq_len is read by the parent's attention metadata builder.
|
||||
# Plain draft model doesn't do per-batch adjustment; cap at max.
|
||||
# Standalone AR drafting doesn't do per-batch adjustment; cap at max.
|
||||
self.draft_max_seq_len = self.max_model_len
|
||||
|
||||
self.last_token_indices = torch.zeros(
|
||||
@@ -65,10 +65,10 @@ class PlainDraftModelSpeculator(DraftModelSpeculator):
|
||||
self.supports_mm_inputs = False
|
||||
|
||||
def init_cudagraph_manager(self, cudagraph_mode: CUDAGraphMode) -> None:
|
||||
pass # CUDA graph not yet supported for plain draft model speculator.
|
||||
pass # CUDA graph not yet supported for standalone AR speculator.
|
||||
|
||||
def capture(self) -> None:
|
||||
pass # CUDA graph not yet supported for plain draft model speculator.
|
||||
pass # CUDA graph not yet supported for standalone AR speculator.
|
||||
|
||||
def set_attn(
|
||||
self,
|
||||
@@ -355,6 +355,7 @@ class PlainDraftModelSpeculator(DraftModelSpeculator):
|
||||
skip_attn_for_dummy_run: bool = False,
|
||||
mm_inputs: tuple[list[torch.Tensor], torch.Tensor] | None = None,
|
||||
is_profile: bool = False,
|
||||
num_speculative_tokens: int | None = None,
|
||||
) -> torch.Tensor:
|
||||
assert self.model is not None
|
||||
|
||||
@@ -414,7 +415,7 @@ def _prepare_prefill_inputs_kernel(
|
||||
max_model_len,
|
||||
BLOCK_SIZE: tl.constexpr,
|
||||
):
|
||||
"""Per-request step-0 input preparation for the plain draft-model speculator.
|
||||
"""Per-request step-0 input preparation for the standalone AR speculator.
|
||||
|
||||
Output layout for request i (out_start = query_start_loc[i] + i):
|
||||
[out_start, out_start + num_valid) accepted tokens
|
||||
+45
@@ -1,11 +1,13 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass, replace
|
||||
|
||||
import torch
|
||||
|
||||
from vllm.config.compilation import CUDAGraphMode
|
||||
from vllm.v1.kv_cache_interface import KVCacheConfig
|
||||
from vllm.v1.spec_decode.dynamic.utils import build_dynamic_sd_schedule_lookup
|
||||
from vllm.v1.worker.gpu.block_table import BlockTables
|
||||
from vllm.v1.worker.gpu.cudagraph_utils import (
|
||||
BatchExecutionDescriptor,
|
||||
@@ -17,6 +19,11 @@ from vllm.v1.worker.gpu.model_states.interface import ModelState
|
||||
from vllm.v1.worker.utils import AttentionGroup
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class SpeculatorBatchDescriptor(BatchExecutionDescriptor):
|
||||
num_speculative_tokens: int = 0
|
||||
|
||||
|
||||
class SpeculatorCudaGraphManager(CudaGraphManager):
|
||||
"""CudaGraphManager for draft prefill and decode.
|
||||
|
||||
@@ -27,6 +34,18 @@ class SpeculatorCudaGraphManager(CudaGraphManager):
|
||||
earlier capture would execute kernels with stale buffer contents.
|
||||
"""
|
||||
|
||||
def specialize_spec_tokens(
|
||||
self, desc: BatchExecutionDescriptor, num_speculative_tokens: int
|
||||
) -> BatchExecutionDescriptor:
|
||||
if desc.cg_mode != CUDAGraphMode.FULL or desc in self.graphs:
|
||||
return desc
|
||||
desc = SpeculatorBatchDescriptor(
|
||||
**vars(desc), num_speculative_tokens=num_speculative_tokens
|
||||
)
|
||||
return (
|
||||
desc if desc in self.graphs else replace(desc, cg_mode=CUDAGraphMode.NONE)
|
||||
)
|
||||
|
||||
def capture(
|
||||
self,
|
||||
forward_fn: Callable,
|
||||
@@ -36,7 +55,25 @@ class SpeculatorCudaGraphManager(CudaGraphManager):
|
||||
attn_groups: list[list[AttentionGroup]],
|
||||
kv_cache_config: KVCacheConfig,
|
||||
progress_bar_desc: str = "Capturing CUDA graphs",
|
||||
specialize_spec_tokens: bool = False,
|
||||
) -> None:
|
||||
if specialize_spec_tokens:
|
||||
speculative_config = self.vllm_config.speculative_config
|
||||
assert speculative_config is not None
|
||||
dense_schedule = build_dynamic_sd_schedule_lookup(
|
||||
speculative_config.num_speculative_tokens_per_batch_size,
|
||||
vllm_max_batch_size=self.max_num_reqs,
|
||||
vllm_num_speculative_tokens=self.vllm_config.num_speculative_tokens,
|
||||
)
|
||||
self._capture_descs = {
|
||||
mode: [
|
||||
SpeculatorBatchDescriptor(**vars(desc), num_speculative_tokens=k)
|
||||
for desc in descs
|
||||
for k in sorted(set(dense_schedule) - {0, 1}, reverse=True)
|
||||
]
|
||||
for mode, descs in self._capture_descs.items()
|
||||
}
|
||||
|
||||
def create_forward_fn(
|
||||
desc: BatchExecutionDescriptor,
|
||||
warmup: bool,
|
||||
@@ -60,6 +97,13 @@ class SpeculatorCudaGraphManager(CudaGraphManager):
|
||||
max_query_len=desc.max_query_len or desc.uniform_token_count,
|
||||
)
|
||||
|
||||
forward_kwargs = {}
|
||||
if self.decode_query_len == 1:
|
||||
forward_kwargs["num_speculative_steps"] = (
|
||||
desc.num_speculative_tokens
|
||||
if isinstance(desc, SpeculatorBatchDescriptor)
|
||||
else self.vllm_config.num_speculative_tokens
|
||||
)
|
||||
return lambda cg_mode: forward_fn(
|
||||
num_reqs,
|
||||
num_tokens,
|
||||
@@ -67,6 +111,7 @@ class SpeculatorCudaGraphManager(CudaGraphManager):
|
||||
slot_mappings,
|
||||
num_tokens_across_dp,
|
||||
cg_mode,
|
||||
**forward_kwargs,
|
||||
)
|
||||
|
||||
super().capture(create_forward_fn, progress_bar_desc)
|
||||
+56
-44
@@ -17,16 +17,22 @@ from vllm.v1.worker.gpu.cudagraph_utils import BatchExecutionDescriptor
|
||||
from vllm.v1.worker.gpu.dp_utils import DPSyncState, dispatch_cg_and_sync_dp
|
||||
from vllm.v1.worker.gpu.input_batch import InputBatch, InputBuffers
|
||||
from vllm.v1.worker.gpu.model_states.interface import ModelState
|
||||
from vllm.v1.worker.gpu.spec_decode.autoregressive.cudagraph_utils import (
|
||||
from vllm.v1.worker.gpu.spec_decode.speculator import DraftModelSpeculator
|
||||
from vllm.v1.worker.gpu.spec_decode.target_dependent_ar.cudagraph_utils import (
|
||||
SpeculatorCudaGraphManager,
|
||||
)
|
||||
from vllm.v1.worker.gpu.spec_decode.speculator import DraftModelSpeculator
|
||||
from vllm.v1.worker.utils import AttentionGroup, get_uniform_decode_token_count
|
||||
|
||||
logger = init_logger(__name__)
|
||||
|
||||
|
||||
class AutoRegressiveSpeculator(DraftModelSpeculator):
|
||||
class TargetDependentARSpeculator(DraftModelSpeculator):
|
||||
"""Autoregressive (AR) drafting that depends on target model state.
|
||||
|
||||
Base for Eagle, MTP, and Gemma4 drafters, which consume the target's
|
||||
hidden states (and, for Gemma4, its KV cache) at each draft step.
|
||||
"""
|
||||
|
||||
def __init__(self, vllm_config: VllmConfig, device: torch.device):
|
||||
super().__init__(vllm_config, device)
|
||||
|
||||
@@ -99,10 +105,6 @@ class AutoRegressiveSpeculator(DraftModelSpeculator):
|
||||
self.use_fused_multi_step_decode = False
|
||||
return
|
||||
|
||||
if not self.advance_draft_positions:
|
||||
self.use_fused_multi_step_decode = True
|
||||
return
|
||||
|
||||
unsupported_backends = sorted(
|
||||
{
|
||||
attn_group.backend.get_name()
|
||||
@@ -190,6 +192,8 @@ class AutoRegressiveSpeculator(DraftModelSpeculator):
|
||||
self.attn_groups,
|
||||
self.kv_cache_config,
|
||||
progress_bar_desc="Capturing decode CUDA graphs",
|
||||
specialize_spec_tokens=self.use_fused_multi_step_decode
|
||||
and self.speculative_config.uses_dynamic_speculative_decoding(),
|
||||
)
|
||||
self.on_multi_step_decode_end(self.max_num_reqs)
|
||||
|
||||
@@ -220,14 +224,17 @@ class AutoRegressiveSpeculator(DraftModelSpeculator):
|
||||
skip_attn_for_dummy_run: bool = False,
|
||||
mm_inputs: tuple[list[torch.Tensor], torch.Tensor] | None = None,
|
||||
is_profile: bool = False,
|
||||
num_speculative_tokens: int | None = None,
|
||||
) -> torch.Tensor:
|
||||
num_reqs = input_batch.num_reqs
|
||||
if num_speculative_tokens is None:
|
||||
num_speculative_tokens = self.num_speculative_steps
|
||||
num_tokens = input_batch.num_tokens
|
||||
num_tokens_padded = input_batch.num_tokens_after_padding
|
||||
num_reqs = input_batch.num_reqs
|
||||
max_query_len = input_batch.num_scheduled_tokens.max()
|
||||
max_seq_len = input_batch.seq_lens_cpu_upper_bound[:num_reqs].max().item()
|
||||
self.draft_max_seq_len = min(
|
||||
max_seq_len + self.num_speculative_steps, self.max_model_len
|
||||
max_seq_len + num_speculative_tokens, self.max_model_len
|
||||
)
|
||||
|
||||
# NOTE(woosuk): To avoid CPU-GPU synchronization without CPU knowing the
|
||||
@@ -322,9 +329,10 @@ class AutoRegressiveSpeculator(DraftModelSpeculator):
|
||||
)
|
||||
self.on_prefill_end(num_reqs)
|
||||
|
||||
if self.num_speculative_steps == 1:
|
||||
# Early exit.
|
||||
return self.draft_tokens[:num_reqs, :1]
|
||||
if num_speculative_tokens <= 1:
|
||||
if num_speculative_tokens == 0:
|
||||
self.draft_tokens[:num_reqs].fill_(-1)
|
||||
return self.draft_tokens[:num_reqs]
|
||||
|
||||
if self.pcp_manager is not None and not dummy_run:
|
||||
self.block_tables.gather_block_tables(
|
||||
@@ -360,6 +368,10 @@ class AutoRegressiveSpeculator(DraftModelSpeculator):
|
||||
need_eager=is_profile,
|
||||
dp_sync=decode_batch_sync,
|
||||
)
|
||||
if self.decode_cudagraph_manager is not None:
|
||||
decode_batch_desc = self.decode_cudagraph_manager.specialize_spec_tokens(
|
||||
decode_batch_desc, num_speculative_tokens
|
||||
)
|
||||
num_tokens_across_dp = (
|
||||
decode_batch_sync.num_tokens_across_dp
|
||||
if decode_batch_sync is not None
|
||||
@@ -379,6 +391,7 @@ class AutoRegressiveSpeculator(DraftModelSpeculator):
|
||||
decode_batch_desc,
|
||||
num_tokens_across_dp,
|
||||
input_batch.seq_lens_cpu_upper_bound,
|
||||
num_speculative_tokens,
|
||||
)
|
||||
self.on_multi_step_decode_end(num_reqs)
|
||||
|
||||
@@ -505,6 +518,7 @@ class AutoRegressiveSpeculator(DraftModelSpeculator):
|
||||
batch_desc: BatchExecutionDescriptor,
|
||||
num_tokens_across_dp: torch.Tensor | None,
|
||||
seq_lens_cpu_upper_bound: torch.Tensor,
|
||||
num_speculative_steps: int,
|
||||
) -> None:
|
||||
positions = self.input_buffers.positions[:num_reqs]
|
||||
query_start_loc = self.input_buffers.query_start_loc[: num_reqs + 1]
|
||||
@@ -512,7 +526,7 @@ class AutoRegressiveSpeculator(DraftModelSpeculator):
|
||||
|
||||
attn_metadata = None
|
||||
slot_mappings_by_layer = None
|
||||
for step in range(1, self.num_speculative_steps):
|
||||
for step in range(1, num_speculative_steps):
|
||||
# Rebuild every step when positions advance, or just once
|
||||
# on the first step when positions are constant (Gemma4 MTP).
|
||||
if not skip_attn and (self.advance_draft_positions or step == 1):
|
||||
@@ -546,6 +560,7 @@ class AutoRegressiveSpeculator(DraftModelSpeculator):
|
||||
slot_mappings_by_layer,
|
||||
num_tokens_across_dp=num_tokens_across_dp,
|
||||
cudagraph_runtime_mode=batch_desc.cg_mode,
|
||||
num_speculative_steps=num_speculative_steps,
|
||||
)
|
||||
|
||||
def _fused_multi_step_decode(
|
||||
@@ -555,11 +570,17 @@ class AutoRegressiveSpeculator(DraftModelSpeculator):
|
||||
batch_desc: BatchExecutionDescriptor,
|
||||
num_tokens_across_dp: torch.Tensor | None,
|
||||
seq_lens_cpu_upper_bound: torch.Tensor,
|
||||
num_speculative_steps: int,
|
||||
) -> None:
|
||||
positions = self.input_buffers.positions[:num_reqs]
|
||||
query_start_loc = self.input_buffers.query_start_loc[: num_reqs + 1]
|
||||
idx_mapping = self.idx_mapping[:num_reqs]
|
||||
|
||||
if batch_desc.cg_mode == CUDAGraphMode.FULL:
|
||||
assert self.decode_cudagraph_manager is not None
|
||||
self.decode_cudagraph_manager.run_fullgraph(batch_desc)
|
||||
return
|
||||
|
||||
attn_metadata = None
|
||||
slot_mappings_by_layer = None
|
||||
if not skip_attn:
|
||||
@@ -569,10 +590,9 @@ class AutoRegressiveSpeculator(DraftModelSpeculator):
|
||||
positions,
|
||||
batch_desc.num_tokens,
|
||||
)
|
||||
if batch_desc.cg_mode != CUDAGraphMode.FULL:
|
||||
slot_mappings_by_layer = build_slot_mappings_by_layer(
|
||||
slot_mappings, self.kv_cache_config
|
||||
)
|
||||
slot_mappings_by_layer = build_slot_mappings_by_layer(
|
||||
slot_mappings, self.kv_cache_config
|
||||
)
|
||||
attn_metadata = self._build_uniform_attn_metadata(
|
||||
num_reqs=num_reqs,
|
||||
batch_desc=batch_desc,
|
||||
@@ -581,11 +601,6 @@ class AutoRegressiveSpeculator(DraftModelSpeculator):
|
||||
step=1,
|
||||
)
|
||||
|
||||
if batch_desc.cg_mode == CUDAGraphMode.FULL:
|
||||
assert self.decode_cudagraph_manager is not None
|
||||
self.decode_cudagraph_manager.run_fullgraph(batch_desc)
|
||||
return
|
||||
|
||||
self._generate_fused_drafts(
|
||||
num_reqs,
|
||||
batch_desc.num_tokens,
|
||||
@@ -593,6 +608,7 @@ class AutoRegressiveSpeculator(DraftModelSpeculator):
|
||||
slot_mappings_by_layer,
|
||||
num_tokens_across_dp,
|
||||
batch_desc.cg_mode,
|
||||
num_speculative_steps,
|
||||
)
|
||||
|
||||
def _generate_fused_drafts(
|
||||
@@ -602,18 +618,25 @@ class AutoRegressiveSpeculator(DraftModelSpeculator):
|
||||
attn_metadata: dict[str, Any] | None,
|
||||
slot_mappings: dict[str, torch.Tensor] | None,
|
||||
num_tokens_across_dp: torch.Tensor | None,
|
||||
cudagraph_runtime_mode: CUDAGraphMode = CUDAGraphMode.NONE,
|
||||
cudagraph_runtime_mode: CUDAGraphMode,
|
||||
num_speculative_steps: int,
|
||||
) -> None:
|
||||
idx_mapping = self.idx_mapping[:num_reqs]
|
||||
positions = self.input_buffers.positions[:num_reqs]
|
||||
query_start_loc = self.input_buffers.query_start_loc[: num_reqs + 1]
|
||||
attn_groups = (
|
||||
[group for groups in self.attn_groups for group in groups]
|
||||
if attn_metadata is not None
|
||||
else []
|
||||
)
|
||||
|
||||
for step in range(1, self.num_speculative_steps):
|
||||
for step in range(1, num_speculative_steps):
|
||||
if attn_metadata is not None and (
|
||||
self.advance_draft_positions or step == 1
|
||||
):
|
||||
self.block_tables.compute_slot_mappings(
|
||||
idx_mapping,
|
||||
query_start_loc,
|
||||
positions,
|
||||
num_tokens_padded,
|
||||
)
|
||||
self._update_draft_decode_metadata(attn_metadata, num_reqs)
|
||||
|
||||
self.current_draft_step.fill_(step)
|
||||
self._generate_draft(
|
||||
num_reqs,
|
||||
@@ -622,20 +645,8 @@ class AutoRegressiveSpeculator(DraftModelSpeculator):
|
||||
slot_mappings,
|
||||
num_tokens_across_dp,
|
||||
cudagraph_runtime_mode,
|
||||
num_speculative_steps,
|
||||
)
|
||||
if (
|
||||
step < self.num_speculative_steps - 1
|
||||
and attn_metadata is not None
|
||||
and self.advance_draft_positions
|
||||
):
|
||||
self.block_tables.compute_slot_mappings(
|
||||
idx_mapping,
|
||||
query_start_loc,
|
||||
positions,
|
||||
num_tokens_padded,
|
||||
)
|
||||
for attn_group in attn_groups:
|
||||
attn_group.update_draft_decode_metadata(attn_metadata)
|
||||
|
||||
def _generate_draft(
|
||||
self,
|
||||
@@ -644,7 +655,8 @@ class AutoRegressiveSpeculator(DraftModelSpeculator):
|
||||
attn_metadata: dict[str, Any] | None,
|
||||
slot_mappings: dict[str, torch.Tensor] | None,
|
||||
num_tokens_across_dp: torch.Tensor | None,
|
||||
cudagraph_runtime_mode: CUDAGraphMode = CUDAGraphMode.NONE,
|
||||
cudagraph_runtime_mode: CUDAGraphMode,
|
||||
num_speculative_steps: int,
|
||||
) -> None:
|
||||
self._prepare_eplb_forward(num_reqs)
|
||||
|
||||
@@ -682,7 +694,7 @@ class AutoRegressiveSpeculator(DraftModelSpeculator):
|
||||
self.sample_src_positions,
|
||||
num_reqs,
|
||||
self.max_model_len,
|
||||
self.num_speculative_steps,
|
||||
num_speculative_steps,
|
||||
advance_draft_positions=self.advance_draft_positions,
|
||||
)
|
||||
|
||||
@@ -16,6 +16,7 @@ class RequestState:
|
||||
vocab_size: int,
|
||||
device: torch.device,
|
||||
num_prefill_lookahead: int = 1,
|
||||
use_dense_all_token_ids: bool = False,
|
||||
):
|
||||
self.max_num_reqs = max_num_reqs
|
||||
self.max_model_len = max_model_len
|
||||
@@ -30,12 +31,14 @@ class RequestState:
|
||||
|
||||
# NOTE(woosuk): This tensor can be extremely large (e.g., several GBs)
|
||||
# depending on the configured max_num_reqs and max_model_len.
|
||||
# To save GPU memory, we use UVA instead of GPU for this tensor.
|
||||
# To save GPU memory, we use UVA instead of GPU by default, but
|
||||
# ngram_gpu benefits from dense device residency because it scans
|
||||
# active rows repeatedly during proposal.
|
||||
self.all_token_ids = StagedWriteTensor(
|
||||
(self.max_num_reqs, self.max_model_len),
|
||||
dtype=torch.int32,
|
||||
device=device,
|
||||
uva_instead_of_gpu=True,
|
||||
uva_instead_of_gpu=not use_dense_all_token_ids,
|
||||
)
|
||||
# NOTE(woosuk): Distinguish clearly between prompt_len and prefill_len:
|
||||
# - prompt_len: Number of tokens in the user-provided prompt.
|
||||
|
||||
@@ -139,9 +139,16 @@ def run_mixed_prefill_decode_warmup(
|
||||
next_block_id += num_blocks
|
||||
return block_ids
|
||||
|
||||
sampling_params = SamplingParams(max_tokens=2, temperature=0.0)
|
||||
sampling_params = SamplingParams(
|
||||
max_tokens=2,
|
||||
temperature=0.0,
|
||||
watermarking=False,
|
||||
)
|
||||
|
||||
decode_prefill_output = SchedulerOutput.make_empty()
|
||||
decode_prefill_output.num_spec_tokens_to_schedule = (
|
||||
model_runner.num_speculative_steps
|
||||
)
|
||||
decode_prefill_output.scheduled_new_reqs = [
|
||||
NewRequestData(
|
||||
req_id=decode_req_id,
|
||||
@@ -171,6 +178,7 @@ def run_mixed_prefill_decode_warmup(
|
||||
]
|
||||
|
||||
mixed_output = SchedulerOutput.make_empty()
|
||||
mixed_output.num_spec_tokens_to_schedule = model_runner.num_speculative_steps
|
||||
mixed_output.scheduled_cached_reqs = cached_decode_req
|
||||
mixed_output.scheduled_new_reqs = [
|
||||
NewRequestData(
|
||||
@@ -349,6 +357,7 @@ def _warmup_kernels(
|
||||
]
|
||||
|
||||
prefill_output = SchedulerOutput.make_empty()
|
||||
prefill_output.num_spec_tokens_to_schedule = num_spec_steps
|
||||
prefill_output.scheduled_new_reqs = new_reqs
|
||||
prefill_output.num_scheduled_tokens = {rid: prompt_len for rid in req_ids}
|
||||
prefill_output.total_num_scheduled_tokens = prompt_len * num_reqs
|
||||
@@ -408,6 +417,7 @@ def _warmup_kernels(
|
||||
step_spec_tokens[req_ids[i]] = [0] * num_spec_steps
|
||||
|
||||
decode_output = SchedulerOutput.make_empty()
|
||||
decode_output.num_spec_tokens_to_schedule = num_spec_steps
|
||||
decode_output.scheduled_cached_reqs = cached_req_data
|
||||
decode_output.num_scheduled_tokens = step_num_scheduled_tokens
|
||||
decode_output.scheduled_spec_decode_tokens = step_spec_tokens
|
||||
|
||||
Reference in New Issue
Block a user