Repository navigation
refactor(writer): one ordered table for the save meta fields - #6666
Merged
Merged
Conversation
The save tail wrote nine `meta_set` calls by hand, three of them through inline GPTAQ/FOEM/JOINTQ payload builders. Replace them with one ordered `_SAVE_META_FIELDS` table of (key, getter) pairs and one `_stamp_save_meta` loop. `meta` is serialized in insertion order, so the table order is the checkpoint contract; the getters reproduce the old values exactly, including the `alpha`/`beta`/`device` payloads and the JointQ `meta_payload()`. No config source, value or write order changes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
7 tasks done
Qubitium
marked this pull request as ready for review
December 1, 2026 17:43
5 tasks done
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
The save tail in
ModelWriter.save_quantizedwrote ninemetaentries with nine hand-writtenmeta_setcalls, including three inline payload builders (GPTAQ, FOEM, JointQ). This PR replaces the block with one ordered table of(key, value-getter)pairs and one loop.metais serialized in insertion order intoquantize_config.json, so the table order is part of the checkpoint format. The getters reproduce the old values exactly and the saved bytes are unchanged; no config source, value, key order or public API changes.What Changed
gptqmodel/models/writer.py(1 file, +35/−66):_solver_meta(config, *fields)and_jointq_meta(config)for the three inline payload builders._SAVE_META_FIELDS, the ordered table:damp_percent,damp_auto_increment,static_groups,true_sequential,mse.norm,gptaq,foem,jointq,act_group_aware._stamp_save_meta(quantize_config);save_quantizednow calls it instead of the 66-line block (old lines 2726-2786).split_by="layer"writer is untouched.Tests
Save A/B
Harness kept out of the repo (
writer-meta-table.scratch/meta_ab.py): a tiny LlamaLlamaQModelwith a real packed quantized module, driven throughModelWriter.save_quantizedon both trees. Each case writesconfig.json,quantize_config.jsonandmodel.safetensors; the dump records the sha256 of every saved file plus themetakey order.Cases:
gptq_default,gptq_gptaq,gptq_foem,gptq_jointq(TorchLinear),awq(AwqGEMVTorchLinear),gguf,paro,exl3. The last three exercise non-GPTQ methods that add their own meta keys (AWQscale_search_chunked_activations, Paroopt_*, EXL3 tensor metadata).Real end-to-end CPU GPTQ (tiny 2-layer Llama,
GPTQModel.load->quantizewith 4 calibration rows onBACKEND.TORCH,device="cpu"->save):quantize_config.json,model.safetensors,config.json,generation_config.jsonand both tokenizer files are byte-identical main vs branch. Onlyquant_log.csvdiffers, and it also differs between two runs on the same tree (per-module timing/loss rows), so it is not an effect of this refactor.Measured Impact
Not applicable: behavior-preserving refactor with no runtime, memory or accuracy change (save A/B is byte-identical).
Model Support / Module Plan
Not applicable: no
MODEL_MAP, module-tree, plan or definition change; only the private save-tail meta writer inwriter.py.AWQ onboarding safety
Not applicable: no AWQ grouping, search, replay or fold change. AWQ appears only as a save A/B case, where the saved bytes are unchanged.
Logic Flow Documentation
The change replaces a straight-line write sequence with a declared ordered table; there is no decision, selection or tensor-lifecycle change.
flowchart LR A[save_quantized] --> B[_stamp_quantizer_meta] B --> C[_stamp_save_meta] C --> D[_SAVE_META_FIELDS in order] D --> E["damp_percent .. act_group_aware"]writer.py:2726-2786: ninemeta_setcalls, three inline payload builderswriter.py:889-897:_SAVE_META_FIELDStable;writer.py:900-903:_stamp_save_metaloopalpha+device(str-normalized)_solver_meta(..., "alpha")alpha/beta+device_solver_meta(..., "alpha", "beta")jointq_cfg.meta_payload()_jointq_meta(...)No docs page: the table is the complete specification of a fixed write order with no branch to diagram.
Review Requirements
Kernel Accuracy Requirements
Not applicable: no kernel, dispatch or fusion change.
Notes
_stamp_quantizer_meta;save_quantizedcalls it after the quantizer fingerprint, preserving the exact insertion order.split_by="layer"writer was left untouched.🤖 Generated with Claude Code