Skip to content

[BUG] fresh.load_state_dict(mod.state_dict()) from a v1-loaded module into a freshly built v2-runtime module still skips the v1→v2 conversion (incomplete fix of #4304) #4377

Closed

Description

@Qubitium

Severity: medium (silent corruption). Status: confirmed on an RTX 4090 at def6e61. Kind: incomplete fix of #4304. Commit 0189599 fixed only the assign=True trigger. The second trigger, described in the #4304 comment, is still present.

Where

gptqmodel/nn_modules/qlinear/__init__.py ~1763: if layout_code in (1, 2): if layout_code != self._runtime_qzeros_format(): .... The constructor sets _qzeros_format = 1 at :1371.

Cause

  • A module loaded from a v1 gptq checkpoint emits the marker qzeros_format=1 in its state_dict().
  • A freshly constructed TorchLinear, or any kernel with REQUIRES_FORMAT_V2, also reports runtime format 1.
  • So the incoming marker looks like it already matches. The v1 words are never converted, and the kernel decodes them as v2.

Repro

Use any small Llama quantized with QuantizeConfig(bits=4, group_size=128, sym=False) in format gptq:

import torch
from gptqmodel import GPTQModel, BACKEND
m = GPTQModel.load("<gptq v1 sym=False ckpt>", backend=BACKEND.TORCH, device="cuda:0")
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).to("cuda:0")
fresh.load_state_dict(mod.state_dict()); fresh.post_init(); fresh.eval()
x = torch.randn(3, mod.in_features, dtype=torch.bfloat16, device="cuda:0")
print(((fresh(x).float() - mod(x).float()).norm() / mod(x).float().norm()).item(), fresh.qzero_format(), mod.qzero_format())

Actual:

  • Relative error is 0.243.
  • fresh.qzero_format() is 1, while the source module's is 2.

Expected: about 0. Copying the same state dict into an already-loaded model gives 0.0.

Now fixed: assign=True and plain-copy loads into a loaded model both give a relative error of 0.0.


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

    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.

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

    @Qubitium
    CollaboratorAuthor

    Claimed. This issue is now owned by a dedicated worker; a fix PR referencing it will follow. Please avoid duplicating work on it in the meantime.

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