Skip to content

fix(writer): list definition-excluded linears for GPTQ HF interop - #6232

Closed
Qubitium wants to merge 1 commit into
mainfrom
fix/6163-issue
Closed

Qubitium wants to merge 1 commit into
mainfrom
fix/6163-issue

Conversation

@Qubitium

@Qubitium Qubitium commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #6163

Problem

LFM3's definition keeps the per-head sigmoid gate dense (self_attn.g_proj:!:nosrc), so a GPTQ checkpoint stores g_proj.weight. The writer only emitted quantization_config.modules_in_block_to_quantize when the config had dynamic -: exclusions. Optimum therefore built a quantized layer for every decoder nn.Linear, including g_proj: plain AutoModelForCausalLM.from_pretrained reported g_proj.{qweight,qzeros,scales,g_idx} MISSING and g_proj.weight UNEXPECTED. On this CPU-only runner the same plain-HF load failed in post-init with ValueError: TorchLinear: checkpoint g_idx is out of range ...; with the list injected by hand it loaded and kept g_proj dense.

Fix

  • Add _definition_dense_decoder_linears(owner, model): walks the live export shell for nn.Linear modules under extract_layers_node(), resolves each layer-relative path through the compiled ModulePlan, and returns the ones whose definition spec has quantize=False (a :! leaf).
  • _gptq_explicit_quantized_modules now emits the explicit inclusion list for dynamic -: exclusions or definition-declared dense decoder linears. The packed set still comes from find_modules(model, layers=[BaseQuantLinear]); the list is unchanged for models with neither source.
  • Document the definition-declared source in 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_hf

It quantizes and saves a tiny native LFM3 GPTQ checkpoint, then asserts:

  • modules_in_block_to_quantize is present, grouped, and covers every BaseQuantLinear;
  • both self_attn.g_proj names (layers 1 and 2) are absent from the list and do not match Optimum's name.endswith check;
  • the checkpoint keeps g_proj.weight and has no g_proj.qweight;
  • plain AutoModelForCausalLM.from_pretrained(..., device_map="cpu") loads the checkpoint, keeps g_proj as nn.Linear, and quantizes q_proj.

Red at HEAD (2d3261d)

CLONE=/root/openai-audit/issue-6163
cd "$CLONE/tests"
PYTHONPATH="$CLONE:$CLONE/tests" /root/venv/bin/python -m pytest \
  test_lfm3_local_port.py::test_gptq_save_declares_definition_excluded_gate_for_plain_hf -q -rs
E AssertionError: GPTQ checkpoint omitted the definition-declared dense `self_attn.g_proj`
E assert 'modules_in_block_to_quantize' in {'auto_dtype_cast': 'auto_nf12', 'bits': 4, ...}
1 failed in 8.94s

Manual plain-HF load of that checkpoint (no list) on CPU:

ValueError: TorchLinear: checkpoint g_idx is out of range for 2 scale group(s)
(got min=0, max=1952543845, valid [-2, 1])

Green after the fix

CLONE=/root/openai-audit/issue-6163
cd "$CLONE/tests"
CUDA_VISIBLE_DEVICES="" PYTHONPATH="$CLONE:$CLONE/tests" /root/venv/bin/python -m pytest \
  test_lfm3_local_port.py::test_gptq_save_declares_definition_excluded_gate_for_plain_hf -q -rs
1 passed, 1 warning in 32.67s

Affected family:

CLONE=/root/openai-audit/issue-6163
cd "$CLONE/tests"
CUDA_VISIBLE_DEVICES="" PYTHONPATH="$CLONE:$CLONE/tests" /root/venv/bin/python -m pytest test_lfm3_local_port.py -q -rs
# 37 passed, 1 warning in 30.60s

CUDA_VISIBLE_DEVICES="" PYTHONPATH="$CLONE:$CLONE/tests" /root/venv/bin/python -m pytest \
  module_tree/test_lfm3_local_port.py module_tree/test_lfm3_vl_local_port.py \
  module_tree/test_lfm3_omni_local_port.py test_lfm3_vl_local_port.py \
  test_lfm3_omni_local_port.py test_lfm3_support.py test_lfm3_native_coverage.py \
  test_split_by_layer_save.py test_writer_attention.py -q -rs
# 146 passed, 9 skipped in 56.75s

Skips: 6 missing /monster/data/model/LFM3* fixtures and 3 pre-existing SUPPORTED_SPLIT_BY skips. ruff check gptqmodel/models/writer.py tests/test_lfm3_local_port.py passed.

test_checkpoint_compat.py test_checkpoint_interop_4053.py: 49 passed, 1 failed (test_untied_lm_head_quantizes_and_reloads) on a heterogeneous-GPU device_map="auto" selection error; I reproduced the same failure at HEAD with this patch removed, so it is pre-existing and unrelated.

Not verified

  • CUDA/Marlin plain-HF loading of the real LFM3-1.7B checkpoint (CPU-only runner; tiny fixture used).
  • The GPU-marked dynamic-exclusion test in tests/test_auto_nf12_excluded_layers.py (same code path; the dynamic branch is unchanged).

Overlap

This edits gptqmodel/models/writer.py next 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_quantize logic is not modified.

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
@Qubitium

Copy link
Copy Markdown
Collaborator Author

Consolidated into #6269, which combines #6230, #6232 and #6233 on one branch because all three insert a helper into the same gptqmodel/models/writer.py block. All changes and tests from this PR are preserved there. Closing this draft in favor of the consolidated PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant