Skip to content

fix(weight-only): return the in-flight layer to its home device on failure (#5011) - #5049

Merged
Qubitium merged 1 commit into
mainfrom
root/inflight-layer-5011
Nov 18, 2026
Merged

Qubitium merged 1 commit into
mainfrom
root/inflight-layer-5011

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

Fixes #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:

RuntimeError: Expected all tensors to be on the same device, but found at least
two devices, cuda:0 and cpu!  (Qwen2RMSNorm.forward)

ModuleLooper solved exactly this for #4546. This PR shares that machinery
instead of copying it.

What Changed

Tests

tests/test_weight_only_failed_run_device_5011.py on unmodified origin/main
(236f31b07, test copied into a separate worktree): 8 failed.

  • The five end-to-end nodes (RTN, RTN without disk offload, GGUF, GGUF
    q_k_m, FP8) fail with
    a 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 the
    in-flight layer.
  • The three tracker nodes fail because the shared tracker does not exist on
    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_*):

tree result
origin/main 11 failed, 181 passed, 59 skipped
this branch 11 failed, 181 passed, 59 skipped — identical failure set (diffed)

The 11 are pre-existing on main (cancel/offload-path nodes plus two
test_post_loop_tail_failure_5023 GPTQ nodes that fail with an
UnboundLocalError in gptq_processor.py on both trees). ruff check clean.

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 #4546 cancelled-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

  • The mixin is deliberately a plain class, not a dataclass: _inflight_layer
    has a class-level None default so a looper that never stages a layer needs
    no __init__ change and cleanup stays a no-op.
  • git diff origin/main is 4 files, +346/−77; no unrelated edits.

…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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant