Repository navigation
fix(looper): release pre-looper resources on a failed quantize (#4862) - #4906
Merged
Merged
Conversation
#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 was referenced Nov 17, 2026
sLaffey
pushed a commit
to sLaffey/GPTQModel
that referenced
this pull request
Nov 18, 2026
…elCloud#4967) (ModelCloud#4971) `tests/test_docs_contract_refs.py` was red on main again: four citations into `gptqmodel/models/base.py` were 114 lines out of the 8-line window, because base.py keeps growing under them (ModelCloud#4894, ModelCloud#4906, ModelCloud#4912, ModelCloud#4930): docs/awq-scale-folding.md _select_prev_op 5489 -> 5667 docs/calibration-replay.md capture_layer_type_replay_kwargs 4022 -> 4200 docs/calibration-replay.md _build_layer_type_position_embeddings 4005 -> 4183 docs/fp8-scale-semantics.md _decoder_fp8_scale_semantics 4752 -> 4930 Re-anchoring the numbers would rot again at the next base.py change, so the guard now accepts a symbol-anchored citation (`path.py::symbol`) and those four docs use it. The test still resolves the symbol in the source, so a renamed or removed symbol fails; only the line number stops being part of the contract. The line-number form stays for files that are not growing. Also re-anchored the stale `:5531` on the adjacent `:postnorm` row to `base.py::_select_prev_op` and `POST_NORM_FLAG` (base.py:560). And the test now runs pre-merge: it is the first file in the AWQ CPU `unit` suite, and `docs/**` plus the test itself are added to that workflow's path filter, so a base.py or docs change runs it. On unmodified main: 4 failed, 16 passed. With the fix: 20 passed. Copying only the new test onto main (docs still citing line numbers) also fails all four, which proves the new form is actually enforced. Closes ModelCloud#4967.
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 #4862.
Root cause
LoopProcessor.__init__opened onedevice_smi.Deviceper accelerator plus the CPU before validating/preparing the calibration dataset. Every handle owns a 5 Hzdevice-smi-metrics-*daemon thread. The #4823 fix only released handles in the loopers' failure branches, so:release_failed_run();loop()(checkpoint_session,install_w4a_llama_replay,ModuleLooper.__init__) had the same gap.Each retry added two threads for the life of the process.
Fix
_device_smi_handlesstarts as an uninitialized sentinel and_ensure_device_smi_handles()opens them on the first metric query, under the existing lock. A processor that never runs starts no sampler._close_device_smi_handles()marks the processor closed, so a released processor cannot reopen one._quantize_with_calibrationnow wraps processor construction -> checkpoint entry ->install_w4a_llama_replay->ModuleLooper.__init__->loop()inexcept BaseException: release_failed_run_processors(processors); raise. Same wrapper for_quantize_weight_onlyand_eora_generate.release_failed_run_processors()is shared withModuleLooper._release_failed_run_processors()(same best-effort, non-masking semantics); repeated release stays idempotent, so the fix(looper): close the Device-SMI handles on a failed or cancelled run (#4813) #4823 in-loop release double-call is harmless.Evidence
Red on parent (
6ec93e63, pristine worktree + final test file): 5 failed, exit 1[empty],[too-short],[bad-row]: each left['device-smi-metrics-cpu']ImportError: _DEVICE_SMI_UNINITIALIZEDGreen after fix: new file 5 passed; new file + #4823 suite 10 passed; 8 affected suites 85 passed;
test_checkpoint_interop_4053.py27 passed, 1 skipped; success-path smoke leaves 0device-smithreads;ruff check gptqmodel testsclean.Pre-existing failure on main (not caused here)
test_checkpoint_interop_4053.py::test_load_state_dict_round_trip_preserves_v1_model[gptq_triton]is red on pristineorigin/maind8758c48— its_logits()helper forwards CPUinput_idsinto a CUDA model, and #4871 deliberately removed the per-module hooks that used to move them. Filed separately.Residual risk
release_workspace_cache(), which is process-wide; a concurrent run in the same process could see its cached Hessian workspace dropped. Same semantics fix(looper): close the Device-SMI handles on a failed or cancelled run (#4813) #4823 already uses on failure; quantize runs are not designed to overlap.eora_save()failures after a successful EoRA loop remain uncovered (processors are finalized by then).