[Rebase] Rebase to vllm 0.23.0 (#4286)

Signed-off-by: tzhouam <tzhouam@connect.ust.hk>
This commit is contained in:
Zhou Taichang authored and GitHub committed 2026-06-13 16:43:02 +00:00
1 parent a9ee92ddec
commit 7b837944a1
36 files changed
+481 -135

No files matched your search

+58
View File
@@ -6,6 +6,7 @@ and also outputs sampled tokens.
from __future__ import annotations
import gc
from collections.abc import Mapping
from contextlib import nullcontext
from copy import copy
@@ -268,6 +269,63 @@ class GPUARModelRunner(OmniGPUModelRunner, OmniConnectorModelRunnerMixin):
self._capture_talker_mtp_graphs()
return result
def shutdown(self) -> None:
"""Release omni-specific GPU resources before upstream shutdown.
Order of operations (must match upstream's expectation):
1. Unfreeze Python GC so model weights are collected immediately
when self.model is set to None (upstream Worker.init_device
calls gc.freeze() / freeze_gc_heap()).
2. Destroy omni-specific CUDA graphs (talker MTP) so references to
model parameters are released before self.model = None.
3. Clear GPU-side buffers (input_ids, inputs_embeds) and per-request
caches that may hold GPU tensor references.
4. Call CUDAGraphWrapper.clear_all_graphs() unconditionally (not just
on ROCm) to ensure all CUDA graphs including talker MTP are
released before model weight teardown.
5. Call BreakableCUDAGraphWrapper.clear_all_graphs() as well, to
match the upstream ROCm-only pattern but also protect CUDA.
6. Delegate to upstream GPUModelRunner.shutdown() which sets
self.model = None, clears KV caches, resets workspace, etc.
This prevents abrupt GPU memory release during EngineCore subprocess
exit that can trigger GPU OOM signals when the parent process
concurrently cleans up its own GPU state.
"""
# 1. Unfreeze GC so model weights and GPU tensors are collected
# immediately when references are dropped (upstream Worker.shutdown
# also does this before any teardown).
gc.unfreeze()
# 2. Destroy talker MTP CUDA graph wrapper to release captured graphs.
if hasattr(self, "talker_mtp") and self.talker_mtp is not None:
self.talker_mtp = None
self.has_talker_mtp = False
# 3. Clear GPU-side buffers (small tensors, but every MiB helps).
if hasattr(self, "input_ids") and self.input_ids is not None:
self.input_ids = None
if hasattr(self, "inputs_embeds") and self.inputs_embeds is not None:
self.inputs_embeds = None
# 4. Clear per-request caches that may hold GPU tensor references.
if hasattr(self, "_downstream_payload_cache"):
self._downstream_payload_cache.clear()
if hasattr(self, "model_intermediate_buffer"):
self.model_intermediate_buffer.clear()
# 5. Release all CUDA graphs unconditionally (upstream only does this
# on ROCm; on CUDA the graphs are only freed by Python GC during
# interpreter shutdown, which is too late to prevent memory spikes).
from vllm.compilation.breakable_cudagraph import BreakableCUDAGraphWrapper
from vllm.compilation.cuda_graph import CUDAGraphWrapper
CUDAGraphWrapper.clear_all_graphs()
BreakableCUDAGraphWrapper.clear_all_graphs()
# 6. Delegate to upstream shutdown (model = None, KV caches, workspace).
super().shutdown()
def _capture_talker_mtp_graphs(self) -> None:
from vllm.compilation.cuda_graph import CUDAGraphWrapper