Skip to content

[BUG] writer/HF interop: GPTQ checkpoints of models whose definition keeps a decoder nn.Linear unquantized (LFM3 self_attn.g_proj) omit modules_in_block_to_quantize, so AutoModelForCausalLM.from_pretrained fails on them #6163

Done

Description

@Qubitium

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 (11 g_proj plus lm_head), wikitext2 PPL 28.50 (bf16 source 25.38).
  • With quantization_config.modules_in_block_to_quantize = [[<the 142 quantized module names>]] added to config.json by hand, AutoModelForCausalLM.from_pretrained loads 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions