Repository navigation
fix(looper): materialize unreached layers after a cancelled run (#4860) - #4893
Merged
Merged
Conversation
The failure branch kept the per-run offload root for the layers that finished before a cancel (#4829) but never filled the layers the loop never reached. With the default offload_to_disk=True those layers still owned meta tensors and had no offload hook, so the next forward failed on the first unreached layer with "Tensor on device cpu is not on the expected device meta!". Call the success path's remaining-meta materialization best effort on the cancel/failure path (ModuleLooper and WeightOnlyLooper). It only touches modules that own meta tensors and skips packed quantized modules, so the completed layers stay readable through the kept offload root and a resumable checkpoint is untouched.
This was referenced Nov 17, 2026
Qubitium
added a commit
that referenced
this pull request
Nov 17, 2026
…4947) (#4979) #4893 materialized the layers a cancelled run never reached, and #4829/#4807 kept the offload root of the layers it did finish, but the failure branch never rehomed the finished layers' kernels. A run packed with an accelerator-only kernel (AwqGEMMLinear, QQQLinear, GGUF Triton) therefore left CUDA-only modules behind a CPU model and the next in-session forward raised NotImplementedError: Could not run 'gptqmodel_awq::gemm_forward_fp32_reduce' with arguments from the 'CPU' backend The success path rehomes them in rehome_quantized_kernel; the failure path now does the same, best effort: - rehome_failed_run_kernels() (loop_processor) resolves the device from a materialized packed layer, else from the rest of the model (finished layers of a disk-offloaded run are meta shells), and calls rehome_quantized_kernel(model, device=...) so the probe can be overridden. Rehome errors such as the save-and-reload guidance are logged and swallowed so the original cancellation still propagates. - ModuleLooper and WeightOnlyLooper call it right after the #4893 materialization, so the #4893/#4829/#4807 behaviour is unchanged. - _switch_quant_linear_class rebinds the accelerate offload hook's captured bound ``forward`` (_old_forward) to the target kernel; otherwise the hook kept calling the accelerator-only class even after the swap. Adds tests/test_cancelled_quantize_kernel_rehome_4947.py: cancelled and RuntimeError-failed AWQ and QQQ runs, a cancel at the last layer, and a checkpoint resume. Each asserts the finished layers use the portable kernel, model.qlinear_kernel is updated, and an in-session forward is finite. The QQQ case forces the CUDA-only class when the native extension cannot build. On the parent all kernel/forward cases fail with AwqGEMMLinear/QQQLinear left behind.
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 #4860.
Root cause
The
except BaseExceptioncleanup inModuleLooper.loop()(andWeightOnlyLooper.loop()) restored the in-flight layer and base modules, but never ran the success path's_materialize_remaining_meta_modules(). With the defaultoffload_to_disk=Truethe model is a lazy meta shell, so every layer past the cancel point still owned meta tensors and had no offload hook. The next forward failed on the first unreached layer withTensor on device cpu is not on the expected device meta!.Repro on base
6ec93e63(which already includes #4829), 4-layer tiny Llama, cancel at layer 2:Fix
module_looper.py: new_materialize_unreached_meta_modules()(best effort, logs and never masks the original exception) called in the failure branch after_restore_offloaded_base_modules(strict=False), before the offload-root keep/release decision.weight_only_looper.py: same helper, which also runs the weight-only success path's_materialize_meta_base_modules(strict=False)so base modules are covered.After the fix the same repro shows
layer3: meta-mods=0, root kept for layers 0-1,FWD_OK. Same result forStopMainLoopat layers 1/2/3 and an injectedRuntimeError.Tests
New
tests/test_cancelled_quantize_default_offload_4860.py(4-layer tiny Llama viaGPTQModel.load, default offload):module.safetensorsbundles in the kept root, and a plain forward worksResults: 3 passed, exit 0. Red on parent: 2 failed / 3 passed with
AssertionError: layer 3 was never reached ... but still owns meta tensors.Also:
tests/test_cancelled_quantize_disk_offload_4807.pypasses;ruff check gptqmodel testsclean.Pre-existing failure (not caused here)
tests/test_failed_run_fence_4595.py::test_failed_quantize_does_not_leak_offload_bundlesfails identically on pristineorigin/maind8758c48— the test still asserts the run root is deleted, but #4829 intentionally keeps it while completed layers remain hooked. Left untouched to keep this PR scoped.Residual risk
pre_quantizefailure in scratch, not in the committed test.