Skip to content

[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

Closed

Description

@Qubitium

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

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

from gptqmodel import GPTQModel, QuantizeConfig
cal = [...]  # ~128 text samples, e.g. from c4
text = "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=True
m.quantize(cal, batch_size=8)
ids = m.tokenizer(text, return_tensors="pt")
print(m.model(**ids, labels=ids["input_ids"]).loss)                         # in-session
m.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.

Activity

  1. added
    bug
    on Nov 16, 2026
  2. Qubitium commented on Nov 16, 2026

    @Qubitium
    CollaboratorAuthor

    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
    
    1. 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.
    2. Stuck on the CPU: the in-session model can't be moved to the GPU, so it can only run on the CPU. There it falls into the slow CPU fp16 GEMM (item 3 of [MEM] CUDA default alloc conf (expandable_segments + max_split_size_mb:256) grows reserved VRAM per layer during GPTQ (1B: 5.4 GiB reserved for 1.23 allocated; 8B: ~45 GiB), AllSpark keeps both weight layouts resident, CPU fp16 TorchLinear ~120x slow GEMM #4389), so a single 512-token wikitext window took 131–147 s.

    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.

    🤖 Generated with Claude Code

  3. Qubitium commented on Nov 16, 2026

    @Qubitium
    CollaboratorAuthor

    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.

  4. self-assigned this
    on Nov 16, 2026
  5. Qubitium commented on Nov 16, 2026

    @Qubitium
    CollaboratorAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions