Repository navigation
fix(hf): restore instance-scoped save_pretrained layout guard (#6137) - #6144
Merged
Merged
Conversation
#4620 removed the PreTrainedModel.save_pretrained wrapper that entered checkpoint_serialization(), so an HF-loaded Marlin/ExLlamaV2 model wrote its irreversible runtime layout (tile/shuffled qweight, empty qzeros/g_idx) plus qzeros_format markers under an ordinary checkpoint_format: gptq config. The directory could not be reloaded by GPTQModel.load or Transformers. Attach the guard to the loaded model instance in hf_gptqmodel_post_init, the bridge Transformers' GPTQ/AWQ quantizers already call. It is instance-scoped, so no Transformers class is touched. Bridge saves now refuse on runtime-layout kernels with the #4134 error and drop qzeros_format for checkpoint-layout kernels; GPTQModel.load/GPTQModel.save and read-only state_dict() callers are unchanged.
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.
Summary
Fixes #6137.
#4620 removed the
PreTrainedModel.save_pretrainedwrapper that enteredcheckpoint_serialization(). After that, an HF-loaded Marlin/ExLlamaV2 modelwrote its private runtime layout (tile/shuffled
qweight, emptyqzeros/g_idx)and
*.qzeros_formatmarkers under an ordinarycheckpoint_format: gptqconfig. The directory could not be reloaded by
GPTQModel.loador byAutoModelForCausalLM.from_pretrained.This restores the refusal without patching Transformers:
hf_gptqmodel_post_init(the bridge Transformers' GPTQ and AWQ quantizers already call) now wraps
save_pretrainedon the loaded instance only. Notransformers.*class ormodule is touched, and
GPTQModel.loadmodels keep their existing writer path.What Changed
gptqmodel/utils/model.py: new_attach_checkpoint_serialization_save_guard()and a call from
hf_gptqmodel_post_init(). The wrapper is idempotent and runsthe original instance writer inside
checkpoint_serialization().from
_save_to_state_dictinstead of publishing an unloadable checkpoint.qzeros_formatruntime marker is dropped from the HF payload (fix(checkpoint): stop HF save_pretrained from writing qzeros_format markers (#4152) #4155).docs/checkpoint-interop.md: section 3 and its diagrams now describe thebridge-instance guard instead of claiming HF
save_pretrained()is read-only.tests/test_checkpoint_interop_4053.py: synthetic GPTQ checkpointloaded through
AutoModelForCausalLM; valid CPU round trip, Marlin andExLlamaV2 refusal, and a native
GPTQModel.save()control.Out of scope:
save_pretrainedon a model loaded byGPTQModel.loadis notwrapped (it is not the HF bridge, and an instance attribute there would make
torch.save(model)unpicklable).GPTQModel.save()remains the supportedwriter.
Tests
Environment:
/root/venv(torch 2.15.0+cu132, transformers 5.23.0),CUDA_VISIBLE_DEVICES=0on an RTX 4090 (sm89). No sm80 device was available inthis worker; the defect is in the save dispatch, not kernel arithmetic, and both
Marlin and ExLlamaV2 run natively here.
Green:
Lint (same command as CI):
/root/venv/bin/ruff check gptqmodel gptqmodel/models/ports/native/auto/__init__.py \ gptqmodel/models/ports/native/auto/_registry.py docs/eora tests setup.py # All checks passed!Red (new test file copied onto a clean worktree at
43b999585, fix absent):Real-model reproduction at HEAD (before the fix),
Qwen/Qwen2.5-0.5B-Instruct-GPTQ-Int4:After the fix the same script raises at save:
and leaves only
config.json/generation_config.json, nomodel.safetensors.Pre-#4620 confirmation:
git show 8c71625b5:gptqmodel/__init__.pydefines andcalls
_patch_transformers_save_pretrained_runtime_layout_guard(), whose wrapperruns
checkpoint_serialization()around the original writer;git show 6f9ad69e6documents the #4134 refusal. The old class-wide patch is not restored.Native writer control (
GPTQModel.save()on Marlin and ExLlamaV2, reload +forward parity):
Skips
test_checkpoint_state_invariant.py: machete, swordfish and bitblas runtimesare not installed in this venv.
torch.cuda.is_available()is false.