Repository navigation
Description
Summary
The #6224 fix (0558c6e, #6246) makes head_bits imply lm_head=True: EXL3Config.__post_init__ now sets self.lm_head = True unconditionally whenever head_bits is given. The looper refuses lm_head=True on any model whose output head is tied to the input embeddings. So every EXL3 quantize that passes head_bits on a tied model now fails after the model is loaded and calibration has been prepared:
INFO Estimated Quantization BPW (bits per weight): 4 bpw, based on [bits: 4, head_bits: 6]
File "gptqmodel/models/base.py", line 3681, in quantize
File "gptqmodel/models/base.py", line 4492, in _quantize_with_calibration
File "gptqmodel/looper/module_looper.py", line 2074, in loop
File "gptqmodel/looper/module_looper.py", line 2196, in _loop_impl
NotImplementedError: quantization of `lm_head` layer with tied weights is not supported. Untie the model weights before quantization.
Before the fix the same config quantized normally: the decoder was EXL3 4-bit and the tied head stayed with the embedding. Tied heads are the norm for small models (Llama-3.2-1B/3B, Qwen2.5-0.5B/1.5B/3B, Qwen3-0.6B..4B, Gemma, SmolLM), and head_bits is the knob users copy from exllamav3 recipes. The user never asked for lm_head=True, so the error tells them to "untie the model weights", which a config option cannot do. The only way around it is to drop head_bits.
On untied models the fix works as intended. TinyLlama EXL3Config(bits=4, head_bits=6) now gives a 6-bit ExllamaV3Linear head (trellis [128, 2000, 96]), saves, reloads and generates (PPL 11.95).
Introduced by
0558c6e (#6246, "fix(exl3): honor head_bits and reload injected dynamic rules (#6224, #6216)").
Location (HEAD 42827b6, unchanged on origin/main be14824)
gptqmodel/quantization/config.py:10858-10862 (EXL3Config.__post_init__):
# `head_bits` is EXL3's request to quantize the output head
...
self.lm_head = Truegptqmodel/looper/module_looper.py:2192-2199:
if self.gptq_model.quantize_config.lm_head:
if self._lm_head_is_tied():
raise NotImplementedError(
"quantization of `lm_head` layer with tied weights is not supported. "
"Untie the model weights before quantization."
)Reproduction (ran it: RTX 5090, transformers 5.23, torch 2.15)
from datasets import load_dataset
from gptqmodel import GPTQModel, CalibrationConfig
from gptqmodel.quantization import EXL3Config
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(512)) if len(r["text"]) > 300][:64]
qc = EXL3Config(bits=4, head_bits=6)
print(qc.lm_head, qc.head_bits) # True 6 (was False 6)
m = GPTQModel.load("unsloth/Llama-3.2-1B-Instruct", qc) # tie_word_embeddings=True
m.quantize(CalibrationConfig(dataset=calib, batch_size=4))- HEAD 42827b6:
NotImplementedError: quantization of lm_head layer with tied weights is not supported ...(traceback above). - Parent 89dbcf9, same script: quantize, save and reload succeed. Head is the tied
Linear, output' Paris. The Eiffel Tower is a famous landmark in', wikitext-2 PPL 20.46 (BOS prepended per window).
Checkpoints written before the fix with head_bits and a dense head ("lm_head": false) still load at HEAD. I checked TinyLlama: dense head, same PPL 11.936, so that direction is fine.
Expected vs actual
- Expected:
head_bitsquantizes the head where that is possible, as the [BUG] EXL3Config(head_bits=N) without lm_head=True is accepted, logged and saved, but the output head is never quantized (stays dense BF16), with no warning #6224 fix intended, and does not turn a previously valid tied-model config into a hard failure. For a tied model the head rate cannot apply, so warn and leave the head with the embedding (or reject it at config/load time with a message that nameshead_bits). - Actual: quantize() raises after load and calibration preparation, and the message refers to
lm_head, which the user did not set.
Suggested fix
Do not force lm_head=True in EXL3Config.__post_init__, because the config cannot know whether the model is tied. Resolve it in the looper instead: when head_bits is set and lm_head was not explicitly requested, quantize the head only if _lm_head_is_tied() is false. Otherwise log a warning that head_bits is ignored for a tied head, and keep lm_head=False in the saved config. Keep the hard error only for an explicit lm_head=True. Add an EXL3 head_bits test on a tied tiny model.
Activity
fix(exl3): resolve head_bits against tied output heads (ModelCloud#6347…
fix: repair three merge-wave regressions (EXL3 numeric validation, fi…
test: repair three stale test fixtures on main 1615acc (#6401)