Repository navigation
Description
Summary
The LFM3 definition (#3496) deliberately leaves the per-head sigmoid gate self_attn.g_proj (nn.Linear(2048, 16)) unquantized ("g_proj:!:nosrc"), and the GPTQ checkpoint stores it as a dense g_proj.weight. The writer adds modules_in_block_to_quantize to config.json only when the config has dynamic -: exclusions (_gptq_explicit_quantized_modules → has_dynamic_exclusions()). Exclusions that come from the model definition never get it. Optimum then builds a quantized layer for every nn.Linear in the decoder blocks, including g_proj. Plain Transformers loading of a freshly quantized LFM3-1.7B therefore reports g_proj.qweight/qzeros/scales/g_idx MISSING and g_proj.weight UNEXPECTED, and on CUDA it crashes in post-init. With a backend that does not crash, the attention gates would be randomly initialized instead.
GPTQModel.load of the same checkpoint works (PPL 28.50, coherent). Adding the explicit module list by hand fixes plain HF loading exactly (same PPL). save() logs no hf_compat_warnings entry for this checkpoint.
Introduced by
974644d (#3496, LFM3 support with g_proj unquantized), together with the writer rule from #4086 that emits modules_in_block_to_quantize only for dynamic -: exclusions. The same gap applies to any definition that marks a decoder-block nn.Linear with :!.
Location
HEAD 8ebe255, gptqmodel/models/writer.py:429-433:
if getattr(quantize_config, "method", None) not in (METHOD.GPTQ, METHOD.ADMMQ):
return None
if not quantize_config.has_dynamic_exclusions():
return None
return [sorted(find_modules(model, layers=[BaseQuantLinear]))]gptqmodel/models/definitions/lfm3.py:74: "g_proj:!:nosrc",
Reproduction (ran on RTX 4090, torch 2.15, transformers 5.23, optimum installed)
from gptqmodel import GPTQModel, GPTQConfig, CalibrationConfig
m = GPTQModel.load("LiquidAI/LFM3-1.7B", GPTQConfig(bits=4, group_size=128)) # native lfm3, trust_remote_code=False
m.quantize(CalibrationConfig(dataset=c4_texts[:128], batch_size=1)); m.save("lfm3-gptq")
from transformers import AutoModelForCausalLM
AutoModelForCausalLM.from_pretrained("lfm3-gptq", device_map="cuda:0")Output:
model.layers.{2...22}.self_attn.g_proj.weight | UNEXPECTED |
model.layers.{2...22}.self_attn.g_proj.qweight | MISSING |
model.layers.{2...22}.self_attn.g_proj.g_idx | MISSING |
model.layers.{2...22}.self_attn.g_proj.scales | MISSING |
model.layers.{2...22}.self_attn.g_proj.qzeros | MISSING |
File ".../optimum/gptq/quantizer.py", line 624, in post_init_model
File "gptqmodel/utils/model.py", line 2193, in hf_gptqmodel_post_init
...
NotImplementedError: GPTQ Marlin: checkpoint g_idx is non-contiguous but `desc_act` is False. Activation-order decoding requires tile-aligned shapes; got K=2048, N=16. Load with a non-Marlin backend.
Same checkpoint:
GPTQModel.load: 142 MarlinLinear and 12 dense Linear (11g_projpluslm_head), wikitext2 PPL 28.50 (bf16 source 25.38).- With
quantization_config.modules_in_block_to_quantize = [[<the 142 quantized module names>]]added toconfig.jsonby hand,AutoModelForCausalLM.from_pretrainedloads 142 MarlinLinear and 12 Linear, PPL 28.5011, identical to native, with the same generation.
Expected vs actual
Expected: a GPTQ checkpoint whose definition leaves some decoder nn.Linear unquantized carries the exact quantized set, so Transformers/Optimum load it like native (the writer already does this for dynamic exclusions). If that is not possible, save() should at least warn.
Actual: no module list is written and no warning is logged. Plain HF loading crashes on CUDA, and would otherwise randomly initialize the excluded linears.
Suggested fix
In _gptq_explicit_quantized_modules, also return the explicit list whenever the layer blocks contain an nn.Linear that is not a BaseQuantLinear, for example from a definition :! leaf or any unquantized linear under the layers prefix. Do not require has_dynamic_exclusions(). Add an LFM3 save → AutoModelForCausalLM.from_pretrained test.
Activity
fix(writer): HF/vLLM interop for dense towers, excluded linears and d…
fix(writer): HF/vLLM interop for dense towers, excluded linears and d…