Skip to content

[BUG] EXL3 + lm_head=True: the implicit lm_head rule {"bits": 8, "group_size": 32, ...} is saved into the EXL3 checkpoint, and GPTQModel.load then rejects the config (EXL3Config: group_size is not used) #6216

Done

Description

@Qubitium

Summary

EXL3Config(bits=4, head_bits=6, lm_head=True) quantizes an untied model and saves it without error. In-session the head is a real ExllamaV3Linear, and head_bits=6 is applied: the head trellis is [128, 2000, 96] int16, i.e. 16 x 6 words per tile. The saved checkpoint cannot be loaded again:

saved: {'bits': 4, 'head_bits': 6, 'lm_head': True,
        'dynamic': {'lm_head': {'bits': 8, 'group_size': 32, 'sym': True, 'desc_act': False, 'mse': 2.4}}}
GPTQModel.load(out) -> ValueError: EXL3Config: `group_size` is not used; keep it at `-1`.

ModuleLooper._loop_impl injects the GPTQ-style implicit head override {"bits": 8, "group_size": 32, "sym": True, "desc_act": False, "mse": 2.4} into quantize_config.dynamic for every method whenever lm_head=True. The EXL3 path never reads it: head_bits overrides bits, and group_size does not exist for EXL3. The override is still serialized. On reload, EXL3Config.__post_init__ validates dynamic and refuses group_size=32. So every EXL3 checkpoint quantized with lm_head=True fails to load. head_bits is documented as the EXL3 output-head option (docs/exl3-runtime-weights.md, "The same 1.5, 2.5 and 3.5 rates are accepted for head_bits"), and tests/test_exl3_fractional_bits.py builds configs with lm_head=True, head_bits=6. That test only round-trips a config built by hand. It never quantizes, so it never sees the injected rule.

Introduced by

Pre-existing. The implicit head rule dates from 98d1a05 (#1037) / 7939d1a (#1302) and is method-agnostic. The EXL3 dynamic group_size refusal has existed since the EXL3 config was added (renamed in 673cdce, #2690). Still present on origin/main b050965.

Location

gptqmodel/looper/module_looper.py:2189-2193 (87e424a):

            lm_head_quant_config = {"bits": 8, "group_size": 32, "sym": True, "desc_act": False, "mse": 2.4}
            if self.gptq_model.quantize_config.dynamic is None:
                self.gptq_model.quantize_config.dynamic = {self.gptq_model.lm_head: lm_head_quant_config}
            elif self.gptq_model.quantize_config.dynamic_get(self.gptq_model.lm_head, default=None) is None:
                self.gptq_model.quantize_config.dynamic[self.gptq_model.lm_head] = lm_head_quant_config

gptqmodel/quantization/config.py:10539-10540 (EXL3Config._normalize_dynamic_layer_config, called from __post_init__ at :10585 on load):

            elif key == "group_size" and value not in (-1, None):
                raise ValueError("EXL3Config: `group_size` is not used; keep it at `-1`.")

Reproduction (ran it: RTX 5090, 87e424a, transformers 5.23)

import json, torch
from datasets import load_dataset
from gptqmodel import GPTQModel, CalibrationConfig
from gptqmodel.quantization import EXL3Config
out = "tinyllama-exl3-head"
ds = load_dataset("allenai/c4", data_files="en/c4-train.00001-of-01024.json.gz", split="train")
calib = [r["text"] for r in ds.select(range(256)) if len(r["text"]) > 300][:32]
m = GPTQModel.load("TinyLlama/TinyLlama-1.1B-Chat-v1.0", EXL3Config(bits=4, head_bits=6, lm_head=True))
m.quantize(CalibrationConfig(dataset=calib, batch_size=4))
print("in-session head:", type(m.model.lm_head).__name__)
m.save(out)
qc = json.load(open(f"{out}/config.json"))["quantization_config"]
print("saved:", {k: qc[k] for k in ("bits", "head_bits", "lm_head", "dynamic")})
del m; torch.cuda.empty_cache()
GPTQModel.load(out)

Output:

in-session head: ExllamaV3Linear
saved: {'bits': 4, 'head_bits': 6, 'lm_head': True, 'dynamic': {'lm_head': {'bits': 8, 'group_size': 32, 'sym': True, 'desc_act': False, 'mse': 2.4}}}
  File "gptqmodel/models/loader.py", line 3469, in from_quantized
  File "gptqmodel/quantization/config.py", line 8166, in from_pretrained
  File "gptqmodel/quantization/config.py", line 8130, in from_quant_config
  File "gptqmodel/quantization/config.py", line 10585, in __post_init__
  File "gptqmodel/quantization/config.py", line 10540, in _normalize_dynamic_layer_config
ValueError: EXL3Config: `group_size` is not used; keep it at `-1`.

For comparison, GPTQ, AWQ and GGUF with lm_head=True on the same model all save, reload and re-save byte-identically.

Expected vs actual

Expected: an EXL3 checkpoint with a quantized head (rate from head_bits) reloads with GPTQModel.load.
Actual: quantize and save succeed, then every reload fails at config parsing. The only workaround is to hand-edit config.json / quantize_config.json.

Suggested fix

Make the implicit head rule method-aware. Skip it for EXL3, where head_bits is the head knob, or inject only keys the active config accepts (EXL3: none, or {"bits": head_bits}). Alternatively, strip keys the method does not use before serializing dynamic. Add an end-to-end EXL3 lm_head=True quantize -> save -> load 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