[Frontend] shutdown engine core and its sub processes asap when initializing (#52299)
Signed-off-by: Andy Xie <andy.xning@gmail.com> Co-authored-by: Simon Mo <simon.mo@hey.com>
This commit is contained in:
+51
-17
@@ -1410,6 +1410,50 @@ class EngineCoreProc(EngineCore):
|
||||
vllm_config.kv_transfer_config.engine_id,
|
||||
)
|
||||
|
||||
# declare engine core as None and register signal handler before
|
||||
# engine_core initialization in case engine core process is terminated
|
||||
# in the middle of initialization. For example, frontend process exits
|
||||
# unexpectedly, if signal handler is not registered, engine core process
|
||||
# will use default signal handler which will terminate the process
|
||||
# silently. If engine core model executor has been initialized, it will
|
||||
# not be terminated asap. Register signal handler early and only log a
|
||||
# message will make engine core process alive. engine core process and
|
||||
# its subprocesses(model executor processes) will be force killed in
|
||||
# CoreEngineProcManager.shutdown.
|
||||
engine_core = None
|
||||
# A termination signal can arrive while engine_core is still being
|
||||
# constructed. At that point the request cannot be recorded on
|
||||
# engine_core, so keep it in its own flag and apply it later.
|
||||
shutdown_requested = False
|
||||
|
||||
def wakeup_engine():
|
||||
# Wakes up idle engine via input_queue when shutdown is requested
|
||||
# Not safe in a signal handler - we may interrupt the main thread
|
||||
# while it is holding the non-reentrant input_queue.mutex
|
||||
assert engine_core is not None
|
||||
engine_core.input_queue.put_nowait((EngineCoreRequestType.WAKEUP, None))
|
||||
|
||||
def signal_handler(signum, frame):
|
||||
nonlocal shutdown_requested
|
||||
signal_name = signal.Signals(signum).name
|
||||
logger.info(
|
||||
"[shutdown] EngineCore: trigger received signal=%s",
|
||||
signal_name,
|
||||
)
|
||||
# Record the request first so it survives the construction window.
|
||||
shutdown_requested = True
|
||||
if engine_core is not None:
|
||||
engine_core.shutdown_state = EngineShutdownState.REQUESTED
|
||||
# signal_callback is armed only after engine_core exists. Don't
|
||||
# trigger it earlier: it is one-shot, and a wakeup cannot be
|
||||
# delivered while there is no input_queue to wake.
|
||||
# For more info: https://github.com/vllm-project/vllm/pull/52299#pullrequestreview-5370255271
|
||||
if signal_callback is not None:
|
||||
signal_callback.trigger()
|
||||
|
||||
signal.signal(signal.SIGTERM, signal_handler)
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
|
||||
parallel_config.data_parallel_index = dp_rank
|
||||
if data_parallel and vllm_config.model_config.is_moe:
|
||||
# Set data parallel rank for this engine process.
|
||||
@@ -1424,25 +1468,15 @@ class EngineCoreProc(EngineCore):
|
||||
|
||||
assert engine_core is not None
|
||||
|
||||
def wakeup_engine():
|
||||
# Wakes up idle engine via input_queue when shutdown is requested
|
||||
# Not safe in a signal handler - we may interrupt the main thread
|
||||
# while it is holding the non-reentrant input_queue.mutex
|
||||
engine_core.input_queue.put_nowait((EngineCoreRequestType.WAKEUP, None))
|
||||
|
||||
signal_callback = SignalCallback(wakeup_engine)
|
||||
|
||||
def signal_handler(signum, frame):
|
||||
signal_name = signal.Signals(signum).name
|
||||
logger.info(
|
||||
"[shutdown] EngineCore: trigger received signal=%s",
|
||||
signal_name,
|
||||
)
|
||||
# Apply a signal received during construction before entering the
|
||||
# loop. run_busy_loop calls _handle_shutdown first, so the loop exits
|
||||
# right away instead of blocking on an idle input_queue.
|
||||
if shutdown_requested:
|
||||
engine_core.shutdown_state = EngineShutdownState.REQUESTED
|
||||
signal_callback.trigger()
|
||||
|
||||
signal.signal(signal.SIGTERM, signal_handler)
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
# Arm the wakeup callback only now that input_queue exists, so a
|
||||
# later signal can still wake an idle busy loop.
|
||||
signal_callback = SignalCallback(wakeup_engine)
|
||||
|
||||
engine_core.run_busy_loop()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user