[Feature] Abort diffusion request (#1156)
Signed-off-by: dengyunyang <584797741@qq.com>
This commit is contained in:
1 parent
2ec1fc3c9c
commit
dc45f43a6a
6 files changed
+90
-16
No files matched your search
@@ -2,8 +2,8 @@
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
import os
|
||||
import signal
|
||||
import time
|
||||
from collections.abc import Iterable
|
||||
from typing import Any
|
||||
|
||||
import PIL.Image
|
||||
@@ -371,7 +371,13 @@ class DiffusionEngine:
|
||||
if hasattr(self, "executor"):
|
||||
self.executor.shutdown()
|
||||
|
||||
def abort(self, request_id: str | Iterable[str]) -> None:
|
||||
# TODO implement it
|
||||
logger.warning("DiffusionEngine abort is not implemented yet")
|
||||
pass
|
||||
def abort(self) -> None:
|
||||
"""
|
||||
Abort diffusion generation requests.
|
||||
"""
|
||||
try:
|
||||
for worker_pid in self.executor.get_worker_pids():
|
||||
os.kill(worker_pid, signal.SIGUSR1)
|
||||
logger.info("Interrupt signal sent to worker.")
|
||||
except Exception as e:
|
||||
logger.error(f"Failed to interrupt current diffusion forward: {e}")
|
||||
@@ -84,3 +84,8 @@ class DiffusionExecutor(ABC):
|
||||
def shutdown(self) -> None:
|
||||
"""Shutdown the executor and release resources."""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_worker_pids(self) -> None:
|
||||
"""Get worker pid."""
|
||||
pass
|
||||
@@ -130,6 +130,9 @@ class MultiprocDiffusionExecutor(DiffusionExecutor):
|
||||
def add_req(self, request: OmniDiffusionRequest) -> DiffusionOutput:
|
||||
return self.scheduler.add_req(request)
|
||||
|
||||
def get_worker_pids(self):
|
||||
return [process.pid for process in self._processes]
|
||||
|
||||
def collective_rpc(
|
||||
self,
|
||||
method: str,
|
||||
|
||||
@@ -9,6 +9,7 @@ to DiffusionModelRunner.
|
||||
|
||||
import multiprocessing as mp
|
||||
import os
|
||||
import signal
|
||||
from contextlib import AbstractContextManager, nullcontext
|
||||
|
||||
import torch
|
||||
@@ -66,6 +67,21 @@ class DiffusionWorker:
|
||||
self._sleep_saved_buffers: dict[str, torch.Tensor] = {}
|
||||
self.lora_manager: DiffusionLoRAManager | None = None
|
||||
self.init_device()
|
||||
# Registry signal
|
||||
signal.signal(signal.SIGUSR1, self._on_interrupt)
|
||||
|
||||
def _on_interrupt(self, signum, frame):
|
||||
# Set interrupt flag on the pipeline
|
||||
# The pipeline checks this flag in the diffuse loop
|
||||
if (
|
||||
self.model_runner is not None
|
||||
and self.model_runner.pipeline is not None
|
||||
and hasattr(self.model_runner.pipeline, "_interrupt")
|
||||
):
|
||||
self.model_runner.pipeline._interrupt = True
|
||||
logger.info("Worker: Interrupt flag set for current Running Request")
|
||||
else:
|
||||
logger.warning("Worker: Cannot set interrupt flag - model_runner or pipeline is None")
|
||||
|
||||
def init_device(self) -> None:
|
||||
"""Initialize the device and distributed environment."""
|
||||
|
||||
Reference in new issue
Block a user