Repository navigation
fix(looper): rehome finished layers' kernels after a failed quantize (#4947) - #4979
Merged
Merged
Conversation
…4947) #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 was referenced Nov 17, 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.
Fixes #4947 — the follow-up to my #4893.
Root cause
Two parts:
rehome_quantized_kernel()after the loop, but the failure/cancel branch ofModuleLooper.loop()(andWeightOnlyLooper) only restored/materialized modules. Finished layers kept the calibration-time kernel (AwqGEMMLinear,QQQLinear, GGUF Triton) while their buffers sat on CPU/offload, so the next forward raisedNotImplementedError ... with arguments from the 'CPU' backend(AWQ) or the missing-kernel error (QQQ).forwardin_old_forward, so a__class__swap alone keeps executing the accelerator-only kernel. The swap now rebinds that captured forward.Chosen strategy
Rehome the finished layers rather than restoring them to dense: the packed buffers are valid and layout-compatible with the portable Torch kernel, so rehoming keeps the completed work and leaves the model usable, while preserving #4893's materialization and #4829/#4807's offload-root behaviour. Finished layers of an offloaded run are meta shells, so
rehome_failed_run_kernels()resolves the device from a materialized packed layer, else from the rest of the model, and passes it through a newdevice=override ofrehome_quantized_kernel. Rehome errors (e.g. the save-and-reload guidance) are logged and swallowed so the original exception always propagates. Called from both loopers right after materialization.Evidence (CUDA host, tiny 4-layer Llama,
offload_to_disk=True, cancel at layer 2)AwqGEMMLinear-> forwardNotImplementedError ... gemm_forward; QQQ layersQQQLinear-> forward failsAwqTorchLinear/QQQTorchLinear,qlinear_kernelupdated, forward(1, 4, 32)finite; also verified withoffload_to_disk=False(14 modules rehomed, qweight CPU, forward OK)Tests
New
tests/test_cancelled_quantize_kernel_rehome_4947.py(8 tests): red on parent 6 failed / 2 passed (the 4test_failed_run_rehomes_finished_layerscases and bothtest_cancel_at_last_layer...); green here 8/8. The 2 resume tests pass on parent too — they are guards, not red tests.test_cancelled_quantize_default_offload_4860+..._disk_offload_4807+..._layer_cleanup_4546+test_quantize_in_session_4381+test_qqq_runtime_state_4940: 27 passed, exit 0gemv_insession_4554,hf_cpu,gptq_lifecycle,modules_to_not_convert_lifecycle_4309,pack_vectorized,kernels/test_awq_torch): 78 passed, exit 0ruff check gptqmodel tests: cleanResidual risk
rehome_quantized_kernelraises its save-and-reloadRuntimeError; the failure path logs it and leaves the model mixed. Restoring to dense instead would discard finished layers, so this mirrors the success path's documented limitation.model.qlinear_kernelare skipped by the existing "only reinterpret kernels this run produced" rule and may stay mixed.WeightOnlyLooper(GGUF) rehome is best-effort and not exercised here (no GGUF fixture)._old_forward) are handled; a custom hook without that attribute keeps the old forward.