Repository navigation
fix(looper): close the Device-SMI handles on a failed or cancelled run (#4813) - #4823
Merged
Merged
Conversation
This was referenced Nov 17, 2026
Qubitium
added a commit
that referenced
this pull request
Nov 17, 2026
#4906) #4823 released the processors' Device-SMI handles in the failure branch of ModuleLooper.loop() and WeightOnlyLooper.loop(). A quantize() that failed before a looper existed still leaked them: LoopProcessor.__init__ opened one device_smi.Device per accelerator plus the CPU first and only then validated the calibration dataset, so every empty, too-short, or malformed dataset raised with two live 5 Hz sampler threads. A later processor in the chain failing (GPTQ + EoRA) leaked the processors already built, and the half-built one, for the same reason. Retry loops accumulated two threads per attempt. Open the Device-SMI handles lazily on the first metric query, so a processor that never runs never starts a sampler, and keep a closed processor closed. Additionally wrap the whole quantize prologue -- processor construction, checkpoint entry, install_w4a_llama_replay, ModuleLooper.__init__, and the loop itself -- in a try/except that releases every processor built so far (shared release_failed_run_processors helper, also used by ModuleLooper). Weight-only and EoRA generation get the same wrapper. Adds tests/test_pre_looper_failure_cleanup_4862.py: empty, too-short, and malformed calibration, a later EoRA processor failing after GPTQ was built, and release_failed_run on a never-opened processor. On the parent the three calibration cases each leave a device-smi-metrics-cpu thread and the EoRA case never releases the built processor.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4813.
Every
LoopProcessoropens adevice_smi.Deviceper device plus the CPU; eachstarts a daemon
device-smi-metrics-*thread polling at 5 Hz. The handles wereclosed only in
LoopProcessor.finalize(), which runs only on the success path,so every
StopMainLoop,KeyboardInterruptor callback/kernel exception leakedtwo polling threads (NVML/procfs) per processor for the life of the process.
Change
LoopProcessor.release_failed_run(): closes the Device-SMI handles andreleases the workspace cache, mirroring the part of
finalize()that thefailure path skipped. Idempotent, so a later
finalize()is a no-op.ModuleLooper.loop()'s failure branch calls it right after_fence_run_work()(before layer/offload restoration). Per-processorfailures are contained so the original run error is never masked.
WeightOnlyLooper.loop()had the same leak; it releases there too.Tests
New
tests/test_failed_run_device_smi_cleanup_4813.py:StopMainLoop) and a raising callback: snapshotsdevice-smi*thread idents, then polls (up to 10 s) and asserts none outlivethe run.
contained, and
release_failed_run()is idempotent with a real CPU handle.The one weight-only failure (
..._respects_dense_and_moe_vram_strategy_devices)also fails on the parent commit: the container exposes one GPU while the test
expects
cuda:0/1/2placement.Red on parent (source reverted, test kept): 5 failed — leaked
device-smi-metrics-cpu, missing release call, andAttributeError: no attribute 'release_failed_run'.Manual repro: parent cancelled run leaves
['device-smi-metrics-cpu']; fixedleaves
[]; fixed successful run leaves[].ruff: clean.