Repository navigation
fix(awq): load dynamic AWQ checkpoints on transformers 5.23 (#5322) - #5335
Merged
Merged
Conversation
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
Transformers 5.23 tightened
core_model_loading.set_param_for_module: acheckpoint tensor whose shape differs from the meta module is now recorded as a
mismatched key unless the active quantizer reports
param_needs_quantizationfor it.
AwqQuantizerinherits the base implementation, which always returnsFalsebecause a pre-quantized checkpoint has nothing to quantize. A GPT-QModel AWQ
checkpoint with
dynamicper-modulegroup_sizetherefore builds its modulesfrom the global
group_size, the checkpoint's widerqzeros/scalesarerecorded as MISMATCH, and
_finalize_model_loadingraisesYou set ignore_mismatched_sizes to False ...beforepostprocess_modelcanrun
hf_gptqmodel_repair_awq_load. The documented plainAutoModelForCausalLM.from_pretrainedflow indocs/peft.mdfails for everydynamicAWQ checkpoint on 5.23.Fixes #5322
What Changed
gptqmodel/utils/hf_load.py_hf_quantization_config_is_native_awq: reads the livequantization_configand decides provenance (explicitgptqmodelquantizer entry,
meta.uri, or adynamicmap). An explicitoptimumorthird-party quantizer entry wins, so another tool's
dynamicfield is notreinterpreted.
hf_gptqmodel_awq_tolerated_mismatch: accepts a mismatch only for one ofqweight/qzeros/scales/g_idx/biason aBaseQuantLinearin anative AWQ checkpoint. Dense parameters and unknown paths stay reported.
gptqmodel/__init__.py: the AWQ bridge wrapper also wrapsAwqQuantizer.param_needs_quantizationwith that guard. The accepted tensorsare then rebuilt from the serialized per-module config by the existing
post-weight repair, so the result still matches
GPTQModel.load.docs/hf-interop.md: new "Transformers 5.23 mismatch gate" section withbefore/after flow and situation table; failure-contract and test tables
extended.
docs/peft.md: notes that the repair now survives the 5.23 load check.tests/test_hf_awq_dynamic_mismatch_5322.py: new fast unit test.No API change. Transformers <= 5.22 behavior is unchanged (the old check was
already skipped whenever a quantizer was active), and the guard is inert for
GPTQ and third-party AWQ checkpoints.
Tests
The 5.23 red/green pair runs the CPU and CUDA nodes of the issue's test: both
fail on the unpatched tree and pass with it, with the rebuilt modules'
group_size/qzerosshape and NLL matchingGPTQModel.load.Skips: none. Both nodes ran on their real device.
Model Support / Module Plan
Not applicable: no model type, alias, definition, or module plan change.
AWQ onboarding safety
Not applicable to quantization math/grouping: this changes only how an HF load
accepts an already-serialized checkpoint's tensors. No source/consumer
relationship, scale search, or replay context changes. The repaired modules are
still built from the manifest and verified against
GPTQModel.loadintests/test_hf_awq_bridge_import_order_4795.py.Logic Flow Documentation
The change alters a load decision (which shape mismatches are accepted), so the
flow is documented in
docs/hf-interop.md("Transformers 5.23 mismatch gate"),already linked from the interop section of
README.md.flowchart TD A["plain AutoModelForCausalLM.from_pretrained"] --> B["AwqQuantizer builds modules from the global config"] B --> C["core_model_loading.set_param_for_module"] C --> D{"shape differs and param_needs_quantization false?"} D -->|"before 5.23: quantizer active"| E["assign tensor, continue"] D -->|"5.23: not quantizing"| F["mismatched_keys"] F --> G["_finalize_model_loading raises"] G --> H["post-weight repair never runs"] C --> I["patched param_needs_quantization"] I --> J{"native GPT-QModel AWQ and a packed buffer of a packed module?"} J -->|"yes"| E J -->|"no"| D style G fill:#f8d7da,stroke:#b02a37 style E fill:#d9f2d9,stroke:#2e7d32Replaced mechanism: the unconditional
hf_quantizer is Noneearly-exit intransformers/core_model_loading.py:1458-1461(5.23), whose new conditionnot hf_quantizer.param_needs_quantization(...)is now answered by the bridge.Review Requirements
Kernel Accuracy Requirements
Not applicable: no kernel, fusion, or dispatch change.
Notes
dynamicAWQ path on Transformers 5.23. Thepre-existing contract is unchanged: a per-expert AWQ checkpoint still needs
import gptqmodelbeforefrom_pretrained, because those tensors areUNEXPECTED rather than shape-mismatched.
convert_modelbuilds the per-module geometry before tensors are assigned.That path was not modified.