Merge remote-tracking branch 'origin/main' into qwen-image-2.1
# Conflicts: # vllm_omni/diffusion/executor/multiproc_executor.py # vllm_omni/diffusion/offloader/sequential_backend.py
This commit is contained in:
commit
9174554e40
1332 files changed
+160051
-60504
No files matched your search
@@ -1,13 +1,19 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from collections.abc import Callable
|
||||
from dataclasses import replace
|
||||
from typing import TYPE_CHECKING, Any
|
||||
|
||||
from vllm.utils.import_utils import resolve_obj_by_qualname
|
||||
from vllm.v1.kv_cache_interface import KVCacheConfig, KVCacheSpec
|
||||
from vllm.v1.outputs import KVConnectorOutput
|
||||
|
||||
from vllm_omni.diffusion.data import OmniDiffusionConfig
|
||||
from vllm_omni.diffusion.sched.interface import CachedRequestData
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from vllm_omni.diffusion.request import OmniDiffusionRequest
|
||||
@@ -159,7 +165,7 @@ class DiffusionExecutor(ABC):
|
||||
# ranks are not silently dropped.
|
||||
self.collective_rpc("set_kv_cache_configs", args=(kv_cache_configs, resolved_max_model_len))
|
||||
|
||||
def remove_diffusion_kv_requests(self, request_ids: list[str]) -> None:
|
||||
def remove_diffusion_kv_requests(self, request_ids: list[str | tuple[str, int]]) -> None:
|
||||
"""Clear request rows on every Worker after Scheduler retirement."""
|
||||
|
||||
unique_request_ids = list(dict.fromkeys(request_ids))
|
||||
@@ -170,6 +176,35 @@ class DiffusionExecutor(ABC):
|
||||
args=(unique_request_ids,),
|
||||
)
|
||||
|
||||
def prepare_kv_for_forward(self, scheduler_output: DiffusionSchedulerOutput) -> KVConnectorOutput | None:
|
||||
if scheduler_output.kv_connector_metadata is None:
|
||||
return
|
||||
transfer_output = replace(
|
||||
scheduler_output,
|
||||
scheduled_new_reqs=[],
|
||||
scheduled_cached_reqs=CachedRequestData.make_empty(),
|
||||
kv_prefetch_job=None,
|
||||
)
|
||||
outputs: list[KVConnectorOutput] = self.collective_rpc(
|
||||
"prepare_kv_for_forward",
|
||||
args=(transfer_output,),
|
||||
unique_reply_rank=0,
|
||||
exec_all_ranks=True,
|
||||
)
|
||||
if len(outputs) != self.od_config.num_gpus or any(output.invalid_block_ids for output in outputs):
|
||||
# Missing ranks / invalid pages cannot establish safe ownership.
|
||||
raise RuntimeError("Diffusion KV receive failed on one or more ranks")
|
||||
completed = getattr(self, "_kv_receive_completed_ranks", {})
|
||||
for rank, output in enumerate(outputs):
|
||||
for request_id in output.finished_recving or ():
|
||||
completed.setdefault(request_id, set()).add(rank)
|
||||
finished = {request_id for request_id, ranks in completed.items() if len(ranks) == len(outputs)}
|
||||
for request_id in finished:
|
||||
del completed[request_id]
|
||||
self._kv_receive_completed_ranks = completed
|
||||
outputs[0].finished_recving = finished
|
||||
return outputs[0]
|
||||
|
||||
@abstractmethod
|
||||
def shutdown(self) -> None:
|
||||
"""Shutdown the executor and release resources."""
|
||||
|
||||
@@ -13,7 +13,7 @@ import threading
|
||||
import time
|
||||
import weakref
|
||||
from collections.abc import Callable
|
||||
from dataclasses import dataclass
|
||||
from dataclasses import dataclass, field
|
||||
from multiprocessing.process import BaseProcess
|
||||
from multiprocessing.synchronize import Event
|
||||
from typing import TYPE_CHECKING, Any, cast
|
||||
@@ -46,6 +46,7 @@ _DEQUEUE_TIMEOUT_S = 5.0
|
||||
_DLO_DP_WAVE_TIMEOUT_S = float(os.environ.get("VLLM_OMNI_DLO_DP_WAVE_TIMEOUT", 600.0))
|
||||
_WORKER_SHUTDOWN_GRACE_S = 15.0
|
||||
_WORKER_TERMINATE_GRACE_S = 5.0
|
||||
_WORKER_KILL_GRACE_S = 5.0
|
||||
_RESULT_PUMP_JOIN_TIMEOUT_S = 2.0
|
||||
|
||||
|
||||
@@ -83,34 +84,62 @@ class _ExecutorShutdownCleaner:
|
||||
|
||||
broadcast_mq: MessageQueue | None = None
|
||||
num_workers: int = 0
|
||||
processes: list[BaseProcess] | None = None
|
||||
processes: list[mp.Process] | None = None
|
||||
_lock: threading.Lock = field(default_factory=threading.Lock, init=False, repr=False)
|
||||
|
||||
def __call__(self) -> None:
|
||||
"""Clean up background resources."""
|
||||
# The worker monitor and an explicit shutdown may race. A retry must
|
||||
# not signal/join the same Process objects while cleanup is in flight.
|
||||
if not self._lock.acquire(blocking=False):
|
||||
return
|
||||
try:
|
||||
self._cleanup()
|
||||
finally:
|
||||
self._lock.release()
|
||||
|
||||
def _cleanup(self) -> None:
|
||||
if self.broadcast_mq is not None:
|
||||
try:
|
||||
for _ in range(self.num_workers):
|
||||
self.broadcast_mq.enqueue(SHUTDOWN_MESSAGE, timeout=1.0)
|
||||
|
||||
self.broadcast_mq = None
|
||||
except Exception as exc:
|
||||
logger.warning("Failed to send shutdown signal: %s", exc)
|
||||
finally:
|
||||
self.broadcast_mq = None
|
||||
|
||||
if self.processes:
|
||||
join_deadline = time.monotonic() + _WORKER_SHUTDOWN_GRACE_S
|
||||
for proc in self.processes:
|
||||
if not proc.is_alive():
|
||||
continue
|
||||
proc.join(max(0.0, join_deadline - time.monotonic()))
|
||||
|
||||
alive = [proc for proc in self.processes if proc.is_alive()]
|
||||
for proc in alive:
|
||||
logger.warning("Terminating diffusion worker %s after timeout", proc.name)
|
||||
proc.terminate()
|
||||
for action, grace in (
|
||||
(None, _WORKER_SHUTDOWN_GRACE_S),
|
||||
("terminate", _WORKER_TERMINATE_GRACE_S),
|
||||
("kill", _WORKER_KILL_GRACE_S),
|
||||
):
|
||||
if not alive:
|
||||
break
|
||||
if action is not None:
|
||||
for proc in alive:
|
||||
try:
|
||||
logger.warning("Calling %s on diffusion worker %s (pid=%s)", action, proc.name, proc.pid)
|
||||
getattr(proc, action)()
|
||||
except OSError:
|
||||
logger.exception("Failed to %s diffusion worker %s (pid=%s)", action, proc.name, proc.pid)
|
||||
|
||||
terminate_deadline = time.monotonic() + _WORKER_TERMINATE_GRACE_S
|
||||
for proc in alive:
|
||||
proc.join(max(0.0, terminate_deadline - time.monotonic()))
|
||||
deadline = time.monotonic() + grace
|
||||
for proc in alive:
|
||||
try:
|
||||
proc.join(max(0.0, deadline - time.monotonic()))
|
||||
except OSError:
|
||||
logger.exception("Failed to join diffusion worker %s (pid=%s)", proc.name, proc.pid)
|
||||
alive = [proc for proc in alive if proc.is_alive()]
|
||||
|
||||
self.processes = alive
|
||||
if alive:
|
||||
logger.error(
|
||||
"Diffusion worker cleanup incomplete after kill: %s; retaining processes for shutdown retry",
|
||||
[(proc.name, proc.pid) for proc in alive],
|
||||
)
|
||||
|
||||
|
||||
class MultiprocDiffusionExecutor(DiffusionExecutor):
|
||||
@@ -1010,8 +1039,12 @@ class MultiprocDiffusionExecutor(DiffusionExecutor):
|
||||
def shutdown(self) -> None:
|
||||
self._closed = True
|
||||
self._pump_stop.set()
|
||||
cleaner = self._shutdown_cleaner
|
||||
try:
|
||||
self._finalizer()
|
||||
if self._finalizer.alive:
|
||||
self._finalizer()
|
||||
elif cleaner is not None:
|
||||
cleaner()
|
||||
finally:
|
||||
pump_threads = getattr(self, "_result_pump_threads", [])
|
||||
for thread in pump_threads:
|
||||
@@ -1035,5 +1068,6 @@ class MultiprocDiffusionExecutor(DiffusionExecutor):
|
||||
self._rpc_futures.clear()
|
||||
self._output_futures.clear()
|
||||
self._batch_split_map.clear()
|
||||
self._shutdown_cleaner = None
|
||||
self._processes = []
|
||||
self._processes = (cleaner.processes or []) if cleaner is not None else []
|
||||
if not self._processes:
|
||||
self._shutdown_cleaner = None
|
||||
Reference in new issue
Block a user