Skip to content

fix(hf): mark v2 qzeros runtime layout on bridge load (#4952) - #4980

Merged
Qubitium merged 1 commit into
mainfrom
fix/issue-4952
Nov 17, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/issue-4952

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #4952.

Root cause

hf_convert_gptq_v1_to_v2_format (the HF bridge post-init) recorded _checkpoint_format_on_disk = GPTQ_V2 for a v2 checkpoint but returned early without calling qzero_format(2). The module therefore kept the constructor placeholder _qzeros_format = 1 while its live words were v2, and checkpoint_layout_qzeros() applied the v1->v2 +1 correction to already-v2 words on state_dict()/save_pretrained(). The persistent qzeros_format buffer was also left as uninitialized memory on the HF path.

Fix

gptqmodel/utils/model.py, inside hf_convert_gptq_v1_to_v2_format:

  • FORMAT.GPTQ_V2: call module.qzero_format(format=2) on every GPTQQuantLinear after recording _checkpoint_format_on_disk — marks the runtime layout and initializes the persistent marker without touching the words.
  • FORMAT.GPTQ: keep the existing conditional v1->v2 conversion, then initialize the marker (qzero_format(1)) only on modules the conversion did not already mark.
  • Return (model, converted) instead of the early returns, so the v1 marker init always runs.

The native GPTQModel.load path is unchanged; only the HF bridge calls this helper.

Before / after (tiny v2 checkpoint, AutoModelForCausalLM bridge)

before after
_runtime_qzeros_format() 1 2
qzeros_format buffer 3516303411600 (uninit) 2
state_dict()["...qzeros"] == disk False True
save_pretrained qzeros max diff vs disk 286331153 (0x11111111) 0
reloaded logits max diff 0.2509765625 0.0

v1 is unchanged: runtime 2, marker 2, save max diff 0, logits identical.

Tests

New tests/test_hf_bridge_v2_save_qzeros_4952.py (4 cases): v1 and v2 HF load->save->reload qzeros bytes + logits, and state_dict() round-trip identity for both. Red on parent: 2 failed, 2 passed (the two v2 cases). Green: 4 passed.

test_checkpoint_interop_4053.py 27 passed / 1 skipped; test_hf_gptqmodel_load_bridge.py 30 passed; test_qzeros_format_invariant.py 7 passed; test_inmemory_qzero_format.py 3 passed. test_hf_awq_bridge_import_order_4795.py has 1 environmental failure (test_plain_transformers_load_honors_dynamic_awq_on_cuda cannot build the Marlin JIT: nvcc/cuda_toolkit.h header mismatch), identical on parent. ruff check gptqmodel tests: clean.

Residual risk

  • Other GPTQ-family kernels with a private runtime layout (Marlin, ExLlamaV2, Machete, BitBLAS) are GPTQQuantLinear subclasses and now get qzero_format(2), but their own save paths still use their private-layout marker/refusal; the mark changes neither their words nor their save contract.
  • The fix relies on GPTQQuantLinear owning the qzeros convention; AWQ/FP8/GGUF save paths are untouched.
  • The test loads through AutoModelForCausalLM after importing gptqmodel. The mid-import fix(hf): install and repair the AWQ load bridge independent of import order (#4795) #4839 repair path is AWQ-specific and not re-exercised here, but it reaches the same hf_gptqmodel_post_init_for_load hook.

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

Labels

None yet

Projects

None yet

1 participant