Repository navigation
[CI] vlm: Harden fixture cleanup after setup and shutdown failures - #45461
Conversation
…tearDownClass Each class's _init_visual loads a vision tower/projector into the test process, and tearDownClass only shut down the engine, so the next class started with ~1.8 GiB still held by the test process. The CI GPU idle check discounts the current process by PID, which fails on runners whose NVIDIA driver reports host PIDs inside containers, so the next setUpClass timed out with "GPU(s) still not idle". Drop the class-level nn.Module attributes and empty the device cache after shutting down the engine. Co-Authored-By: Claude Opus 5.5 <[email protected]>
| @@ -106,6 +107,17 @@ def tearDownClass(cls): | |||
| if cls.engine is not None: | |||
| cls.engine.shutdown() | |||
There was a problem hiding this comment.
Should fix: cls.engine.shutdown() has no try/finally around it. If it raises, the release below never runs. Engine.shutdown wraps kill_process_tree(..., wait_timeout=60) in a try/finally with no except, so a timeout or a failure stopping a gRPC or weight-cache daemon propagates out. The vision modules then stay on the GPU, and the next class fails the idle check with "GPU(s) still not idle" instead of showing the real teardown error.
Wrap the shutdown in try: and move the module release into finally:.
| for name, value in list(vars(cls).items()): | ||
| if isinstance(value, torch.nn.Module): | ||
| setattr(cls, name, None) | ||
| gc.collect() |
There was a problem hiding this comment.
Should fix: this release frees nothing when setUpClass fails partway through _init_visual. CustomTestCase.safe_setUpClass (python/sglang/test/test_utils.py) calls tearDownClass() from inside its except block, while the exception is still live. The traceback's _init_visual frame still holds the model local, and that parent model keeps every submodule already moved to the GPU alive. Setting the class attributes to None doesn't drop them, and empty_cache() runs before the frame is released. After that nothing calls it again, so the next class fails the idle check: the same cascade this PR is fixing.
Two concrete cases:
- Gemma:
vision_tower.to(cuda)succeeds, thenmulti_modal_projector.to(cuda)OOMs. - InternVL:
vision_modelandmlp1reach the GPU, then a transformers bump drops a config field read at lines 538-549.
One way to fix it in this file is to clear the failed frames' locals before re-raising, wherever _init_visual is called. That is the base setUpClass plus the InternVL and MiniCPM overrides:
try:
cls._init_visual()
except BaseException as e:
traceback.clear_frames(e.__traceback__)
raise| if _is_cuda: | ||
| torch.cuda.empty_cache() | ||
| elif _is_xpu: | ||
| torch.xpu.empty_cache() |
There was a problem hiding this comment.
Should fix: empty_gpu_cache() in sglang.test.test_utils already does this. It calls torch.accelerator.empty_cache() and falls back to CUDA/XPU.
The hand-rolled branch also doesn't match how devices are picked. The InternVL and MiniCPM setUpClass overrides choose cuda via torch.cuda.is_available(), which is True on ROCm. _is_cuda is sglang's is_cuda(), which requires torch.version.cuda and is False on ROCm, so the cache is never emptied there.
| if _is_cuda: | |
| torch.cuda.empty_cache() | |
| elif _is_xpu: | |
| torch.xpu.empty_cache() | |
| empty_gpu_cache() |
(plus from sglang.test.test_utils import CustomTestCase, empty_gpu_cache)
This comment has been minimized.
This comment has been minimized.
|
🚀 |
|
|
Picks up sgl-project#45461, which fixes the unrelated CI failure https://github.com/sgl-project/sglang/actions/runs/39963987853/job/120661771575 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Picks up sgl-project#45461, which fixes the unrelated CI failure https://github.com/sgl-project/sglang/actions/runs/39962247821/job/120658000049 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Motivation
VLM input-format tests load vision towers and projectors into the parent test process. Shutting down the engine leaves those modules alive across test classes. On affected runners, NVML reports a PID that the container's GPU-idle check cannot match, so this retained memory causes the next class to fail with
GPU(s) still not idle.Cleanup must also run when engine shutdown raises or visual initialization fails partway through loading a model. A live initialization traceback can otherwise retain the parent model even after class attributes are cleared.
Changes
finally, collect cycles, and call the existing backend-awareempty_gpu_cache()helper.The GPU-idle memory threshold and PID matching are unchanged. Shared PID-namespace handling remains separate work.
Validation
Tested the original PR head
8e34fba684and the updated fixture on one H200 devbox with Python 3.12.15, PyTorch 2.14.1+cu130, Transformers 5.19.0, and NVIDIA open kernel driver 595.71.05.SGLANG_IS_IN_CI=true.Gemma was excluded because this devbox lacks authorized access to the gated model. The H200 environment reports matching local and NVML PIDs, so it does not reproduce the proprietary-driver PID mismatch. ROCm and XPU hardware were not tested.
The initial PR author separately reported testing on an affected H100 runner with NVIDIA driver
570.211.01and the proprietary kernel module, running this file directly withSGLANG_IS_IN_CI=true. After releasing the vision modules, the run passed 16 tests with 3 skips; that result was not rerun here.CI States
Latest PR Test (Base): ❌ Run #39875042227
Latest PR Test (Extra): ❌ Run #39875042141
Latest PR Test (AMD ROCm 10): ❌ Run #39875042267