[Feature]: Support pause / resume and sleep / wake for AR stages in AsyncOmni (#6084)
Signed-off-by: knlnguyen1802 <knlnguyen1802@gmail.com> Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
072bfc02dd
commit
d15b7ca3e1
12 files changed
+1024
-69
No files matched your search
@@ -50,6 +50,7 @@ from vllm_omni.engine.async_engine_utils import (
|
||||
)
|
||||
from vllm_omni.engine.messages import (
|
||||
AbortRequestMessage,
|
||||
AbortResultMessage,
|
||||
AddCompanionRequestMessage,
|
||||
CollectiveRPCRequestMessage,
|
||||
CollectiveRPCResultMessage,
|
||||
@@ -1736,14 +1737,51 @@ class AsyncOmniEngine:
|
||||
return self.stage_metadata[stage_id]
|
||||
|
||||
def abort(self, request_ids: list[str]) -> None:
|
||||
"""Send abort message to the Orchestrator."""
|
||||
"""Fire-and-forget abort: enqueue and return without waiting.
|
||||
|
||||
Prefer :meth:`abort_async` when the caller needs acknowledgment that
|
||||
stage aborts, binding release, and orchestrator request cleanup finished.
|
||||
"""
|
||||
if self.request_queue is None:
|
||||
raise RuntimeError("request_queue is not initialized")
|
||||
self.request_queue.sync_q.put(AbortRequestMessage(request_ids=request_ids))
|
||||
|
||||
async def abort_async(self, request_ids: list[str]) -> None:
|
||||
"""Async abort API."""
|
||||
self.abort(request_ids)
|
||||
async def abort_async(
|
||||
self,
|
||||
request_ids: list[str],
|
||||
timeout: float | None = None,
|
||||
) -> None:
|
||||
"""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.
|
||||
"""
|
||||
if self.request_queue is None:
|
||||
raise RuntimeError("request_queue is not initialized")
|
||||
transport = self._correlated_rpc_client
|
||||
if transport is None:
|
||||
raise RuntimeError("correlated RPC client is not initialized")
|
||||
|
||||
rpc_id = uuid.uuid4().hex
|
||||
msg = AbortRequestMessage(request_ids=request_ids, rpc_id=rpc_id)
|
||||
|
||||
def _wait() -> AbortResultMessage:
|
||||
result_msg = transport.execute(
|
||||
("abort", rpc_id),
|
||||
msg,
|
||||
timeout=timeout,
|
||||
timeout_message=f"abort timed out after {timeout} seconds",
|
||||
block_on_submit=True,
|
||||
)
|
||||
if not isinstance(result_msg, AbortResultMessage):
|
||||
raise RuntimeError(f"unexpected abort result type: {type(result_msg).__name__}")
|
||||
return result_msg
|
||||
|
||||
loop = asyncio.get_running_loop()
|
||||
result_msg = await loop.run_in_executor(None, _wait)
|
||||
if not result_msg.success:
|
||||
raise RuntimeError(result_msg.error or "abort failed")
|
||||
|
||||
def submit_interaction(
|
||||
self,
|
||||
|
||||
@@ -42,6 +42,20 @@ class AddCompanionRequestMessage(EngineQueueMessage, kw_only=True):
|
||||
class AbortRequestMessage(EngineQueueMessage, kw_only=True):
|
||||
type: Literal["abort"] = "abort"
|
||||
request_ids: list[str]
|
||||
# When set, Orchestrator emits AbortResultMessage on rpc_async_queue so
|
||||
# callers can await acknowledgment. Omit for fire-and-forget abort().
|
||||
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):
|
||||
|
||||
@@ -36,6 +36,7 @@ from vllm_omni.engine.cfg_companion_tracker import CfgCompanionTracker
|
||||
from vllm_omni.engine.membership_controller import MembershipController
|
||||
from vllm_omni.engine.messages import (
|
||||
AbortRequestMessage,
|
||||
AbortResultMessage,
|
||||
AddCompanionRequestMessage,
|
||||
CollectiveRPCRequestMessage,
|
||||
CollectiveRPCResultMessage,
|
||||
@@ -817,13 +818,35 @@ class Orchestrator:
|
||||
)
|
||||
|
||||
async def _handle_abort(self, msg: AbortRequestMessage) -> None:
|
||||
"""Handle an abort message from the main thread."""
|
||||
"""Handle an abort message from the main thread.
|
||||
|
||||
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.
|
||||
"""
|
||||
request_ids = msg.request_ids
|
||||
# _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)
|
||||
logger.info("[Orchestrator] Aborted request(s) %s", request_ids)
|
||||
error: str | None = None
|
||||
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)
|
||||
logger.info("[Orchestrator] Aborted request(s) %s", request_ids)
|
||||
except Exception as exc:
|
||||
error = str(exc)
|
||||
logger.exception("[Orchestrator] Abort failed for request(s) %s", request_ids)
|
||||
if msg.rpc_id is None:
|
||||
raise
|
||||
if msg.rpc_id is not None:
|
||||
# Always emit a result when rpc_id is set so CorrelatedRpcClient
|
||||
# waiters are unblocked even on failure.
|
||||
await self.rpc_async_queue.put(
|
||||
AbortResultMessage(
|
||||
rpc_id=msg.rpc_id,
|
||||
success=error is None,
|
||||
error=error,
|
||||
)
|
||||
)
|
||||
|
||||
async def _handle_interaction(self, msg: InteractionMessage) -> None:
|
||||
"""Handle a midway interaction for an active streaming diffusion request."""
|
||||
|
||||
@@ -94,6 +94,16 @@ class StagePool:
|
||||
|
||||
DISPATCH_WAIT_TIMEOUT_S: float = 10.0
|
||||
DISPATCH_RETRY_INTERVAL_S: float = 0.1
|
||||
# Only these EngineCore helpers may skip collective_rpc_async. A generic
|
||||
# ``{method}_async`` on AsyncMPClient must not silently drop timeout.
|
||||
_ENGINE_CORE_CONTROL_ASYNC_METHODS = frozenset(
|
||||
{
|
||||
"pause_scheduler",
|
||||
"resume_scheduler",
|
||||
"sleep",
|
||||
"wake_up",
|
||||
}
|
||||
)
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
@@ -1214,6 +1224,7 @@ class StagePool:
|
||||
kwargs: dict[str, Any] | None = None,
|
||||
) -> dict[str, Any] | Any:
|
||||
"""Dispatch a stage-scoped control-plane RPC to one physical route."""
|
||||
args = tuple(args or ())
|
||||
kwargs = dict(kwargs or {})
|
||||
client = self.clients[replica_id]
|
||||
if client is None:
|
||||
@@ -1222,6 +1233,14 @@ class StagePool:
|
||||
"error": f"stage {self.stage_id} replica {replica_id} is not attached",
|
||||
}
|
||||
try:
|
||||
if self.stage_type != "diffusion" and method in self._ENGINE_CORE_CONTROL_ASYNC_METHODS:
|
||||
client_method = getattr(client, f"{method}_async", None)
|
||||
if callable(client_method):
|
||||
result = client_method(*args, **kwargs)
|
||||
if timeout is not None:
|
||||
return await asyncio.wait_for(result, timeout=timeout)
|
||||
return await result
|
||||
|
||||
return await client.collective_rpc_async(
|
||||
method=method,
|
||||
timeout=timeout,
|
||||
|
||||
Reference in new issue
Block a user