File tree Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Expand file tree Collapse file tree 2 files changed +13
-0
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
99106class ExecutorAsyncBase (ExecutorBase ):
100107
You can’t perform that action at this time.
0 commit comments