Skip to content

Commit 15e7c67

Browse files
authored
[Core] Add shutdown() method to ExecutorBase (#4349)
1 parent b6dcb4d commit 15e7c67

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

vllm/engine/llm_engine.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,12 @@ def __reduce__(self):
287287
# the closure used to initialize Ray worker actors
288288
raise RuntimeError("LLMEngine should not be pickled!")
289289

290+
def __del__(self):
291+
# Shutdown model executor when engine is garbage collected
292+
# Use getattr since __init__ can fail before the field is set
293+
if model_executor := getattr(self, "model_executor", None):
294+
model_executor.shutdown()
295+
290296
def get_tokenizer(self) -> "PreTrainedTokenizer":
291297
return self.tokenizer.get_lora_tokenizer(None)
292298

vllm/executor/executor_base.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ def check_health(self) -> None:
9595
exception."""
9696
raise NotImplementedError
9797

98+
def shutdown(self) -> None:
99+
"""Shutdown the executor."""
100+
return
101+
102+
def __del__(self):
103+
self.shutdown()
104+
98105

99106
class ExecutorAsyncBase(ExecutorBase):
100107

0 commit comments

Comments
 (0)