You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] Every cancelled/failed quantize() leaks the processors' device-smi metric threads (2 per run, NVML/CPU polled at 5 Hz forever): handles are closed only in finalize(), which the failure path never calls #4813
Found on main @ dba142d, RTX 4090, torch 2.15, device-smi installed in the venv.
What is wrong
Each LoopProcessor opens device_smi.Device handles for every device plus the CPU (gptqmodel/looper/loop_processor.py:535-536). Each handle starts a daemon device-smi-metrics-<type> thread that polls metrics every 200 ms (device_smi/device.py:_configure_fast_metrics, NVML for the GPU).
The handles are closed only in LoopProcessor.finalize() (loop_processor.py:1600, _close_device_smi_handles), and finalize() runs only on the success path. The failure branch of ModuleLooper.loop() (module_looper.py:2042-2063) does the following, and none of it closes the processors' handles:
fences work,
restores the in-flight layer and base modules,
releases the offload root,
releases the run workspace.
Each poll thread holds its Device through the bound target, so garbage collection never stops it.
As a result, every cancelled or failed quantize() permanently leaks 2 polling threads (GPU + CPU) per processor and device. This covers StopMainLoop from subset_callback, KeyboardInterrupt, and callback or kernel exceptions. The leaked threads keep querying NVML/procfs 5 times per second for the life of the process. A later successful run does not reap them.
Repro (Qwen2.5-0.5B-Instruct truncated to 4 layers, GPTQ 4-bit; cancel at layer 1 through the supported subset-callback path)
importgc, threading, time, resourcefromgptqmodelimportGPTQModelfromgptqmodel.quantizationimportconfigasCfromgptqmodel.looper.module_looperimportStopMainLoopdefsmi(): return [t.namefortinthreading.enumerate() ift.name.startswith("device-smi")]
foriinrange(4):
m=GPTQModel.load(MODEL, C.GPTQConfig(bits=4, group_size=128), dtype=torch.float16)
m.subset_callback=lambda**kw: StopMainLoopifkw.get("stage") =="forward_start"andkw.get("layer_idx") ==1elseNonetry: m.quantize(C.CalibrationConfig(dataset=calib, batch_size=4))
exceptStopMainLoop: passdelm; gc.collect(); time.sleep(1)
print(f"after cancelled run {i+1}: device-smi threads {len(smi())}") # + idle CPU over 5 s
start: device-smi threads 0, idle cpu% 0.0
after cancelled run 1: device-smi threads 2 idle cpu% 0.4
after cancelled run 2: device-smi threads 4 idle cpu% 0.8
after cancelled run 3: device-smi threads 6 idle cpu% 1.3
after cancelled run 4: device-smi threads 8 idle cpu% 1.4
after a successful run: device-smi threads 8 idle cpu% 1.5
A failure from an exception inside GPTQ.quantize, a layer_callback exception or KeyboardInterrupt, or a layer-forward exception leaves the same two extra threads (device-smi-metrics-cpu, device-smi-metrics-gpu) next to the pool's DPWorker-*/DP-Janitor. A successful run leaves none.
The same lingering threads were already visible in #4356's pytest thread count ("Twenty of those threads are lingering device-smi-metrics threads"), but the root cause was not filed.
Suggested fix
In ModuleLooper.loop()'s failure branch, after _fence_run_work(), close every processor's device-smi handles. Either call a new LoopProcessor.release_failed_run() that runs _close_device_smi_handles() (and the release_workspace_cache() that finalize() also skips), or make _close_device_smi_handles part of release_run_workspace(), which the finally already calls on every exit.
Test that should have caught it
tests/test_failed_run_fence_4595.py / test_cancelled_quantize_layer_cleanup_4546.py: assert that no device-smi-metrics* thread outlives a failed quantize().
Severity
Low-medium. It is a thread and CPU leak that grows with every cancelled or failed run in long-lived processes (notebooks, services that retry, sweeps that catch errors), and it pollutes thread-count tests.
Activity
Qubitium commentedon Nov 17, 2026
Agent claim released:
agent-53ba17eb4d83finished this issue.Pull request: #4823
Fixing: reproduce, root-cause, add regression test, keep existing suites green.
fix(looper): close Device-SMI handles on a failed or cancelled run (#…
fix(weight-only): return the in-flight layer to its home device on fa…