Repository navigation
fix(hf): mark v2 qzeros runtime layout on bridge load (#4952) - #4980
Merged
Merged
Conversation
This was referenced Nov 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4952.
Root cause
hf_convert_gptq_v1_to_v2_format(the HF bridge post-init) recorded_checkpoint_format_on_disk = GPTQ_V2for a v2 checkpoint but returned early without callingqzero_format(2). The module therefore kept the constructor placeholder_qzeros_format = 1while its live words were v2, andcheckpoint_layout_qzeros()applied the v1->v2+1correction to already-v2 words onstate_dict()/save_pretrained(). The persistentqzeros_formatbuffer was also left as uninitialized memory on the HF path.Fix
gptqmodel/utils/model.py, insidehf_convert_gptq_v1_to_v2_format:FORMAT.GPTQ_V2: callmodule.qzero_format(format=2)on everyGPTQQuantLinearafter 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.(model, converted)instead of the early returns, so the v1 marker init always runs.The native
GPTQModel.loadpath is unchanged; only the HF bridge calls this helper.Before / after (tiny v2 checkpoint,
AutoModelForCausalLMbridge)_runtime_qzeros_format()qzeros_formatbuffer3516303411600(uninit)state_dict()["...qzeros"] == disksave_pretrainedqzeros max diff vs disk286331153(0x11111111)0.2509765625v1 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, andstate_dict()round-trip identity for both. Red on parent: 2 failed, 2 passed (the two v2 cases). Green: 4 passed.test_checkpoint_interop_4053.py27 passed / 1 skipped;test_hf_gptqmodel_load_bridge.py30 passed;test_qzeros_format_invariant.py7 passed;test_inmemory_qzero_format.py3 passed.test_hf_awq_bridge_import_order_4795.pyhas 1 environmental failure (test_plain_transformers_load_honors_dynamic_awq_on_cudacannot build the Marlin JIT:nvcc/cuda_toolkit.hheader mismatch), identical on parent.ruff check gptqmodel tests: clean.Residual risk
GPTQQuantLinearsubclasses and now getqzero_format(2), but their own save paths still use their private-layout marker/refusal; the mark changes neither their words nor their save contract.GPTQQuantLinearowning the qzeros convention; AWQ/FP8/GGUF save paths are untouched.AutoModelForCausalLMafter importinggptqmodel. 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 samehf_gptqmodel_post_init_for_loadhook.