[Bugfix] Fix colocate-async sleep admission race and deliver AR abort tokens (#6367)

Signed-off-by: knlnguyen1802 <knlnguyen1802@gmail.com>
Signed-off-by: Cursor <cursoragent@cursor.com>
Signed-off-by: Samit <285365963@qq.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Samit <285365963@qq.com>
This commit is contained in:
authored and GitHub committed 2026-08-29 09:11:39 +00:00
1 parent 5c47fd0bc8
commit bb5bf8fd0a
23 files changed
+1229 -157

No files matched your search

+7 -1
View File
@@ -67,6 +67,7 @@ from vllm_omni.engine.messages import (
EngineQueueMessage,
ErrorMessage,
InteractionMessage,
OutputMessage,
StageSubmissionMessage,
)
from vllm_omni.engine.orchestrator import Orchestrator
@@ -1920,12 +1921,16 @@ class AsyncOmniEngine:
self,
request_ids: list[str],
timeout: float | None = None,
) -> None:
) -> list[OutputMessage]:
"""Abort requests and wait for orchestrator acknowledgment.
Unlike :meth:`abort`, this generates an ``rpc_id``, correlates the
:class:`AbortResultMessage` via :class:`CorrelatedRpcClient`, and
raises if the orchestrator reports failure or times out.
Returns:
Final-stage AR abort ``OutputMessage`` list carrying partial
tokens generated before abort (empty for diffusion / no OP state).
"""
if not request_ids or getattr(self, "_shutdown_called", False):
return
@@ -1959,6 +1964,7 @@ class AsyncOmniEngine:
raise
if not result_msg.success:
raise RuntimeError(result_msg.error or "abort failed")
return list(result_msg.abort_outputs or [])
def submit_interaction(
self,
+14 -11
View File
@@ -48,17 +48,6 @@ class AbortRequestMessage(EngineQueueMessage, kw_only=True):
rpc_id: str | None = None
class AbortResultMessage(EngineQueueMessage, kw_only=True):
type: Literal["abort_result"] = "abort_result"
rpc_id: str
success: bool
error: str | None = None
@property
def rpc_correlation_key(self) -> tuple[str, str]:
return ("abort", self.rpc_id)
class InteractionMessage(EngineQueueMessage, kw_only=True):
type: Literal["interaction"] = "interaction"
request_id: str
@@ -113,6 +102,20 @@ class OutputMessage(EngineQueueMessage, kw_only=True):
stage_submit_ts: float | None = None
class AbortResultMessage(EngineQueueMessage, kw_only=True):
type: Literal["abort_result"] = "abort_result"
rpc_id: str
success: bool
error: str | None = None
# Final-stage AR abort outputs (partial tokens) for frontend delivery.
# Empty for diffusion / requests with no output-processor state.
abort_outputs: list[OutputMessage] | None = None
@property
def rpc_correlation_key(self) -> tuple[str, str]:
return ("abort", self.rpc_id)
class StageMetricsMessage(EngineQueueMessage, kw_only=True):
type: Literal["stage_metrics"] = "stage_metrics"
request_id: str
+63 -8
View File
@@ -871,14 +871,19 @@ class Orchestrator:
When ``msg.rpc_id`` is set, emit :class:`AbortResultMessage` after
stage aborts, binding release, and request cleanup complete so the
caller can await acknowledgment. Fire-and-forget aborts omit rpc_id.
AR final-stage abort outputs (partial tokens) are attached to the
result message when ``rpc_id`` is set, or enqueued on
``output_async_queue`` for fire-and-forget aborts.
"""
request_ids = msg.request_ids
error: str | None = None
abort_outputs: list[OutputMessage] = []
try:
# _cleanup_request_ids is CFG-aware: it expands aborted parents to
# their companions and fails a deferred parent whose companion is
# aborted before its output arrived.
await self._cleanup_request_ids(list(request_ids), abort=True)
abort_outputs = await self._cleanup_request_ids(list(request_ids), abort=True)
logger.info("[Orchestrator] Aborted request(s) %s", request_ids)
except Exception as exc:
error = str(exc)
@@ -893,8 +898,12 @@ class Orchestrator:
rpc_id=msg.rpc_id,
success=error is None,
error=error,
abort_outputs=abort_outputs or None,
)
)
elif abort_outputs:
for output_msg in abort_outputs:
await self.output_async_queue.put(output_msg)
async def _handle_interaction(self, msg: InteractionMessage) -> None:
"""Handle a midway interaction for an active streaming diffusion request."""
@@ -934,13 +943,53 @@ class Orchestrator:
)
)
async def _abort_request_ids(self, request_ids: list[str]) -> None:
"""Forward abort requests to all stage pools."""
async def _abort_request_ids(self, request_ids: list[str]) -> list[OutputMessage]:
"""Forward abort requests to all stage pools.
Collects final-stage AR abort outputs (partial tokens) while request
state is still available for stage-id filtering. Diffusion pools do
not contribute abort outputs.
"""
if not request_ids:
return
return []
abort_outputs: list[OutputMessage] = []
for pool in self.stage_pools:
await pool.abort_requests(request_ids)
stage_outputs = await pool.abort_requests(request_ids) or []
if bool(getattr(pool, "final_output", False)) and getattr(pool, "stage_type", None) != "diffusion":
final_output_type = getattr(pool.stage_client, "final_output_type", None) or "text"
for orch_req_id, request_output in stage_outputs:
req_state = self.request_states.get(orch_req_id)
if req_state is None:
continue
final_stage_ids = req_state.final_output_stage_ids or {req_state.final_stage_id}
if pool.stage_id not in final_stage_ids:
continue
engine_output = OmniRequestOutput.from_stage_output(
request_output,
request_id=orch_req_id,
finished=True,
stage_id=pool.stage_id,
replica_id=pool.get_bound_replica_id(orch_req_id),
final_output_type=final_output_type,
)
abort_outputs.append(
OutputMessage(
request_id=orch_req_id,
stage_id=pool.stage_id,
replica_id=pool.get_bound_replica_id(orch_req_id),
engine_outputs=engine_output,
metrics=None,
finished=False,
stage_submit_ts=req_state.stage_submit_ts.get(pool.stage_id),
)
)
pool.release_bindings(request_ids)
last_index_by_req: dict[str, int] = {}
for index, output_msg in enumerate(abort_outputs):
last_index_by_req[output_msg.request_id] = index
for index, output_msg in enumerate(abort_outputs):
output_msg.finished = index == last_index_by_req[output_msg.request_id]
return abort_outputs
def _release_request_bindings(self, request_ids: list[str]) -> None:
"""Release all stage-local route bindings for the given request ids."""
@@ -1688,7 +1737,7 @@ class Orchestrator:
*,
abort: bool = False,
close_duplex_sessions: bool = False,
) -> None:
) -> list[OutputMessage]:
"""Release pool bindings and logical request state for the given ids.
CFG-aware: cleaning a parent releases its tracker state and pulls its
@@ -1697,9 +1746,13 @@ class Orchestrator:
can never complete). Every teardown path (stage error, abort, replica
loss, membership unregister) funnels through here, so tracker state
cannot outlive its requests.
Returns:
Final-stage AR abort ``OutputMessage`` list when ``abort=True``;
otherwise an empty list.
"""
if not request_ids:
return
return []
cleanup_ids = list(dict.fromkeys(request_ids))
batch = set(cleanup_ids)
@@ -1741,9 +1794,10 @@ class Orchestrator:
cleanup_ids.extend(stale_request_ids)
cleanup_ids = list(dict.fromkeys(cleanup_ids))
abort_outputs: list[OutputMessage] = []
try:
if abort:
await self._abort_request_ids(cleanup_ids)
abort_outputs = await self._abort_request_ids(cleanup_ids)
self._release_request_bindings(cleanup_ids)
for request_id in cleanup_ids:
self._pd_kv_params.pop(request_id, None)
@@ -1759,6 +1813,7 @@ class Orchestrator:
raise
if closing_session_ids and self.duplex_control_plane is not None:
self.duplex_control_plane.finalize_closed_sessions(closing_session_ids)
return abort_outputs
async def _apply_raw_terminal_stage_finish(
self,
+54 -11
View File
@@ -1189,14 +1189,19 @@ class StagePool:
# ---- Stage-local control plane ----
async def abort_requests(self, request_ids: list[str]) -> None:
async def abort_requests(self, request_ids: list[str]) -> list[tuple[str, Any]]:
"""Abort the given requests in this stage pool.
Request-bound abort routing stays inside the pool because route affinity
(``request_id -> replica_id``) is pool-owned.
For AR stages, collect terminal abort ``RequestOutput`` objects from
output-processor state *before* EngineCore abort so partial tokens
generated so far are preserved. Diffusion stages return no abort
outputs (whole-sample retry remains the recovery path).
"""
if not request_ids:
return
return []
request_ids_by_replica: dict[int, list[str]] = {}
for request_id in request_ids:
@@ -1206,18 +1211,45 @@ class StagePool:
continue
request_ids_by_replica.setdefault(replica_id, []).append(request_id)
abort_outputs: list[tuple[str, Any]] = []
is_diffusion = self.stage_type == "diffusion"
for replica_id, replica_request_ids in request_ids_by_replica.items():
# Orchestrator ids are OP external ids; EngineCore may use a
# different internal request_id assigned by InputProcessor.
# Always key collected outputs by the orchestrator id we passed
# (internal=False), never by RequestOutput.request_id — some stages
# still surface EngineCore/internal ids and would drop the prefix.
engine_abort_ids = list(replica_request_ids)
if not is_diffusion and self._output_processor is not None:
collect = getattr(self._output_processor, "abort_requests_collecting_outputs", None)
if collect is not None:
engine_abort_ids = []
for orch_req_id in replica_request_ids:
collected_ids, stage_outputs = collect(
[orch_req_id],
internal=False,
commit_state=False,
)
for req_out in stage_outputs:
abort_outputs.append((orch_req_id, req_out))
if collected_ids:
engine_abort_ids.extend(collected_ids)
else:
engine_abort_ids.append(orch_req_id)
else:
aborted = self._output_processor.abort_requests(replica_request_ids, internal=False)
if aborted:
engine_abort_ids = list(aborted)
client = self.clients[replica_id]
if client is None:
continue
await client.abort_requests_async(replica_request_ids)
await client.abort_requests_async(engine_abort_ids)
if not is_diffusion and self._output_processor is not None:
commit = getattr(self._output_processor, "commit_aborted_request_state", None)
if callable(commit):
commit(replica_request_ids, internal=False)
# Clean up OutputProcessor state (e.g. mm_accumulated tensors) that
# would otherwise leak — aborted requests never produce a final
# EngineCoreOutput, so process_outputs() never fires its cleanup path.
all_aborted = [rid for ids in request_ids_by_replica.values() for rid in ids]
if all_aborted and self._output_processor is not None:
self._output_processor.abort_requests(all_aborted, internal=True)
return abort_outputs
async def collective_rpc(
self,
@@ -1227,7 +1259,12 @@ class StagePool:
args: tuple[Any, ...] = (),
kwargs: dict[str, Any] | None = None,
) -> dict[str, Any] | Any:
"""Dispatch a stage-scoped control-plane RPC to one physical route."""
"""Dispatch a stage-scoped control-plane RPC to one physical route.
EngineCore control methods (``pause_scheduler``, ``resume_scheduler``,
``sleep``, ``wake_up``) propagate worker exceptions. Capability probes
and other RPCs still return ``{"supported": False, "error": ...}``.
"""
args = tuple(args or ())
kwargs = dict(kwargs or {})
client = self.clients[replica_id]
@@ -1258,9 +1295,15 @@ class StagePool:
replica_id,
method,
)
if method in self._ENGINE_CORE_CONTROL_ASYNC_METHODS:
raise
if isinstance(exc, TimeoutError):
error = f"{type(exc).__name__}: {method} timed out after {timeout}s"
else:
error = str(exc) or repr(exc)
return {
"supported": False,
"error": str(exc),
"error": error,
}
def shutdown_replica(self, replica_id: int) -> None:
+272 -102
View File
@@ -17,7 +17,7 @@ from vllm import TokensPrompt
from vllm.engine.protocol import EngineClient, StreamingInput
from vllm.logger import init_logger
from vllm.lora.request import LoRARequest
from vllm.outputs import PoolingRequestOutput
from vllm.outputs import CompletionOutput, PoolingRequestOutput
from vllm.plugins.io_processors import get_io_processor
from vllm.pooling_params import PoolingParams
from vllm.renderers.inputs.preprocess import extract_prompt_components
@@ -150,12 +150,19 @@ class AsyncOmni(EngineClient, OmniBase):
OmniBase.__init__(self, model=model, **kwargs)
self._pause_cond: asyncio.Condition = asyncio.Condition()
self._paused: bool = False
# In-flight EngineCore submits (non-streaming add_request, or each
# streaming ADD/update/final marker). sleep() waits for this to hit
# zero so a pipelined request cannot race into EngineCore during
# drain/offload. Streaming generate does not hold a slot while
# waiting for the next client chunk.
self._admitting: int = 0
# True after pause_generation() or AR EngineCore sleep; wake_up must
# not reopen generate() until resume_generation(). Diffusion-only
# sleep uses _paused as a temporary admission gate and clears it
# on wake so sleep → wake → generate keeps working.
self._hold_admission_until_resume: bool = False
self._sleeping_tags: set[str] = set()
self._stage_sleeping_tags: dict[int, set[str]] = {}
self._level2_sleeping: bool = False
self._duplex_request_client: DuplexRequestClient | None = None
self.duplex_lifecycle_events: asyncio.Queue[DuplexSessionLifecycleMessage] = asyncio.Queue()
@@ -513,31 +520,40 @@ class AsyncOmni(EngineClient, OmniBase):
external_request_id = request_id
request_id = self._get_unique_request_id(external_request_id)
# Wait until generation is resumed if the engine is paused
# Wait until generation is resumed if the engine is paused. Non-streaming
# generate holds an admission slot until add_request completes so sleep()
# cannot race a just-unblocked generate into EngineCore during offload.
# Streaming generate does **not** hold the slot while waiting for the
# first client chunk; the input pump acquires it immediately before each
# EngineCore ADD/update.
streaming_input = isinstance(prompt, AsyncGenerator)
async with self._pause_cond:
await self._pause_cond.wait_for(lambda: not self._paused)
if not streaming_input:
self._admitting = getattr(self, "_admitting", 0) + 1
admitting = not streaming_input
logger.debug(f"[AsyncOmni] generate() called for request {external_request_id}")
_sleeping_tags = getattr(self, "_sleeping_tags", None)
if _sleeping_tags:
raise RuntimeError(
f"Generation rejected: Engine is partially or fully asleep. "
f"Currently sleeping tags: {list(_sleeping_tags)}. "
f"Please perform a full wake_up before generating."
)
# Reject diffusion list-prompt early with a clear API error.
if isinstance(prompt, list) and any(
getattr(client, "stage_type", "") == "diffusion" for client in getattr(self.engine, "stage_clients", [])
):
raise ValueError(
"Diffusion stages accept only a single prompt per request. "
"Submit multiple independent requests to use scheduler batching."
)
input_stream_task: asyncio.Task | None = None
try:
_sleeping_tags = getattr(self, "_sleeping_tags", None)
if _sleeping_tags:
raise RuntimeError(
f"Generation rejected: Engine is partially or fully asleep. "
f"Currently sleeping tags: {list(_sleeping_tags)}. "
f"Please perform a full wake_up before generating."
)
# Reject diffusion list-prompt early with a clear API error.
if isinstance(prompt, list) and any(
getattr(client, "stage_type", "") == "diffusion" for client in getattr(self.engine, "stage_clients", [])
):
raise ValueError(
"Diffusion stages accept only a single prompt per request. "
"Submit multiple independent requests to use scheduler batching."
)
# Start final output dispatcher on the first call to generate()
self._final_output_handler()
@@ -598,8 +614,11 @@ class AsyncOmni(EngineClient, OmniBase):
req_sp_list[p_id] = self._prepare_prefill_sampling_params(request_id, req_sp_list[p_id])
# Add request(s) to stage 0. For streaming inputs, submit
# chunks incrementally through streaming_update.
if isinstance(prompt, AsyncGenerator):
# chunks incrementally through streaming_update. The helper
# returns as soon as the pump task is created; each ADD/update
# takes its own admission slot inside the pump.
if streaming_input:
first_chunk_submitted = asyncio.get_running_loop().create_future()
input_stream_task = await self._add_streaming_input_request(
request_id=request_id,
input_stream=prompt,
@@ -608,7 +627,9 @@ class AsyncOmni(EngineClient, OmniBase):
final_output_stage_ids=final_output_stage_ids,
arrival_time=wall_start_ts,
lora_request=lora_request,
first_chunk_submitted=first_chunk_submitted,
)
await first_chunk_submitted
else:
await self.engine.add_request_async(
request_id=request_id,
@@ -622,6 +643,9 @@ class AsyncOmni(EngineClient, OmniBase):
submit_ts = time.time()
req_state.metrics.stage_first_ts[0] = submit_ts
req_start_ts[request_id] = submit_ts
if admitting:
await self._release_generate_admission()
admitting = False
# Refresh gauges on arrival.
self._publish_request_gauges(len(self.request_states))
@@ -640,18 +664,7 @@ class AsyncOmni(EngineClient, OmniBase):
logger.debug(f"[AsyncOmni] Request {request_id} completed")
# The input pump can outlive a normally-completed generation
# (e.g. a realtime client that keeps streaming after the final
# output); a live pump keeps issuing streaming updates for a
# request the orchestrator no longer tracks.
if input_stream_task is not None and not input_stream_task.done():
input_stream_task.cancel()
self._log_summary_and_cleanup(request_id)
except (asyncio.CancelledError, GeneratorExit):
if input_stream_task is not None and not input_stream_task.done():
input_stream_task.cancel()
self._record_request_failure_once(request_id, reason="client_disconnect")
await self._abort_internal_requests(request_id)
logger.info(f"[AsyncOmni] Request {request_id} aborted.")
@@ -661,6 +674,28 @@ class AsyncOmni(EngineClient, OmniBase):
await self._abort_internal_requests(request_id)
logger.info(f"[AsyncOmni] Request {request_id} failed (input error): {e}")
raise
finally:
if input_stream_task is not None and not input_stream_task.done():
input_stream_task.cancel()
if admitting:
await self._release_generate_admission()
self._log_summary_and_cleanup(request_id)
async def _release_generate_admission(self) -> None:
"""Drop one in-flight generate admission slot held across add_request."""
async with self._pause_cond:
self._admitting = max(getattr(self, "_admitting", 1) - 1, 0)
self._pause_cond.notify_all()
async def _submit_with_admission(self, awaitable):
"""Wait for resume, hold one admission slot for a single EngineCore submit."""
async with self._pause_cond:
await self._pause_cond.wait_for(lambda: not self._paused)
self._admitting = getattr(self, "_admitting", 0) + 1
try:
return await awaitable
finally:
await self._release_generate_admission()
async def _add_streaming_input_request(
self,
@@ -672,6 +707,7 @@ class AsyncOmni(EngineClient, OmniBase):
final_output_stage_ids: Sequence[int],
arrival_time: float,
lora_request: Any = None,
first_chunk_submitted: asyncio.Future[None] | None = None,
) -> asyncio.Task:
"""Submit a streaming input generator as incremental stage-0 updates."""
if not sampling_params_list:
@@ -688,6 +724,10 @@ class AsyncOmni(EngineClient, OmniBase):
stage0_params = stage0_params.clone()
stage0_params.skip_clone = True
def _mark_first_chunk_submitted() -> None:
if first_chunk_submitted is not None and not first_chunk_submitted.done():
first_chunk_submitted.set_result(None)
async def handle_inputs() -> None:
nonlocal has_submitted_first_chunk
cancelled = False
@@ -701,29 +741,34 @@ class AsyncOmni(EngineClient, OmniBase):
prompt_text, _, _ = extract_prompt_components(self.model_config, chunk_prompt)
if not has_submitted_first_chunk:
await self.engine.add_request_async(
request_id=request_id,
prompt=chunk_prompt,
prompt_text=prompt_text,
sampling_params_list=chunk_sampling_params_list,
final_stage_id=final_stage_id,
final_output_stage_ids=final_output_stage_ids,
arrival_time=arrival_time,
lora_request=lora_request,
resumable=True,
await self._submit_with_admission(
self.engine.add_request_async(
request_id=request_id,
prompt=chunk_prompt,
prompt_text=prompt_text,
sampling_params_list=chunk_sampling_params_list,
final_stage_id=final_stage_id,
final_output_stage_ids=final_output_stage_ids,
arrival_time=arrival_time,
lora_request=lora_request,
resumable=True,
)
)
has_submitted_first_chunk = True
_mark_first_chunk_submitted()
else:
await self.engine.add_streaming_update_async(
request_id=request_id,
prompt=chunk_prompt,
prompt_text=prompt_text,
sampling_params_list=chunk_sampling_params_list,
final_stage_id=final_stage_id,
final_output_stage_ids=final_output_stage_ids,
arrival_time=arrival_time,
lora_request=lora_request,
resumable=True,
await self._submit_with_admission(
self.engine.add_streaming_update_async(
request_id=request_id,
prompt=chunk_prompt,
prompt_text=prompt_text,
sampling_params_list=chunk_sampling_params_list,
final_stage_id=final_stage_id,
final_output_stage_ids=final_output_stage_ids,
arrival_time=arrival_time,
lora_request=lora_request,
resumable=True,
)
)
except (asyncio.CancelledError, GeneratorExit):
cancelled = True
@@ -738,37 +783,47 @@ class AsyncOmni(EngineClient, OmniBase):
)
)
finally:
if not cancelled:
# Send empty final request to indicate that inputs have
# finished. Don't send if canceled (session was aborted).
final_sampling_params_list = list(sampling_params_list)
final_sampling_params_list[0] = stage0_params
final_prompt = TokensPrompt(prompt_token_ids=[0])
try:
if not cancelled:
# Send empty final request to indicate that inputs have
# finished. Don't send if canceled (session was aborted).
final_sampling_params_list = list(sampling_params_list)
final_sampling_params_list[0] = stage0_params
final_prompt = TokensPrompt(prompt_token_ids=[0])
if has_submitted_first_chunk:
await self.engine.add_streaming_update_async(
request_id=request_id,
prompt=final_prompt,
prompt_text=None,
sampling_params_list=final_sampling_params_list,
final_stage_id=final_stage_id,
final_output_stage_ids=final_output_stage_ids,
arrival_time=arrival_time,
lora_request=lora_request,
resumable=False,
)
else:
await self.engine.add_request_async(
request_id=request_id,
prompt=final_prompt,
prompt_text=None,
sampling_params_list=final_sampling_params_list,
final_stage_id=final_stage_id,
final_output_stage_ids=final_output_stage_ids,
arrival_time=arrival_time,
lora_request=lora_request,
resumable=False,
)
if has_submitted_first_chunk:
await self._submit_with_admission(
self.engine.add_streaming_update_async(
request_id=request_id,
prompt=final_prompt,
prompt_text=None,
sampling_params_list=final_sampling_params_list,
final_stage_id=final_stage_id,
final_output_stage_ids=final_output_stage_ids,
arrival_time=arrival_time,
lora_request=lora_request,
resumable=False,
)
)
else:
await self._submit_with_admission(
self.engine.add_request_async(
request_id=request_id,
prompt=final_prompt,
prompt_text=None,
sampling_params_list=final_sampling_params_list,
final_stage_id=final_stage_id,
final_output_stage_ids=final_output_stage_ids,
arrival_time=arrival_time,
lora_request=lora_request,
resumable=False,
)
)
has_submitted_first_chunk = True
finally:
# Unblock generate() even on cancel / empty stream / submit
# failure so it can observe a terminal abort or empty result.
_mark_first_chunk_submitted()
input_stream_task = asyncio.create_task(handle_inputs())
req_state.input_stream_task = input_stream_task
@@ -1129,22 +1184,76 @@ class AsyncOmni(EngineClient, OmniBase):
await self._abort(internal_req_ids)
async def _abort(self, request_ids: list[str]) -> None:
"""Abort request IDs via the engine and clean frontend state after ack.
"""Abort request IDs via the engine and enqueue terminal abort outputs.
Waits for orchestrator abort acknowledgment before popping
``request_states`` so generate() cleanup stays consistent with
backend binding/request teardown. Orchestrator abort errors propagate.
Waits for orchestrator abort acknowledgment, enqueues any AR terminal
abort outputs (partial tokens) into each request's asyncio queue, then
cancels the input pump. Frontend ``request_states`` stay registered so
``generate()`` can consume the terminal message in
``_process_orchestrator_results`` and run normal cleanup.
When ``abort_async`` returns no output for an active request (OP not
registered yet, unbound replica, or orchestrator id drop), enqueue a
synthetic finished abort so ``generate()`` cannot hang on ``queue.get``.
"""
await self.engine.abort_async(request_ids)
abort_outputs = await self.engine.abort_async(request_ids) or []
delivered: set[str] = set()
for output_msg in abort_outputs:
req_id = getattr(output_msg, "request_id", None)
if req_id is None:
continue
state = self.request_states.get(req_id)
if state is None:
logger.debug("[AsyncOmni] Dropping abort output for unknown req %s", req_id)
continue
await state.queue.put(output_msg)
delivered.add(req_id)
for rid in request_ids:
state = self.request_states.get(rid)
if state is not None and rid not in delivered:
queue = getattr(state, "queue", None)
if queue is not None:
await state.queue.put(self._synthetic_abort_output_message(rid))
delivered.add(rid)
for rid in request_ids:
self._record_request_failure_once(rid, reason="client_abort")
state = self.request_states.pop(rid, None)
state = self.request_states.get(rid)
input_stream_task = getattr(state, "input_stream_task", None)
if input_stream_task is not None and not input_stream_task.done():
input_stream_task.cancel()
if self.log_stats:
logger.info("[AsyncOmni] Aborted request(s) %s", ",".join(request_ids))
@staticmethod
def _synthetic_abort_output_message(request_id: str) -> OutputMessage:
"""Terminal abort OutputMessage used when the engine returned none."""
engine_output = OmniRequestOutput(
request_id=request_id,
finished=True,
stage_id=0,
final_output_type="text",
outputs=[
CompletionOutput(
index=0,
text="",
token_ids=[],
cumulative_logprob=None,
logprobs=None,
finish_reason="abort",
stop_reason=None,
)
],
)
return OutputMessage(
request_id=request_id,
stage_id=0,
replica_id=None,
engine_outputs=engine_output,
metrics=None,
finished=True,
stage_submit_ts=None,
)
def _split_stage_ids_by_type(self, stage_ids: list[int] | None = None) -> tuple[list[int], list[int]]:
"""Split stage ids into AR/LLM (EngineCore) vs diffusion (worker RPC)."""
n_stages = len(self.engine.stage_clients)
@@ -1168,6 +1277,47 @@ class AsyncOmni(EngineClient, OmniBase):
ar_stage_ids.append(sid)
return ar_stage_ids, diffusion_stage_ids
def _sleeping_tags_for_stages(self, stage_ids: list[int]) -> set[str]:
"""Union of sleeping tags recorded for the given stages."""
per_stage = getattr(self, "_stage_sleeping_tags", None) or {}
tags: set[str] = set()
for sid in stage_ids:
tags.update(per_stage.get(sid, set()))
return tags
def _refresh_union_sleeping_tags(self) -> None:
"""Keep ``_sleeping_tags`` as the engine-wide union of per-stage tags."""
per_stage = getattr(self, "_stage_sleeping_tags", None) or {}
union: set[str] = set()
for stage_tags in per_stage.values():
union.update(stage_tags)
self._sleeping_tags = union
def _record_stage_sleep(self, stage_ids: list[int], tags: Iterable[str]) -> None:
per_stage = getattr(self, "_stage_sleeping_tags", None)
if per_stage is None:
per_stage = {}
self._stage_sleeping_tags = per_stage
tag_set = set(tags)
for sid in stage_ids:
per_stage.setdefault(sid, set()).update(tag_set)
self._refresh_union_sleeping_tags()
def _clear_stage_sleep(self, stage_ids: list[int], tags: Iterable[str]) -> None:
per_stage = getattr(self, "_stage_sleeping_tags", None)
if per_stage is None:
self._sleeping_tags = set()
return
tag_set = set(tags)
for sid in stage_ids:
remaining = per_stage.get(sid)
if remaining is None:
continue
remaining.difference_update(tag_set)
if not remaining:
per_stage.pop(sid, None)
self._refresh_union_sleeping_tags()
async def pause_generation(
self,
*,
@@ -1266,11 +1416,24 @@ class AsyncOmni(EngineClient, OmniBase):
return await self.collective_rpc(method="profile", args=(False, None), stage_ids=stages)
async def reset_mm_cache(self) -> None:
"""Reset the multi-modal cache for all stages.
"""Reset the frontend (P0) multimodal processor cache.
TODO: Forward to Orchestrator process via message.
``EngineCore.sleep(level>=1)`` already clears the P1 receiver cache.
Clearing P0 avoids hash-only follow-up requests after that reset.
"""
logger.warning("[AsyncOmni] reset_mm_cache not yet supported with Orchestrator process")
processor = getattr(self, "input_processor", None)
if processor is None:
processor = getattr(self.engine, "input_processor", None)
cache = getattr(processor, "mm_processor_cache", None)
if cache is None:
logger.debug("[AsyncOmni] reset_mm_cache: no frontend mm_processor_cache")
return
for name in ("clear", "reset", "clear_cache"):
fn = getattr(cache, name, None)
if callable(fn):
fn()
return
logger.debug("[AsyncOmni] reset_mm_cache: cache has no clear/reset method")
async def reset_encoder_cache(self) -> None:
"""Reset the encoder cache for all stages.
@@ -1314,10 +1477,15 @@ class AsyncOmni(EngineClient, OmniBase):
admission and ``sleep → wake → generate`` keeps working.
"""
# Block admission before any sleep RPC so generate() waits on
# _pause_cond during the drain/offload window. EngineCore.sleep will
# pause the AR scheduler itself; avoid a second pause_scheduler here.
# _pause_cond during the drain/offload window. Wait until generate()
# coroutines that already passed the pause check have submitted (or
# failed) so EngineCore does not see ADD frames while sleeping.
async with self._pause_cond:
self._paused = True
await self._pause_cond.wait_for(lambda: getattr(self, "_admitting", 0) == 0)
# P0 sender cache must drop hashes before EngineCore.sleep clears P1.
await self.reset_mm_cache()
self._final_output_handler()
ar_stage_ids, diffusion_stage_ids = self._split_stage_ids_by_type(stage_ids)
@@ -1353,9 +1521,10 @@ class AsyncOmni(EngineClient, OmniBase):
if diffusion_stage_ids:
final_acks.extend(await self._sleep_diffusion(diffusion_stage_ids, level))
if not hasattr(self, "_sleeping_tags"):
self._sleeping_tags = set()
self._sleeping_tags.update([CuMemTag.WEIGHTS.value, CuMemTag.KV_CACHE.value])
self._record_stage_sleep(
ar_stage_ids + diffusion_stage_ids,
[CuMemTag.WEIGHTS.value, CuMemTag.KV_CACHE.value],
)
if level == 2:
self._level2_sleeping = True
return final_acks
@@ -1399,7 +1568,12 @@ class AsyncOmni(EngineClient, OmniBase):
"Use sleep(level=1) instead, which offloads weights to CPU RAM "
"and supports fast DMA restore."
)
_current_tags = getattr(self, "_sleeping_tags", set())
ar_stage_ids, diffusion_stage_ids = self._split_stage_ids_by_type(stage_ids)
target_stage_ids = ar_stage_ids + diffusion_stage_ids
_current_tags = self._sleeping_tags_for_stages(target_stage_ids)
per_stage = getattr(self, "_stage_sleeping_tags", None) or {}
if not _current_tags and not per_stage:
_current_tags = set(getattr(self, "_sleeping_tags", set()))
if tags is None:
requested_tags = list(_current_tags)
else:
@@ -1408,8 +1582,6 @@ class AsyncOmni(EngineClient, OmniBase):
logger.info(f"[{self._name}] Requested tags {tags} are already warm. Skipping wake_up.")
return []
ar_stage_ids, diffusion_stage_ids = self._split_stage_ids_by_type(stage_ids)
final_acks: list[OmniACK] = []
if ar_stage_ids:
logger.info("[%s] Waking AR stage(s) %s via EngineCore", self._name, ar_stage_ids)
@@ -1433,9 +1605,7 @@ class AsyncOmni(EngineClient, OmniBase):
if diffusion_stage_ids:
final_acks.extend(await self._wake_diffusion(diffusion_stage_ids, requested_tags))
for t in requested_tags:
if hasattr(self, "_sleeping_tags"):
self._sleeping_tags.discard(t)
self._clear_stage_sleep(target_stage_ids, requested_tags)
# Only clear the level-2 flag once all tags are warm, in case partial
# wake support (e.g. tags=["kv_cache"] only) is added in the future.
if not getattr(self, "_sleeping_tags", None):
+14 -7
View File
@@ -10,19 +10,26 @@ from vllm_omni.platforms import current_omni_platform
logger = logging.getLogger(__name__)
# Default for ``visible_baseline``: read the live device-control env var.
# Explicit ``None`` means the caller captured an unset env and must not fall
# back to a later thread's temporary CUDA_VISIBLE_DEVICES.
_LIVE_DEVICE_ENV = object()
def resolve_stage_physical_devices(
stage_id: int,
devices: str | int | None,
*,
visible_baseline: str | None = None,
visible_baseline: str | None | object = _LIVE_DEVICE_ENV,
) -> str | None:
"""Map logical stage devices to physical IDs without mutating process env.
When ``visible_baseline`` is provided it is used for logical-to-physical
mapping instead of the current device-control env var. This keeps parallel
stage initialization correct even if another thread has temporarily
narrowed ``CUDA_VISIBLE_DEVICES`` for a different stage.
``visible_baseline`` is the device-control env captured at the start of
replica init. Pass the captured string, or ``None`` when that env was
unset. Omitting the argument reads the live env (single-threaded callers).
Parallel stage init must pass the captured value: another thread may have
already narrowed ``CUDA_VISIBLE_DEVICES`` for a different stage.
"""
if devices in (None, "cpu"):
return None
@@ -32,7 +39,7 @@ def resolve_stage_physical_devices(
device_list = _parse_device_list(devices)
env_var = current_omni_platform.device_control_env_var
visible_devices = visible_baseline if visible_baseline is not None else os.environ.get(env_var)
visible_devices = os.environ.get(env_var) if visible_baseline is _LIVE_DEVICE_ENV else visible_baseline
if visible_devices is not None:
visible_device_list = _parse_device_list(visible_devices)
device_list = _map_device_list(stage_id, device_list, visible_device_list)
@@ -43,7 +50,7 @@ def set_stage_devices(
stage_id: int,
devices: str | int | None,
*,
visible_baseline: str | None = None,
visible_baseline: str | None | object = _LIVE_DEVICE_ENV,
) -> str | None:
"""Configure per-stage device visibility and current device (CUDA or NPU).
+142 -1
View File
@@ -1,6 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
from collections.abc import Iterable
from dataclasses import fields as dataclass_fields
from typing import Any
@@ -432,6 +433,116 @@ class MultimodalOutputProcessor(VLLMOutputProcessor):
return self._native_text_metrics_by_request.pop(request_id, {})
def abort_requests(self, request_ids, internal: bool) -> list[str]:
aborted_ids, _outputs = self.abort_requests_collecting_outputs(request_ids, internal=internal)
return aborted_ids
def abort_requests_collecting_outputs(
self,
request_ids: Iterable[str],
*,
internal: bool,
commit_state: bool = True,
) -> tuple[list[str], list[RequestOutput | PoolingRequestOutput]]:
"""Abort requests and return terminal abort outputs with partial tokens.
Mirrors upstream ``OutputProcessor.abort_requests``, but also returns
abort ``RequestOutput`` objects when ``queue`` is ``None`` (Omni stage
pools register OP state without a collector queue).
Terminal abort outputs use ``RequestOutputKind.CUMULATIVE`` so DELTA
streaming requests still surface the full prefix generated so far.
``new_token_ids`` is the detokenizer prefix: Omni's
``make_request_output`` writes that list onto ``CompletionOutput.token_ids``.
When ``commit_state`` is False, processor mappings stay in place so a
failed physical EngineCore abort can retry with the same prefix.
"""
request_ids = list(request_ids)
if commit_state:
for request_id in request_ids:
if internal:
req_state = self.request_states.get(request_id)
if req_state is not None:
self._native_text_metrics_by_request.pop(req_state.external_req_id, None)
else:
self._native_text_metrics_by_request.pop(request_id, None)
internal_req_ids: list[str] = []
for request_id in request_ids:
if internal:
internal_req_ids.append(request_id)
if commit_state:
if req_state := self.request_states.get(request_id):
external_req_id = req_state.external_req_id
internal_ids = self.external_req_ids.get(external_req_id)
if internal_ids is not None:
try:
internal_ids.remove(request_id)
except ValueError:
pass
if not internal_ids:
self.external_req_ids.pop(external_req_id, None)
elif commit_state:
if internal_ids := self.external_req_ids.pop(request_id, []):
internal_req_ids.extend(internal_ids)
else:
internal_req_ids.extend(self.external_req_ids.get(request_id, []))
request_ids_to_abort: list[str] = []
abort_outputs: list[RequestOutput | PoolingRequestOutput] = []
for request_id in internal_req_ids:
req_state = (
self.request_states.pop(request_id, None) if commit_state else self.request_states.get(request_id)
)
if req_state is not None:
if commit_state:
self.lora_states.request_finished(request_id, req_state.lora_name)
request_ids_to_abort.append(request_id)
original_kind = req_state.output_kind
req_state.output_kind = RequestOutputKind.CUMULATIVE
detok = req_state.detokenizer
new_token_ids = list(detok.output_token_ids) if detok is not None else []
saved_children = None
if not commit_state and req_state.parent_req is not None:
saved_children = set(req_state.parent_req.child_requests)
try:
request_output = req_state.make_request_output(
new_token_ids=new_token_ids,
pooling_output=None,
finish_reason=FinishReason.ABORT,
stop_reason=None,
kv_transfer_params=None,
)
finally:
req_state.output_kind = original_kind
if saved_children is not None and req_state.parent_req is not None:
req_state.parent_req.child_requests = saved_children
if request_output is not None:
abort_outputs.append(request_output)
if commit_state and req_state.queue is not None:
req_state.queue.put(request_output)
if commit_state:
parent_req = req_state.parent_req
if parent_req is not None:
parent_req.child_requests.discard(request_id)
if not parent_req.child_requests:
self.parent_requests.pop(parent_req.request_id, None)
elif parent := self.parent_requests.get(request_id):
if parent.child_requests:
child_reqs = list(parent.child_requests)
child_aborted, child_outputs = self.abort_requests_collecting_outputs(
child_reqs,
internal=True,
commit_state=commit_state,
)
request_ids_to_abort.extend(child_aborted)
abort_outputs.extend(child_outputs)
if commit_state:
self.parent_requests.pop(request_id, None)
return request_ids_to_abort, abort_outputs
def commit_aborted_request_state(self, request_ids: Iterable[str], *, internal: bool) -> None:
"""Drop processor mappings after a successful physical EngineCore abort."""
request_ids = list(request_ids)
for request_id in request_ids:
if internal:
@@ -440,7 +551,37 @@ class MultimodalOutputProcessor(VLLMOutputProcessor):
self._native_text_metrics_by_request.pop(req_state.external_req_id, None)
else:
self._native_text_metrics_by_request.pop(request_id, None)
return super().abort_requests(request_ids, internal)
internal_req_ids: list[str] = []
for request_id in request_ids:
if internal:
internal_req_ids.append(request_id)
if req_state := self.request_states.get(request_id):
external_req_id = req_state.external_req_id
internal_ids = self.external_req_ids.get(external_req_id)
if internal_ids is not None:
try:
internal_ids.remove(request_id)
except ValueError:
pass
if not internal_ids:
self.external_req_ids.pop(external_req_id, None)
elif internal_ids := self.external_req_ids.pop(request_id, []):
internal_req_ids.extend(internal_ids)
for request_id in internal_req_ids:
req_state = self.request_states.pop(request_id, None)
if req_state is not None:
self.lora_states.request_finished(request_id, req_state.lora_name)
parent_req = req_state.parent_req
if parent_req is not None:
parent_req.child_requests.discard(request_id)
if not parent_req.child_requests:
self.parent_requests.pop(parent_req.request_id, None)
elif parent := self.parent_requests.get(request_id):
if parent.child_requests:
self.commit_aborted_request_state(list(parent.child_requests), internal=True)
self.parent_requests.pop(request_id, None)
def add_request(
self,
+9 -1
View File
@@ -201,11 +201,19 @@ class OmniGPUWorkerBase(GPUWorker):
"""
from vllm.device_allocator.cumem import CuMemAllocator
# Drain in-flight kernels before CuMem unmap. Abort/decode can still
# have GPU work after the scheduler reports idle; unmapping then
# returns CUDA_ERROR_INVALID_VALUE (cudaErrorInvalidValue).
current_omni_platform.synchronize()
gc.collect()
mem_before = current_omni_platform.get_current_memory_usage(self.device)
offload_tags = ("weights",) if level == 1 else tuple()
allocator = CuMemAllocator.get_instance()
allocator.sleep(offload_tags=offload_tags)
current_omni_platform.empty_cache()
# allocator.sleep already gc.collects and empty_cache()s. A second
# empty_cache on the pluggable allocator is a known CUDA invalid
# argument (pytorch/pytorch#145168). Only sync for the readout.
current_omni_platform.synchronize()
mem_after = current_omni_platform.get_current_memory_usage(self.device)
freed = max(0, mem_before - mem_after)