Skip to content

[BUG] load_state_dict(..., assign=True) of v1 qzeros into a v2-runtime kernel skips the v1→v2 conversion: silent corruption (regression from 08f1b2b) #4304

Closed

Description

@Qubitium

Severity: medium (silent corruption). Status: confirmed by repro. Kind: regression from 08f1b2b (the #4166 fix).

Where

gptqmodel/nn_modules/qlinear/__init__.py:1758: elif not self._incoming_qzeros_is_live(...) (helper at :1666).

Cause

  • The "is live" check runs after super()._load_from_state_dict.
  • With assign=True, the incoming checkpoint tensor has already become self.qzeros at that point, so incoming is live is true.
  • The loaded tensor is therefore treated as an accelerate refill, and the v1→v2 conversion is skipped.
  • torch DCP set_model_state_dict also uses assign=True for meta-device models, so it is affected too.

Repro

import safetensors.torch
from gptqmodel import GPTQModel, BACKEND
ckpt = "<local GPTQ v1 checkpoint dir, e.g. a Llama-3.2-1B-Instruct GPTQ 4bit g128>"
m = GPTQModel.load(ckpt, backend=BACKEND.TORCH)                     # PPL 9.57
sd = {k: v.cuda() for k, v in safetensors.torch.load_file(f"{ckpt}/model.safetensors").items() if k.endswith("qzeros")}
m.model.load_state_dict(sd, strict=False)                           # PPL 9.57; words converted 0x77777777 -> 0x88888888
m.model.load_state_dict(sd, strict=False, assign=True)              # PPL 1,206,986; words stay 0x77777777
  • Expected: both calls give the same result.
  • Before the regression: at 08f1b2b~1, assign=True gives PPL 9.57.

Found during an AI-assisted review (Claude Code, round 11) of 842d666; repros were run at that commit 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. self-assigned this
    on Nov 16, 2026
  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. Qubitium commented on Nov 16, 2026

    @Qubitium
    CollaboratorAuthor

    A second trigger without assign=True (confirmed at 842d666 by another reviewer):

    nn_modules/qlinear/__init__.py:1752 checks if layout_code != self._runtime_qzeros_format(): self._restore_qzeros_format(layout_code). This compares the incoming marker against the receiver's live layout from before the copy, not against the layout the kernel decodes.

    • A freshly constructed module always has _qzeros_format = 1 (constructor ~1367). That includes TorchLinear, Triton, TorchFused, Machete, W4A and the other kernels that decode v2.
    • So an incoming qzeros_format=1 payload is treated as already matching, and the v1 words are never converted.
    • Any module loaded from a v1 gptq checkpoint emits marker 1, so copying its state_dict() into a fresh module triggers this.
    m = GPTQModel.load("<GPTQ v1 checkpoint, sym=False>", backend=BACKEND.TORCH, device="cpu")
    mod = m.model.model.layers[0].self_attn.q_proj
    fresh = type(mod)(bits=mod.bits, group_size=mod.group_size, sym=mod.sym, desc_act=mod.desc_act,
                      in_features=mod.in_features, out_features=mod.out_features, bias=mod.bias is not None,
                      pack_dtype=mod.pack_dtype, format=mod.format)
    fresh.load_state_dict(mod.state_dict()); fresh.post_init(); fresh.eval()
    x = torch.randn(3, mod.in_features, dtype=mod.scales.dtype)
    print(((mod(x).float() - fresh(x).float()).norm() / mod(x).float().norm()).item())
    • At HEAD: relative error 0.0875 (max abs 0.98), and fresh.qzero_format() stays 1.
    • At 9dad249: 2.5e-4.
    • Unit-level variant: TorchLinear(format=GPTQ).pack() → state_dict() → fresh TorchLinear gives error 0.15.

    This re-breaks the v1↔v2 state_dict copy contract fixed in #4070/#4091. The same assign=True mechanism also corrupts W4AFP8 gptq_v2 re-saves (#4323).

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