Repository navigation
Conversation
LLaVA and Gemma 3 VL pre-quantize hooks move the vision tower and small language-model modules onto the quantization device, then offload them to disk for the layer loop. offload_to_disk() skipped sub-4KB modules without moving them, and accelerate left non-persistent buffers (position_ids, rotary inv_freq) on the execution device. Restoring the model left those tensors on the accelerator while the rest was on CPU, so the first in-session image forward failed in position_embedding. Move skipped small modules to CPU, move non-persistent buffers of offloaded modules to the requested restore device after hook detach, and drop the no-op disk-offload root hooks left behind by child-by-child restore. Test: tests/test_offload_quantized_modules_restored_4450.py::test_llava_offload_hook_round_trip_leaves_no_accelerator_tensors
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.
Fixes #6180
Summary
The LLaVA and Gemma 3 VL pre-quantize hooks move
embed_tokens,norm,rotary_emb,vision_towerandmulti_modal_projectoronto the quantization device, then release them throughoffload_to_disk()for the layer loop. Two generic gaps left tensors behind on the accelerator:state_dict()is at or below the 4 KiB floor were skipped without being moved, so a small norm (and a rotary module whose only state is non-persistent buffers) stayed on CUDA.undo_offload_to_disk()only re-materialized meta leaves, soposition_idsandinv_freqstayed on CUDA after the rest of the module was restored to CPU.This PR:
offload_to_disk();detach_hookhas run;io_same_deviceroot hook thatdisk_offload()leaves on a module after its hooked children are restored one by one.Disk offload stays enabled for the layer loop; the memory benefit is unchanged.
Red evidence
Base
b95b4c6with only the new test (source fix reverted):cd /root/openai-audit/issue-6180/tests CUDA_VISIBLE_DEVICES=4 PYTHONPATH=/root/openai-audit/issue-6180:/root/openai-audit/issue-6180/tests \ /root/venv/bin/python -m pytest \ test_offload_quantized_modules_restored_4450.py::test_llava_offload_hook_round_trip_leaves_no_accelerator_tensors \ -q -rsThe same state also reproduced the reported end-to-end failure: a tiny local LLaVA fixture quantized with the default
offload_to_disk=Trueoncuda:0, then forwarded with an image:Green evidence
End-to-end tiny local LLaVA after the fix:
Lint:
/root/venv/bin/ruff check gptqmodel/utils/offload.py tests/test_offload_quantized_modules_restored_4450.py # All checks passed!Test
tests/test_offload_quantized_modules_restored_4450.py::test_llava_offload_hook_round_trip_leaves_no_accelerator_tensorsIt drives the real
LlavaQModel.pre_quantize_generate_hook_start/endpair on a tiny native LLaVA model, restores the disk-offloaded modules, asserts every parameter/buffer is on CPU and no offload hooks remain, then runs an image forward.Skips / unverified
embed_scaleand rotaryinv_freqtensors go through the same genericoffload_to_disk/undo_offload_to_diskpaths covered here.tests/test_llava_qwen2_local_port.pywas not run: this environment lackstimm(ImportErrorfromports/llava_qwen2/fastvit.py), unrelated to this change.