Repository navigation
fix(weight-only): return the in-flight layer to its home device on failure (#5011) - #5049
Merged
Merged
Conversation
…ilure (#5011) `WeightOnlyLooper` moves the layer it is staging to the quantization device in `BaseQModel.pre_quantize`, and the success path moves it back only in `post_quantize`. The failure branch restored base modules (#4546), filled the layers past the cancel point (#4860), rehomed kernels (#4947) and released processor resources (#4813), but it never returned the in-flight layer. After a cancelled or failed RTN/GGUF/FP8 run every parameter and buffer of that layer -- including its RMSNorms and unquantized projections -- stayed on the accelerator while the rest of the model was on CPU, so every later forward raised `Expected all tensors to be on the same device`. `ModuleLooper` already solved this for #4546. The tracker (`_track_inflight_layer` / `_clear_inflight_layer` / `_restore_inflight_layer`) now lives in `gptqmodel/looper/inflight_layer.py` and both loopers inherit it. `WeightOnlyLooper` tracks the layer before and after `pre_quantize` (which may return a materialized shell) and after the model-specific converter, clears it after `post_quantize`, and restores it first in the failure branch. Tests: `tests/test_weight_only_failed_run_device_5011.py` -- 8 failed on unmodified main, 8 passed here. On main the injected failure leaves all 12 tensors of `model.layers.2` on `cuda:0` (q/k/v/o, gate/up/down and both norms).
This was referenced Nov 18, 2026
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.
Summary
Fixes #5011.
WeightOnlyLoopermoves the layer it is staging to thequantization device in
BaseQModel.pre_quantize, and the success path moves itback only in
post_quantize. The failure branch restored base modules(#4546), filled the layers past the cancel point (#4860), rehomed kernels
(#4947) and released processor resources (#4813), but it never returned the
in-flight layer. After a cancelled or failed RTN/GGUF/FP8 run, every parameter
and buffer of that layer — including its RMSNorms and unquantized projections —
stayed on the accelerator while the rest of the model was on CPU:
ModuleLoopersolved exactly this for #4546. This PR shares that machineryinstead of copying it.
What Changed
gptqmodel/looper/inflight_layer.py(new):InflightLayerTrackerwith_track_inflight_layer/_clear_inflight_layer/_restore_inflight_layerand
_clear_layer_capture_hooks, moved verbatim fromModuleLooper(including the [BUG] #4515 (fix of #4470) incomplete: stopping quantize() at the forward_end subset stage (StopMainLoop, exception or Ctrl-C) leaves capture hooks with forward_hook_last=True; every later forward raises StopForward #5009 capture-hook safety net).
gptqmodel/looper/module_looper.py:ModuleLoopernow inherits the mixin;the three methods and the static helper are removed (no behaviour change).
gptqmodel/looper/weight_only_looper.py:WeightOnlyLooperinherits themixin; it tracks the layer before and after
pre_quantize(which may return amaterialized shell) and after the model-specific converter, clears the tracker
after
post_quantize, and restores the in-flight layer first in the failurebranch. The original exception still propagates unchanged.
tests/test_weight_only_failed_run_device_5011.py(new, 8 nodes), run in theAWQ CPU
unitCI lane.Tests
tests/test_weight_only_failed_run_device_5011.pyon unmodifiedorigin/main(
236f31b07, test copied into a separate worktree): 8 failed.q_k_m, FP8) fail witha failed weight-only run left tensors on the quantization device: {'cuda:0': ['model.layers.2.self_attn.q_proj.weight', ..., 'model.layers.2.input_layernorm.weight', 'model.layers.2.post_attention_layernorm.weight']}— all 12 tensors of thein-flight layer.
main.
On this branch: 8 passed.
Neighbouring suites (
test_weight_only*,test_cancelled_quantize_*,test_failed_run_*,test_quantize_in_session_4381,test_module_looper_*,test_offload_base_modules_restored,test_offload_autograd,test_post_loop_tail_failure_5023,test_looper_*):origin/mainThe 11 are pre-existing on main (cancel/offload-path nodes plus two
test_post_loop_tail_failure_5023GPTQ nodes that fail with anUnboundLocalErroringptq_processor.pyon both trees).ruff checkclean.Model Support / Module Plan
No model, module-plan or kernel change. Both loopers keep their existing
lifecycle; only the failure-path placement restore is now shared and applied to
the weight-only looper.
Logic Flow Documentation
No new doc page: the behaviour is the existing
#4546cancelled-run contract("a failed run leaves the layer where it found it"), now also implemented for
WeightOnlyLooper. The tracker's docstrings carry the issue references(#4546, #5009, #5011).
Notes
_inflight_layerhas a class-level
Nonedefault so a looper that never stages a layer needsno
__init__change and cleanup stays a no-op.git diff origin/mainis 4 files, +346/−77; no unrelated edits.