You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] In-session use after quantize() with the default offload_to_disk=True gives garbage GPTQ output: offloaded layers are reloaded with v1 qzeros but decoded as v2 (incomplete fix of #4203) #4380
Severity: high. It is silent, it happens with the default config, and it is the exact symptom #4203 was filed for. Status: confirmed on an RTX 4090 at def6e61. Kind: incomplete fix of #4203 (46ae741). The qzeros mismatch already exists at 842d666; 46ae741 removed the crash that used to hide it.
Where
gptqmodel/utils/offload.py:506 and :532: _offload_disk_locked bundles module.state_dict(), and then disk_offload(...) installs accelerate hooks on that bundle.
The accelerate hook loads those tensors directly into the module, with no v1→v2 conversion. The live module still reports qzero_format()==2, so TorchLinear decodes every zero point off by one.
Evidence
Inside the forward of model.layers.0.self_attn.q_proj:
qzeros_format buffer
Low nibbles
Offload on
1
7
Offload off
2
8
qweight, scales and g_idx are bit-identical between the two runs. The saved checkpoint is correct.
Repro
fromgptqmodelimportGPTQModel, QuantizeConfigcal= [...] # ~128 text samples, e.g. from c4text="The capital of France is Paris. It is known for the Eiffel Tower, which was built in 1889 for the World's Fair."m=GPTQModel.load("meta-llama/Llama-3.2-1B-Instruct", quantize_config=QuantizeConfig(bits=4, group_size=128)) # default offload_to_disk=Truem.quantize(cal, batch_size=8)
ids=m.tokenizer(text, return_tensors="pt")
print(m.model(**ids, labels=ids["input_ids"]).loss) # in-sessionm.save("out"); r=GPTQModel.load("out", device="cuda:0")
ids=ids.to("cuda:0"); print(r.model(**ids, labels=ids["input_ids"]).loss) # reloaded
Actual:
Model
In-session NLL
Reloaded NLL
fp16 NLL
Llama-3.2-1B-Instruct
14.06
1.65
1.61
Qwen2.5-0.5B-Instruct
17.61
1.59
1.58
Other models: on 3-layer truncations of Qwen3-0.6B, Qwen2.5, Llama-3.2, Gemma-3 and TinyLlama, in-session and reloaded logits differ by 14–35 max-abs, and Gemma-3 gives NaN. TinyLlama is untied, so this is not a tied-weights effect.
Generation: greedy generate repeats a single token.
Control: with offload_to_disk=False, the same scripts match the reload to within 0.008–0.03.
Expected: in-session output matches the reloaded checkpoint. The offload bundle should store, or be reloaded in, the runtime qzeros layout. Otherwise quantize() should refuse in-session use with a clear message.
Found during an AI-assisted review (Claude Code, round 12) of def6e61; repros were run at that commit (A/B against 842d666 where noted) on RTX 4090/5090 (CUDA 13) and/or Radeon AI PRO R9700 (ROCm) unless marked static/suspected.
A second problem in the same code path, which fixing only the v1/v2 decode would leave in place (verified at 5065bf1, RTX 4090, Qwen2.5-0.5B GPTQ 4-bit, default offload_to_disk=True):
The offloaded quantized layers stay disk-hooked after quantize() returns.#4295's _restore_offloaded_base_modules (looper/module_looper.py, and the same in weight_only_looper.py) only restores the base modules. All 168 quantized modules keep meta buffers plus the accelerate SequentialHook installed by utils/offload.py_offload_disk_locked:
devices: cpu/fp16 136M params (base), buf meta int32 45.3M / fp16 2.8M / int64 168 hooks: {'SequentialHook': 168}
fwd seq=64 on cpu: 18.46 s; disk loads per forward: 912 tensors, 178.3 MiB
hf.to("cuda") -> NotImplementedError: Cannot copy out of meta tensor; no data!
offload_to_disk=False: .to("cuda") works, forward 0.069 s
Disk reads per forward: every forward re-reads all quantized weights from safetensors. That is 178 MiB per forward here, and would be several GB per forward on an 8B model.
Fix: at loop exit, undo the offload for the quantized layers too (they are small packed tensors, which is what the offload_to_disk=False path already holds). Do it through load_state_dict, so _restore_qzeros_format runs, which also fixes the v1/v2 decode above. Tested: undo_offload_to_disk + .to("cuda") takes 0.1 s, but the output stays NaN until the format restore also runs (qzeros_format stays 1).
tests/test_offload_base_modules_restored.py uses a toy model with no quantized layers, so it can't see this.
Taking this. I'll investigate against current main, add a targeted regression test, and open a PR. Will report back here if the claim turns out to be invalid or already fixed.
Fixed in #4425: the disk-offload restore path now converts the bundle's checkpoint-layout qzeros to the module's live v2 layout, so in-session output matches the reloaded checkpoint.
Activity
Qubitium commentedon Nov 16, 2026
A second problem in the same code path, which fixing only the v1/v2 decode would leave in place (verified at 5065bf1, RTX 4090, Qwen2.5-0.5B GPTQ 4-bit, default
offload_to_disk=True):The offloaded quantized layers stay disk-hooked after
quantize()returns. #4295's_restore_offloaded_base_modules(looper/module_looper.py, and the same inweight_only_looper.py) only restores the base modules. All 168 quantized modules keep meta buffers plus the accelerateSequentialHookinstalled byutils/offload.py_offload_disk_locked:Fix: at loop exit, undo the offload for the quantized layers too (they are small packed tensors, which is what the
offload_to_disk=Falsepath already holds). Do it throughload_state_dict, so_restore_qzeros_formatruns, which also fixes the v1/v2 decode above. Tested:undo_offload_to_disk+.to("cuda")takes 0.1 s, but the output stays NaN until the format restore also runs (qzeros_formatstays 1).tests/test_offload_base_modules_restored.pyuses a toy model with no quantized layers, so it can't see this.🤖 Generated with Claude Code
Qubitium commentedon Nov 16, 2026
Taking this. I'll investigate against current
main, add a targeted regression test, and open a PR. Will report back here if the claim turns out to be invalid or already fixed.Qubitium commentedon Nov 16, 2026
Fixed in #4425: the disk-offload restore path now converts the bundle's checkpoint-layout qzeros to the module's live v2 layout, so in-session output matches the reloaded checkpoint.
fix: offload the live qzero layout so restored layers decode as v2 (#…
test: fix stale doubles/oracles in the suite-triage red list (#4769) (#…
Offload finalized modules as file-backed tensors instead of meta + ho…
tests: pin file-backed offload instead of meta + hook offload (#6471)
Remove accelerate: explicit WeightLoader for weight loading, placemen…