Merge main into dev/vllm-align for vLLM 0.31 release
Signed-off-by: tzhouam <tzhouam@connect.ust.hk>
This commit is contained in:
commit
008fa25263
252 files changed
+27589
-1237
No files matched your search
@@ -100,6 +100,23 @@ class OmniARScheduler(OmniSchedulerMixin, VLLMScheduler):
|
||||
|
||||
max_num_active_reqs: int
|
||||
|
||||
def reset_prefix_cache(self, reset_running_requests: bool = False, reset_connector: bool = False) -> bool:
|
||||
model_config = self.vllm_config.model_config
|
||||
if (
|
||||
reset_running_requests
|
||||
and self.running
|
||||
and not getattr(model_config, "supports_running_prefix_cache_reset", True)
|
||||
):
|
||||
# Reset preempts and resumes in the same step while discarding
|
||||
# in-flight tokens. The stateful codec and queued PCM have already
|
||||
# consumed those frames and cannot roll back to that boundary.
|
||||
logger.warning(
|
||||
"This stage cannot reset running requests; wait for "
|
||||
"completion or abort them before resetting the prefix cache."
|
||||
)
|
||||
return False
|
||||
return super().reset_prefix_cache(reset_running_requests, reset_connector)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
# Track requests that need KV cache transfer when finished
|
||||
@@ -126,8 +143,11 @@ class OmniARScheduler(OmniSchedulerMixin, VLLMScheduler):
|
||||
# Track requests that have already triggered prefill transfer to avoid duplicates
|
||||
self.transfer_triggered_requests: set[str] = set()
|
||||
|
||||
# Cache per-request flag to avoid repeated deserialization of additional_information
|
||||
self._omits_kv_transfer_cache: dict[str, bool] = {}
|
||||
# Cache per-request flags to avoid repeated deserialization of
|
||||
# additional_information. Value is (payload_id, is_stage_zero_final,
|
||||
# force_kv_transfer); payload_id invalidates the entry when the
|
||||
# object is replaced.
|
||||
self._omits_kv_transfer_cache: dict[str, tuple[int, bool, bool]] = {}
|
||||
|
||||
# KV-wait start ts for the vllm_omni:kv_wait_s metric; see
|
||||
# _emit_kv_wait_output for the engine-core → orchestrator carry.
|
||||
@@ -246,26 +266,40 @@ class OmniARScheduler(OmniSchedulerMixin, VLLMScheduler):
|
||||
return config.get(key, default)
|
||||
return getattr(config, key, default) if config is not None else default
|
||||
|
||||
def _request_omits_kv_transfer_to_next_stage(self, request: Request) -> bool:
|
||||
"""True when this stage-zero-final request does not need downstream KV.
|
||||
|
||||
The result is cached per request to avoid repeated deserialization of
|
||||
additional_information on every scheduler tick.
|
||||
"""
|
||||
rid = request.request_id
|
||||
cached = self._omits_kv_transfer_cache.get(rid)
|
||||
if cached is not None:
|
||||
return cached
|
||||
|
||||
def _omni_final_stage_flags(self, request: Request) -> tuple[bool, bool]:
|
||||
"""Return ``(is_stage_zero_final, force_kv_transfer)`` from request metadata."""
|
||||
payload = getattr(request, "additional_information", None)
|
||||
if payload is None:
|
||||
result = False
|
||||
else:
|
||||
info = deserialize_additional_information(payload)
|
||||
result = info.get("omni_final_stage_id") == 0 and not bool(info.get("omni_force_kv_transfer", False))
|
||||
return False, False
|
||||
|
||||
self._omits_kv_transfer_cache[rid] = result
|
||||
return result
|
||||
cache = getattr(self, "_omits_kv_transfer_cache", None)
|
||||
rid = request.request_id
|
||||
payload_id = id(payload)
|
||||
if cache is not None:
|
||||
cached = cache.get(rid)
|
||||
if cached is not None and cached[0] == payload_id:
|
||||
return cached[1], cached[2]
|
||||
|
||||
info = deserialize_additional_information(payload)
|
||||
is_final = info.get("omni_final_stage_id") == 0
|
||||
force_kv = bool(info.get("omni_force_kv_transfer", False))
|
||||
if cache is not None:
|
||||
cache[rid] = (payload_id, is_final, force_kv)
|
||||
return is_final, force_kv
|
||||
|
||||
def _request_omits_kv_transfer_to_next_stage(self, request: Request) -> bool:
|
||||
"""True when this stage-zero-final request does not need downstream KV."""
|
||||
is_final, force_kv = self._omni_final_stage_flags(request)
|
||||
return is_final and not force_kv
|
||||
|
||||
def _request_omits_chunk_transfer_to_next_stage(self, request: Request) -> bool:
|
||||
"""True when this request has no downstream chunk consumer.
|
||||
|
||||
CFG companions still force KV transfer but are stage-0-final for
|
||||
ordinary inter-stage chunks, so they omit ``save_async`` here.
|
||||
"""
|
||||
is_final, _ = self._omni_final_stage_flags(request)
|
||||
return is_final
|
||||
|
||||
def _should_defer_waiting_admission(self) -> bool:
|
||||
return False
|
||||
@@ -517,7 +551,7 @@ class OmniARScheduler(OmniSchedulerMixin, VLLMScheduler):
|
||||
# domains must consume the old frame before new output passes.
|
||||
request.async_tokens_to_discard = max(0, stale_async_tokens - len(generated_token_ids))
|
||||
|
||||
if output_is_stale or async_output_is_stale:
|
||||
if async_output_is_stale or (output_is_stale and request.drop_stale_output):
|
||||
# Output of a step scheduled before the request's in-flight
|
||||
# tokens were discarded (segment stop / session replacement).
|
||||
# num_computed_tokens was rolled back at the discard site, so
|
||||
@@ -556,12 +590,13 @@ class OmniARScheduler(OmniSchedulerMixin, VLLMScheduler):
|
||||
# tokens and rejections. If some tokens are rejected,
|
||||
# num_computed_tokens is decreased by the number of rejected
|
||||
# tokens.
|
||||
if request.num_computed_tokens > 0:
|
||||
request.num_computed_tokens -= num_rejected
|
||||
# If async scheduling, num_output_placeholders also includes
|
||||
# the scheduled spec tokens count and so is similarly adjusted.
|
||||
if request.num_output_placeholders > 0:
|
||||
request.num_output_placeholders -= num_rejected
|
||||
if not output_is_stale:
|
||||
if request.num_computed_tokens > 0:
|
||||
request.num_computed_tokens -= num_rejected
|
||||
# If async scheduling, num_output_placeholders also includes
|
||||
# the scheduled spec tokens count and so is similarly adjusted.
|
||||
if request.num_output_placeholders > 0:
|
||||
request.num_output_placeholders -= num_rejected
|
||||
spec_decoding_stats = self.make_spec_decoding_stats(
|
||||
spec_decoding_stats,
|
||||
num_draft_tokens=num_draft_tokens,
|
||||
@@ -600,7 +635,10 @@ class OmniARScheduler(OmniSchedulerMixin, VLLMScheduler):
|
||||
# Check for stop and update request status.
|
||||
if new_token_ids:
|
||||
num_sampled_tokens = len(new_token_ids)
|
||||
new_token_ids, stopped = self._update_request_with_output(request, new_token_ids)
|
||||
if output_is_stale:
|
||||
new_token_ids, stopped = self._update_request_with_output(request, new_token_ids, is_stale=True)
|
||||
else:
|
||||
new_token_ids, stopped = self._update_request_with_output(request, new_token_ids)
|
||||
if new_logprobs is not None and len(new_token_ids) < num_sampled_tokens:
|
||||
# A mid-step stop (e.g. spec-decode tokens sampled past
|
||||
# EOS) trims new_token_ids after the validation slice
|
||||
@@ -648,6 +686,11 @@ class OmniARScheduler(OmniSchedulerMixin, VLLMScheduler):
|
||||
|
||||
confirmed_num_computed_tokens = None
|
||||
boundary_generation = None
|
||||
# Only when this step might save. Read additional_information
|
||||
# before _free_request rewrites it.
|
||||
omits_chunk_transfer = False
|
||||
if self.chunk_transfer_adapter is not None and (inter_stage_output is not None or stopped):
|
||||
omits_chunk_transfer = self._request_omits_chunk_transfer_to_next_stage(request)
|
||||
# Capture before resumable stop handling can clear token history.
|
||||
output_token_ids: Any = getattr(request, "output_token_ids", None)
|
||||
if output_token_ids is None:
|
||||
@@ -707,6 +750,7 @@ class OmniARScheduler(OmniSchedulerMixin, VLLMScheduler):
|
||||
# a queued streaming update, and adding twice swallows the
|
||||
# next duplex unit's listen/speak under async scheduling.
|
||||
if request.num_in_flight_tokens > 0:
|
||||
request.drop_stale_output = True
|
||||
request.num_stale_output_tokens = request.num_in_flight_tokens
|
||||
if outstanding_async_tokens > 0:
|
||||
# Discard only outputs that are already in flight and
|
||||
@@ -771,8 +815,16 @@ class OmniARScheduler(OmniSchedulerMixin, VLLMScheduler):
|
||||
assert not prompt_logprobs_tensors
|
||||
assert prompt_token_id_logprobs is None
|
||||
|
||||
if self.chunk_transfer_adapter is not None and (
|
||||
inter_stage_output is not None or is_segment_finished or finished
|
||||
if omits_chunk_transfer and inter_stage_output is not None:
|
||||
logger.warning(
|
||||
"Skipping inter-stage chunk for request %s: "
|
||||
"omni_final_stage_id=0 but inter_stage_output is present",
|
||||
req_id,
|
||||
)
|
||||
if (
|
||||
self.chunk_transfer_adapter is not None
|
||||
and not omits_chunk_transfer
|
||||
and (inter_stage_output is not None or is_segment_finished or finished)
|
||||
):
|
||||
save_kwargs = {
|
||||
"new_token_ids": new_token_ids,
|
||||
@@ -890,6 +942,7 @@ class OmniARScheduler(OmniSchedulerMixin, VLLMScheduler):
|
||||
# a resumable stop applies a queued update through this helper.
|
||||
in_flight_tokens = int(getattr(session, "num_in_flight_tokens", 0) or 0)
|
||||
if in_flight_tokens > 0:
|
||||
session.drop_stale_output = True
|
||||
session.num_stale_output_tokens = in_flight_tokens
|
||||
if outstanding_async_tokens > 0:
|
||||
# Async scheduling may already have sampled the previous
|
||||
@@ -1413,6 +1466,7 @@ class OmniARScheduler(OmniSchedulerMixin, VLLMScheduler):
|
||||
if status is not None:
|
||||
request.status = status
|
||||
if native_transfer and connector_delay_free_blocks:
|
||||
assert transfer_params is not None
|
||||
kv_xfer_params = {
|
||||
**(kv_xfer_params or {}),
|
||||
"transfer_id": transfer_params["transfer_id"],
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import math
|
||||
import os
|
||||
import queue
|
||||
import time
|
||||
from collections import defaultdict
|
||||
from typing import TYPE_CHECKING, Any
|
||||
@@ -57,6 +59,48 @@ class OmniGenerationScheduler(OmniSchedulerMixin, VLLMScheduler):
|
||||
self._init_omni_io_scheduling_state()
|
||||
self._retains_state_across_chunks = bool(getattr(model_config, "retains_state_across_chunks", False))
|
||||
self._pending_finish_reqs: list[Request] = []
|
||||
connector_config = getattr(model_config, "stage_connector_config", None)
|
||||
extra = (
|
||||
connector_config.get("extra", connector_config)
|
||||
if isinstance(connector_config, dict)
|
||||
else getattr(connector_config, "extra", None)
|
||||
) or {}
|
||||
self._generation_min_batch_size = int(extra.get("generation_min_batch_size", 1))
|
||||
self._generation_max_wait_s = float(extra.get("generation_max_wait_ms", 0)) / 1000
|
||||
self._generation_coalescing_policy = extra.get("generation_coalescing_policy", "fixed")
|
||||
self._generation_max_regular_batch = int(extra.get("generation_max_regular_batch", 0) or 0)
|
||||
if self._generation_max_regular_batch < 0:
|
||||
raise ValueError("generation_max_regular_batch must be nonnegative")
|
||||
if self._generation_coalescing_policy not in ("fixed", "idle_wait"):
|
||||
raise ValueError("generation_coalescing_policy must be fixed or idle_wait")
|
||||
if not 1 <= self._generation_min_batch_size <= self.max_num_running_reqs:
|
||||
raise ValueError("generation_min_batch_size must be in [1, max_num_seqs]")
|
||||
if not math.isfinite(self._generation_max_wait_s) or self._generation_max_wait_s < 0:
|
||||
raise ValueError("generation_max_wait_ms must be finite and nonnegative")
|
||||
if self._generation_max_wait_s and self._generation_min_batch_size > 1:
|
||||
parallel = self.vllm_config.parallel_config
|
||||
if not self._native_data_plane:
|
||||
# CUDA-oriented profiles can inherit a platform's V1 runner.
|
||||
# Their connector extras survive that override, but batching
|
||||
# must revert to the fallback runner's default scheduling.
|
||||
logger.warning(
|
||||
"Generation batch waiting and regular-batch limit ignored: "
|
||||
"requires native MRV2; using default generation scheduling."
|
||||
)
|
||||
self._generation_min_batch_size = 1
|
||||
self._generation_max_wait_s = 0.0
|
||||
self._generation_max_regular_batch = 0
|
||||
elif not (
|
||||
self._retains_state_across_chunks
|
||||
and parallel.tensor_parallel_size == parallel.pipeline_parallel_size == 1
|
||||
):
|
||||
raise ValueError("Generation batch waiting requires a stateful native MRV2 TP1/PP1 stage")
|
||||
else:
|
||||
logger.info(
|
||||
"Generation input coalescing: target batch=%d, max wait=%.3f ms",
|
||||
self._generation_min_batch_size,
|
||||
self._generation_max_wait_s * 1000,
|
||||
)
|
||||
self._first_chunk_express = os.environ.get("VLLM_OMNI_CODEC_FIRST_CHUNK_EXPRESS") == "1"
|
||||
self._last_step_express = False
|
||||
# Streams that already had a chunk scheduled; the rest await their first.
|
||||
@@ -75,6 +119,101 @@ class OmniGenerationScheduler(OmniSchedulerMixin, VLLMScheduler):
|
||||
self._express_min_slack_s,
|
||||
)
|
||||
|
||||
def _drain_omni_connector_outputs(self):
|
||||
self._generation_defer_batch = False
|
||||
outputs = super()._drain_omni_connector_outputs()
|
||||
max_wait = getattr(self, "_generation_max_wait_s", 0)
|
||||
target = getattr(self, "_generation_min_batch_size", 1)
|
||||
coordinator = self.input_coordinator
|
||||
if not max_wait or target <= 1 or coordinator is None or self._pause_state != PauseState.UNPAUSED:
|
||||
return outputs
|
||||
|
||||
# Count distinct runnable streams, not notifications, padding rows, or
|
||||
# chunks whose previous execution still owns their state. Waiting here
|
||||
# precedes allocation and metadata replacement. Do not schedule a batch
|
||||
# and then discard it to try to accumulate more input.
|
||||
ready = set(coordinator.requests_with_ready_chunks)
|
||||
terminal = set(coordinator.finished_requests) | set(coordinator.input_terminal_req_ids)
|
||||
deadline = getattr(self, "_generation_batch_deadline", None)
|
||||
if deadline is None:
|
||||
deadline = time.monotonic() + max_wait
|
||||
in_flight = any(
|
||||
not request.is_finished() and request.num_in_flight_tokens > 0 for request in self.requests.values()
|
||||
)
|
||||
new_outputs = outputs
|
||||
waited_without_input = False
|
||||
while True:
|
||||
for output in new_outputs:
|
||||
ready.update(output.chunk_ready_req_ids)
|
||||
terminal.update(output.chunk_finished_req_ids)
|
||||
terminal.update(
|
||||
req_id for req_id, metadata in output.request_metadata.items() if metadata.get("input_terminal")
|
||||
)
|
||||
runnable = {
|
||||
req_id
|
||||
for req_id in ready | terminal
|
||||
if (request := self.requests.get(req_id)) is not None
|
||||
and not request.is_finished()
|
||||
and request.num_in_flight_tokens == 0
|
||||
}
|
||||
if runnable and waited_without_input:
|
||||
# Idle waiting must not eat the ready batch's coalescing budget.
|
||||
# Start that budget at its first arrival, once only. The two
|
||||
# bounded windows can delay control processing by at most 2W.
|
||||
deadline = time.monotonic() + max_wait
|
||||
waited_without_input = False
|
||||
# A first/final chunk participates in the same bounded window.
|
||||
# At high concurrency almost every batch contains one; bypassing
|
||||
# the entire batch in that case defeats coalescing. Low concurrency
|
||||
# still dispatches immediately, including single-request tails.
|
||||
if not runnable:
|
||||
# With no output to retire and all receivers already parked,
|
||||
# a wakeable inbox wait avoids repeatedly executing empty steps.
|
||||
# Admission/registration/terminal work must reach the runner
|
||||
# first; waiting for a not-yet-registered receiver would stall it.
|
||||
can_wait_idle = (
|
||||
getattr(self, "_generation_coalescing_policy", "fixed") == "idle_wait"
|
||||
and not in_flight
|
||||
and bool(self.requests)
|
||||
and not getattr(coordinator, "pending_chunk_registrations", ())
|
||||
and not getattr(coordinator, "pending_input_registrations", ())
|
||||
and not getattr(self, "_pending_data_plane_terminal_req_ids", ())
|
||||
and all(request.status == RequestStatus.WAITING_FOR_CHUNK for request in self.requests.values())
|
||||
)
|
||||
if not can_wait_idle:
|
||||
break
|
||||
waited_without_input = True
|
||||
elif len(runnable) >= target or len(self.requests) < target:
|
||||
break
|
||||
remaining = deadline - time.monotonic()
|
||||
if remaining <= 0:
|
||||
break
|
||||
if in_flight:
|
||||
# Let EngineCore retire the prior output before waiting for
|
||||
# more input. Blocking this thread also blocks the in-flight
|
||||
# fence that makes those streams eligible for the next batch.
|
||||
# Emit a normal empty scheduler step (including connector and
|
||||
# cancellation bookkeeping), never discard an allocated step.
|
||||
self._generation_defer_batch = True
|
||||
self._generation_batch_deadline = deadline
|
||||
return outputs
|
||||
try:
|
||||
output = self._omni_connector_output_inbox.get(timeout=remaining)
|
||||
except queue.Empty:
|
||||
break
|
||||
outputs.append(output)
|
||||
new_outputs = [output]
|
||||
# Drain a burst before re-evaluating, retaining notification order.
|
||||
while True:
|
||||
try:
|
||||
output = self._omni_connector_output_inbox.get_nowait()
|
||||
except queue.Empty:
|
||||
break
|
||||
outputs.append(output)
|
||||
new_outputs.append(output)
|
||||
self._generation_batch_deadline = None
|
||||
return outputs
|
||||
|
||||
def _build_generation_scheduler_output(
|
||||
self,
|
||||
new_reqs_data: list[OmniNewRequestData],
|
||||
@@ -260,6 +399,11 @@ class OmniGenerationScheduler(OmniSchedulerMixin, VLLMScheduler):
|
||||
self._drop_aborted_queued_requests()
|
||||
self._requeue_completed_native_chunks()
|
||||
self._process_pending_omni_inputs(model_mode="generation")
|
||||
if getattr(self, "_generation_defer_batch", False):
|
||||
token_budget = 0
|
||||
max_regular = getattr(self, "_generation_max_regular_batch", 0)
|
||||
if max_regular:
|
||||
execution_batch_size = min(execution_batch_size, max_regular)
|
||||
self._drop_aborted_queued_requests()
|
||||
self._resync_streaming_input_counter()
|
||||
async_chunk_transport = self._async_chunk_transport_enabled()
|
||||
|
||||
@@ -274,12 +274,16 @@ class OmniSchedulerMixin(_SchedulerMixinBase):
|
||||
# num_in_flight_tokens already includes any undrained stale share.
|
||||
# Assign instead of accumulating so callers that fenced the same
|
||||
# rollover before entering this helper do not count it twice.
|
||||
session.drop_stale_output = True
|
||||
session.num_stale_output_tokens = int(getattr(session, "num_in_flight_tokens", 0) or 0)
|
||||
session.num_output_placeholders = 0
|
||||
session.spec_token_ids = []
|
||||
|
||||
def _finish_streaming_session_update(self, session: Request, update: StreamingUpdate) -> None:
|
||||
"""Install payload metadata and send an updated session to admission."""
|
||||
cache = getattr(self, "_omits_kv_transfer_cache", None)
|
||||
if cache is not None:
|
||||
cache.pop(session.request_id, None)
|
||||
session.additional_information = update.additional_information or None
|
||||
session.model_intermediate_buffer = getattr(
|
||||
update,
|
||||
@@ -369,6 +373,7 @@ class OmniSchedulerMixin(_SchedulerMixinBase):
|
||||
# The streaming update may already have fenced this same in-flight
|
||||
# frame. Seed idempotently so the replacement does not count it twice.
|
||||
request.num_stale_output_tokens = int(getattr(request, "num_in_flight_tokens", 0) or 0)
|
||||
request.drop_stale_output = True
|
||||
request.num_output_placeholders = 0
|
||||
request.spec_token_ids = []
|
||||
self._release_replaced_streaming_prompt_cache(request)
|
||||
@@ -379,13 +384,8 @@ class OmniSchedulerMixin(_SchedulerMixinBase):
|
||||
# ready-chunk marker remains until scheduler admission succeeds.
|
||||
replaced_ids.discard(request_id)
|
||||
|
||||
def _consume_pending_connector_output(self, model_mode: str) -> None:
|
||||
"""Drain ``self._latest_omni_connector_output`` into the coordinator.
|
||||
|
||||
Called at the top of every ``schedule()`` cycle. Identical between
|
||||
AR and generation schedulers except for the ``model_mode`` argument
|
||||
forwarded to ``update_request_metadata``.
|
||||
"""
|
||||
def _drain_omni_connector_outputs(self) -> list[OmniConnectorOutput]:
|
||||
"""Collect control messages in order, without changing request state."""
|
||||
connector_outputs: list[OmniConnectorOutput] = []
|
||||
inbox = getattr(self, "_omni_connector_output_inbox", None)
|
||||
if inbox is not None:
|
||||
@@ -398,6 +398,11 @@ class OmniSchedulerMixin(_SchedulerMixinBase):
|
||||
self._latest_omni_connector_output = None
|
||||
if connector_output is not None:
|
||||
connector_outputs.append(connector_output)
|
||||
return connector_outputs
|
||||
|
||||
def _consume_pending_connector_output(self, model_mode: str) -> None:
|
||||
"""Drain input notifications into the coordinator on the scheduler thread."""
|
||||
connector_outputs = self._drain_omni_connector_outputs()
|
||||
input_coordinator = getattr(self, "input_coordinator", None)
|
||||
if input_coordinator is None:
|
||||
return
|
||||
|
||||
@@ -379,14 +379,17 @@ class OmniSchedulingCoordinator:
|
||||
)
|
||||
|
||||
if model_mode != "ar":
|
||||
new_ids = self._flatten_prompt_token_ids(metadata.get("code_predictor_codes"))
|
||||
new_codes = metadata.get("code_predictor_codes")
|
||||
new_ids = self._flatten_prompt_token_ids(new_codes)
|
||||
runtime_seed = None
|
||||
if "left_context_size" in metadata:
|
||||
runtime_seed = {
|
||||
"meta": {"left_context_size": metadata["left_context_size"]},
|
||||
}
|
||||
request._omni_initial_model_buffer = runtime_seed
|
||||
if new_ids:
|
||||
# An explicit empty snapshot clears a previous codec chunk
|
||||
# or prewarmed placeholder. Missing codes leave it intact.
|
||||
if new_codes is not None:
|
||||
request.prompt_token_ids = new_ids
|
||||
request.num_prompt_tokens = len(new_ids)
|
||||
request._all_token_ids.clear()
|
||||
|
||||
Reference in new issue
Block a user