Repository navigation
Conversation
LFM3 keeps self_attn.g_proj dense with a definition :! flag, but the writer only emitted modules_in_block_to_quantize for dynamic -: rules. Optimum then built a quantized layer for every nn.Linear in the block, so plain HF loading reported g_proj.qweight/qzeros/g_idx MISSING and g_proj.weight UNEXPECTED. Derive the definition-declared dense linears inside the decoder blocks from the compiled module plan and emit the exact quantized set whenever one exists. The list still comes from the same plan that decided not to quantize those leaves. Fixes #6163
Collaborator
Author
This was referenced Nov 29, 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 #6163
Problem
LFM3's definition keeps the per-head sigmoid gate dense (
self_attn.g_proj:!:nosrc), so a GPTQ checkpoint storesg_proj.weight. The writer only emittedquantization_config.modules_in_block_to_quantizewhen the config had dynamic-:exclusions. Optimum therefore built a quantized layer for every decodernn.Linear, includingg_proj: plainAutoModelForCausalLM.from_pretrainedreportedg_proj.{qweight,qzeros,scales,g_idx}MISSING andg_proj.weightUNEXPECTED. On this CPU-only runner the same plain-HF load failed in post-init withValueError: TorchLinear: checkpoint g_idx is out of range ...; with the list injected by hand it loaded and keptg_projdense.Fix
_definition_dense_decoder_linears(owner, model): walks the live export shell fornn.Linearmodules underextract_layers_node(), resolves each layer-relative path through the compiledModulePlan, and returns the ones whose definition spec hasquantize=False(a:!leaf)._gptq_explicit_quantized_modulesnow emits the explicit inclusion list for dynamic-:exclusions or definition-declared dense decoder linears. The packed set still comes fromfind_modules(model, layers=[BaseQuantLinear]); the list is unchanged for models with neither source.docs/quantization-features.md.No model or module names are hardcoded; the list is sourced from the same module plan that decided not to quantize the leaf.
Test
New node:
tests/test_lfm3_local_port.py::test_gptq_save_declares_definition_excluded_gate_for_plain_hfIt quantizes and saves a tiny native LFM3 GPTQ checkpoint, then asserts:
modules_in_block_to_quantizeis present, grouped, and covers everyBaseQuantLinear;self_attn.g_projnames (layers 1 and 2) are absent from the list and do not match Optimum'sname.endswithcheck;g_proj.weightand has nog_proj.qweight;AutoModelForCausalLM.from_pretrained(..., device_map="cpu")loads the checkpoint, keepsg_projasnn.Linear, and quantizesq_proj.Red at HEAD (2d3261d)
Manual plain-HF load of that checkpoint (no list) on CPU:
Green after the fix
Affected family:
Skips: 6 missing
/monster/data/model/LFM3*fixtures and 3 pre-existingSUPPORTED_SPLIT_BYskips.ruff check gptqmodel/models/writer.py tests/test_lfm3_local_port.pypassed.test_checkpoint_compat.py test_checkpoint_interop_4053.py: 49 passed, 1 failed (test_untied_lm_head_quantizes_and_reloads) on a heterogeneous-GPUdevice_map="auto"selection error; I reproduced the same failure at HEAD with this patch removed, so it is pre-existing and unrelated.Not verified
tests/test_auto_nf12_excluded_layers.py(same code path; the dynamic branch is unchanged).Overlap
This edits
gptqmodel/models/writer.pynext to the in-flight #6182 (block_name_to_quantize) and #6166 (defused gate/up naming) changes. Only the inclusion-list decision is touched;block_name_to_quantizelogic is not modified.