Repository navigation
fix(offload): keep loader dispatch hooks and release skipped modules/buffers (#6180, #6156) - #6271
Merged
Merged
Conversation
…buffers (#6180, #6156) 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 was referenced Nov 29, 2026
Qubitium
marked this pull request as ready for review
November 29, 2026 08:20
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 #6180
Fixes #6156
Summary
Consolidates #6225 and #6242 into one change. Both PRs fixed different bugs in the same
attach_disk_offload_hook()/undo_offload_to_disk()region ofgptqmodel/utils/offload.py, so they conflicted. This PR carries every behavioural change and every test from both.#6180 — release skipped modules and non-persistent buffers
_offload_disk_locked()moves a module skipped by the 4 KiB cutoff to CPU instead of leaving it on the quantization device.undo_offload_to_disk()moves non-persistent buffers of offloaded modules (inv_freq,original_inv_freq, SigLIPposition_ids) to the requested restore device afterdetach_hook, since they are absent from the offload index and are not meta leaves.restore_disk_offloaded_modules()removes the no-op rootio_same_devicehook thatdisk_offload()leaves behind once the subtree is fully materialized.#6156 — keep loader dispatch hooks across base-module restore
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()reattaches that snapshot after removing the temporary disk-offload hooks.undo_offload_to_disk()is a no-op for modules that were never actually offloaded (below the 4 KiB cutoff or tensor-less, e.g.model.norm/rotary_emb) instead of stripping their unrelated hooks.Conflict resolution
undo_offload_to_disk()now computes one predicate — a tree was offloaded iff it still has meta leaves or a disk-offload hook — and both rules hang off it:detach_hook([BUG] LLaVA / Gemma 3 VL: in-session generate() after quantize() crashes with the default offload_to_disk (vision-tower buffers and small modules left on CUDA) #6180).There is one early return, not two competing ones. The skipped-module release in
_offload_disk_locked()is what makes the #6156 no-op path safe for #6180: the skipped module has already been moved to CPU by the time the restore visits it.Files
gptqmodel/utils/offload.pytests/test_offload_base_modules_restored.pytests/test_offload_quantized_modules_restored_4450.pyTests
CPU-only (as required; the #6180 node is CUDA-marked and skips):
Both new nodes on one CUDA device (
CUDA_VISIBLE_DEVICES=1):Lint:
/root/venv/bin/ruff check gptqmodel/utils/offload.py \ tests/test_offload_base_modules_restored.py \ tests/test_offload_quantized_modules_restored_4450.py # All checks passed!Red evidence on the combined branch
Both test files kept, combined source reverted (
git checkout origin/main -- gptqmodel/utils/offload.py).#6156 node
#6180 node
Green evidence
With the combined source restored, the CPU-only family is
181 passed, 20 skipped, the two test files on CUDA are21 passed, and both new nodes pass individually (test_restore_offloaded_modules_preserves_loader_dispatch_hooksandtest_llava_offload_hook_round_trip_leaves_no_accelerator_tensors).Skips / unverified
requantize()device mismatch itself was not reproduced end-to-end; [BUG] requantize: on a 2-GPU dispatched checkpoint, offload_to_disk restore strips the dispatch hooks from model.norm / rotary_emb / lm_head, so in-session generate() crashes (#6132 follow-up) #6156 is verified at the hook level, including hook-object identity, on CPU and one CUDA device.embed_scale/ rotaryinv_freqgo through the same generic offload/restore paths.Supersedes
Closes #6225 and #6242, which edited the same
undo_offload_to_disk()region.