Repository navigation
Conversation
This was referenced Nov 29, 2026
Merged
Collaborator
Author
Qubitium
added a commit
that referenced
this pull request
Nov 29, 2026
…buffers (#6180, #6156) (#6271) Consolidate #6225 and #6242, which both edited the disk-offload hook lifecycle in gptqmodel/utils/offload.py. #6180: move modules skipped by the 4 KiB cutoff to CPU, move non-persistent buffers of offloaded modules to the requested restore device after detach_hook, and drop the no-op io_same_device root hook left by disk_offload(). #6156: snapshot resident (non-offload) accelerate hooks before disk_offload() wraps them and reattach them after undo. A module that was never offloaded is left untouched. The two rules share one predicate in undo_offload_to_disk(): a tree was offloaded iff it still has meta leaves or a disk-offload hook. A never-offloaded tree restores its snapshot and returns; only an offloaded tree computes and releases non-persistent buffers.
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 #6156.
requantize()on a checkpoint loaded across two GPUs completes, but the first in-sessiongenerate()fails withExpected all tensors to be on the same devicebecauserestore_offloaded_modules()->undo_offload_to_disk()removes every accelerate hook onmodel.norm,model.rotary_emb,lm_head— including theGPTQModelAlignDevicesHookthe multi-GPU loader installed. The weights return to their devices, but without the hook the norm no longer moves its input to its execution device.What Changed
offload_to_disk()/attach_disk_offload_hook()snapshot resident (non-offload) accelerate hooks on the module subtree beforedisk_offload()wraps them.undo_offload_to_disk()restores that snapshot after removing the temporary disk-offload hooks, so loader-installed dispatch hooks survive the round trip.undo_offload_to_disk()is now a no-op for modules that were not actually offloaded (below the 4 KiB cutoff or tensor-less, e.g.model.norm/rotary_emb) instead of stripping their unrelated hooks.Tests
Red at
2d3261d(fix removed from the working tree, regression test kept):Result:
1 failed—AssertionError: assert None is AlignDevicesHook(...)formodel.norm(the hook was stripped).Green with the fix:
Result:
5 passed.Wider CPU-only offload family:
Result:
121 passed, 7 skipped.Also ran CPU-only:
test_offload_disk_container_5145.py test_cancelled_quantize_default_offload_4860.py test_cancelled_quantize_disk_offload_4807.py test_run_exit_recovery_contract_5060.py test_post_loop_tail_failure_5023.py test_cpu_offload_device_map_tied_head_4866.py test_hf_bridge_cpu_offload_5022.py test_offload_run_cleanup_4368.py test_offload_run_namespace.py test_single_device_dispatch_4847.py test_rehome_hook_realign.py -q -rs->81 passed, 35 skipped.Lint:
/root/venv/bin/ruff check gptqmodel/utils/offload.py tests/test_offload_base_modules_restored.py # All checks passed!CPU-only dispatch simulation
The regression test attaches the same
GPTQModelAlignDevicesHook(execution_device=torch.device("cpu"), io_same_device=True, place_submodules=False)the loader attaches for a device map tomodel.norm,model.rotary_emb, andlm_headof a tiny untied Llama. It then runscapture_offloaded_base_modules()->offload_to_disk()->restore_offloaded_modules()and asserts each original hook object is still attached.lm_headis actually disk-offloaded;model.normis below the 4 KiB cutoff androtary_embowns no tensors, so the restore visits them without offloading — exactly the path that stripped their hooks. Hook ownership/removal is device-agnostic; the two-GPU device mismatch itself was not reproduced (no GPU used).Skips / unverified
test_offload_autograd.py:150,test_offload_files.py:979and:2258,test_offload_quantized_modules_restored_4450.py:322,:380x2).generate()afterrequantize()was simulated at the hook level on CPU. The fix preserves the exact hook object, so the dispatch placement is retained.Logic Flow Documentation
Not applicable: this is a hook-lifecycle fix inside the existing disk-offload/restore path; it does not change selection order or add a new decision mechanism.