Skip to content

[CI] vlm: Harden fixture cleanup after setup and shutdown failures - #45461

Merged
Kangyan-Zhou merged 3 commits into
mainfrom
emmett/vlm-input-format-free-models
Oct 23, 2026
Merged

Kangyan-Zhou merged 3 commits into
mainfrom
emmett/vlm-input-format-free-models

Conversation

@em-dreyer

@em-dreyer em-dreyer commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator

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

  • Release class-owned vision modules in finally, collect cycles, and call the existing backend-aware empty_gpu_cache() helper.
  • Clear failed visual-initialization frame locals, including chained exceptions, before existing setup-error teardown runs. Preserve exception objects, messages, and traceback locations.
  • Avoid temporary teardown-loop references keeping the final module alive through cache cleanup.

The GPU-idle memory threshold and PID matching are unchanged. Shared PID-namespace handling remains separate work.

Validation

Tested the original PR head 8e34fba684 and 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.

  • Public-model inference: all 10 InternVL2-2B, Kimi-VL-A3B-Instruct, and Qwen2.5-VL-3B-Instruct tests passed on both versions with SGLANG_IS_IN_CI=true.
  • Real 3 GiB CUDA allocation probes: the original fixture retained the allocation after injected shutdown and initialization failures; the updated fixture returned allocated and reserved memory to zero in both failure cases and normal teardown. Original errors remained observable.
  • Local validation before removing the standalone test: 2 CPU test methods covering 11 subcases passed with GPUs hidden. No new test file is included in the PR.
  • Applicable pre-commit checks passed.

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.01 and the proprietary kernel module, running this file directly with SGLANG_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

…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]>
@github-actions github-actions Bot added Multi-modal multi-modal language model npu labels Oct 20, 2026
@em-dreyer
em-dreyer requested a review from hnyls2002 October 22, 2026 20:08
@@ -106,6 +107,17 @@ def tearDownClass(cls):
if cls.engine is not None:
cls.engine.shutdown()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, then multi_modal_projector.to(cuda) OOMs.
  • InternVL: vision_model and mlp1 reach 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

Comment on lines +117 to +120
if _is_cuda:
torch.cuda.empty_cache()
elif _is_xpu:
torch.xpu.empty_cache()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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)

@alisonshao alisonshao changed the title [CI] vlm: Release in-process vision modules in test_vlm_input_format tearDownClass [CI] Harden VLM fixture cleanup after setup and shutdown failures Oct 22, 2026
@alisonshao
alisonshao marked this pull request as ready for review October 23, 2026 06:26
@alisonshao alisonshao added the run-ci CI: run the baseline test suite on this PR label Oct 23, 2026
@github-actions

This comment has been minimized.

@alisonshao alisonshao changed the title [CI] Harden VLM fixture cleanup after setup and shutdown failures [CI] vlm: Harden fixture cleanup after setup and shutdown failures Oct 23, 2026
@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

🚀 1-gpu-h100 (1 test): ✅ View workflow run

cd test/ && python3 registered/vlm/test_vlm_input_format.py

@alisonshao

Copy link
Copy Markdown
Collaborator

/rerun-test test/registered/vlm/test_vlm_input_format.py

CI run

@Kangyan-Zhou
Kangyan-Zhou merged commit 1d605b7 into main Oct 23, 2026
208 of 231 checks passed
@Kangyan-Zhou
Kangyan-Zhou deleted the emmett/vlm-input-format-free-models branch October 23, 2026 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Multi-modal multi-modal language model npu run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants