Repository navigation
fix(looper): keep the offload root for completed layers of a cancelled run (#4807) - #4829
Merged
Merged
Conversation
…d run (#4807) A cancelled or failed ``quantize()`` with the default ``offload_to_disk=True`` left every already-quantized layer as a meta shell behind an accelerate disk-offload hook, then deleted the per-run offload directory those hooks read from. The next forward raised ``FileNotFoundError`` for ``<run>/model.layers.N.<proj>/module.safetensors`` and the completed layers were unrecoverable: their packed and original weights only existed in that directory. The failure branch restored the in-flight layer and the base modules, but unlike the success path it did not bring the disk-offloaded modules back before calling ``release_private_offload_root``. Fix: keep the run directory alive while any module still owns a disk-offload hook, and release it eagerly only when nothing reads from it. This is the right option for a *cancelled* run: restoring every finished layer into host memory would defeat the memory bound that ``offload_to_disk=True`` exists for (a cancel on a large model would materialize tens of GB), whereas the completed layers stay lazily loadable exactly as they were during the run. The directory is already owned by the model-lifetime ``weakref.finalize`` installed by ``bind_private_offload_root``, so ownership passes to the model: it is reclaimed when the model is collected or when the next run re-binds the namespace (#4368). The in-flight layer and base modules are still restored as before (#4546/#4580). The same guard is applied to the identical failure branch in ``WeightOnlyLooper``. Tests: - New ``tests/test_cancelled_quantize_disk_offload_4807.py`` (cancel via ``StopMainLoop`` and an injected ``RuntimeError`` at layer 1's ``forward_start``) asserts the completed layer is still disk-offloaded, its bundle exists (or the model no longer points at the root), and a plain forward succeeds. It fails on unmodified main with: ``AssertionError: the per-run offload root was deleted while modules still read from it: ['model.layers.0.self_attn.q_proj', ...]``. - ``tests/test_cancelled_quantize_layer_cleanup_4546.py`` and all ``tests/test_*offload*.py``: 170 passed, 9 skipped, 1 failed. The one failure, ``test_offload_base_modules_restored.py::test_loop_restores_base_modules_when_quantize_fails``, is pre-existing on main (identical ``AttributeError: 'ModuleLooper' object has no attribute '_inflight_layer'`` from the test's ``object.__new__`` stub) and is unrelated to this change. - ``ruff check`` passes on every changed file.
This was referenced Nov 17, 2026
Qubitium
added a commit
that referenced
this pull request
Nov 17, 2026
… (#4893) 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. Co-authored-by: Codex <codex@localhost>
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.
sLaffey
pushed a commit
to sLaffey/GPTQModel
that referenced
this pull request
Nov 18, 2026
…lCloud#4978) Seven tests went red because their doubles/oracles predate library changes that behave as intended. This is test-only; no product code changes. - test_fusion_kernel_backends: gc.collect() before the weakref check; ModelCloud#4871 leaves transient Dynamo trace garbage that keeps the pre-fusion weight alive. The refs are still asserted dead afterwards. - test_failed_run_fence_4595: del qmodel + gc.collect() so ModelCloud#4829's finalizer runs before the no-leak assertion; a late finalizer must not recreate the released run dir. - test_exl3_projection_resume: add _release_deferred_hessian_sources() to the _Capture double (ModelCloud#4837). - test_kernel_audit_regressions: stub _needs_torch_fallback=lambda: False on the SimpleNamespace self (ModelCloud#4835). - test_moe_resave_preserves_experts_4589: accept the earlier RuntimeError "does not provide tensors" refusal (ModelCloud#4810); still assert no safetensors. - test_positional_mask_capture_4660: build the native oracle with the same mask-derived position_ids the capture uses (ModelCloud#4930). - test_qqq_kernel_memory_4387: snapshot the oracle weight/s_channel before the first forward, which may drop the checkpoint layout (ModelCloud#4856).
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.
fix(looper): keep the offload root for completed layers of a cancelled run (#4807)
A cancelled or failed
quantize()with the defaultoffload_to_disk=Trueleft every already-quantized layer as a meta shell behind an accelerate
disk-offload hook, then deleted the per-run offload directory those hooks read
from. The next forward raised
FileNotFoundErrorfor<run>/model.layers.N.<proj>/module.safetensorsand the completed layers wereunrecoverable: their packed and original weights only existed in that directory.
The failure branch restored the in-flight layer and the base modules, but unlike
the success path it did not bring the disk-offloaded modules back before calling
release_private_offload_root.Fix: keep the run directory alive while any module still owns a disk-offload
hook, and release it eagerly only when nothing reads from it. This is the right
option for a cancelled run: restoring every finished layer into host memory
would defeat the memory bound that
offload_to_disk=Trueexists for (acancel on a large model would materialize tens of GB), whereas the completed
layers stay lazily loadable exactly as they were during the run. The directory
is already owned by the model-lifetime
weakref.finalizeinstalled bybind_private_offload_root, so ownership passes to the model: it is reclaimedwhen the model is collected or when the next run re-binds the namespace (#4368).
The in-flight layer and base modules are still restored as before (#4546/#4580).
The same guard is applied to the identical failure branch in
WeightOnlyLooper.Tests:
tests/test_cancelled_quantize_disk_offload_4807.py(cancel viaStopMainLoopand an injectedRuntimeErrorat layer 1'sforward_start) asserts the completed layer is still disk-offloaded, itsbundle exists (or the model no longer points at the root), and a plain
forward succeeds. It fails on unmodified main with:
AssertionError: the per-run offload root was deleted while modules still read from it: ['model.layers.0.self_attn.q_proj', ...].tests/test_cancelled_quantize_layer_cleanup_4546.pyand alltests/test_*offload*.py: 170 passed, 9 skipped, 1 failed.The one failure,
test_offload_base_modules_restored.py::test_loop_restores_base_modules_when_quantize_fails,is pre-existing on main (identical
AttributeError: 'ModuleLooper' object has no attribute '_inflight_layer'from the test'sobject.__new__stub) andis unrelated to this change.
ruff checkpasses on every changed file.