[Bugfix][V1] Clean up compiled-model bytecode hooks on VllmRunner exit (#45195)

Signed-off-by: Ting Sun <suntcrick@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
Ting SUN
2026-06-16 20:31:17 -07:00
committed by GitHub
co-authored by mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
parent 14b438a98b
commit 7b5d60cc37
4 changed files with 61 additions and 2 deletions
+9 -1
View File
@@ -154,7 +154,9 @@ class TorchCompileWithNoGuardsWrapper:
)
if envs.VLLM_USE_BYTECODE_HOOK and mode != CompilationMode.STOCK_TORCH_COMPILE:
torch._dynamo.convert_frame.register_bytecode_hook(self.bytecode_hook)
self._bytecode_hook_handle = (
torch._dynamo.convert_frame.register_bytecode_hook(self.bytecode_hook)
)
self._compiled_bytecode: CodeType | None = None
def aot_compile(self, *args: Any, **kwargs: Any) -> Any:
@@ -261,6 +263,12 @@ class TorchCompileWithNoGuardsWrapper:
)
raise RuntimeError(msg)
def cleanup(self) -> None:
"""Remove the bytecode hook registered by this instance."""
handle = getattr(self, "_bytecode_hook_handle", None)
if handle is not None:
handle.remove()
@contextmanager
def _dispatch_to_compiled_code(self) -> Generator[None, None, None]:
# noqa: E501