Repository navigation
fix(exl3): resolve head_bits against tied output heads (#6347) - #6354
Merged
Merged
Conversation
#6224 made `head_bits` imply `lm_head=True` in `EXL3Config.__post_init__`. The config cannot know whether the loaded model ties its output head to the input embedding, so `ModuleLooper` refused the request on tied models after the model was loaded and calibration was prepared. Keep the implication for untied models, but resolve it against the real model before any calibration work: - implied `head_bits` on a tied head warns, keeps the head tied, and records `lm_head=False` so the saved config matches the tensors it wrote; - explicit `lm_head=True` on a tied head keeps the hard error, now raised by `quantize()` instead of deep inside the loop; - explicit `lm_head=False` is respected, so a tied checkpoint reloads with a dense head instead of claiming a packed one; - an untied model still schedules and packs the head at `head_bits`. Fixes #6347
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #6347
Mechanism
#6224 (0558c6e) made
head_bitsimplylm_head=TrueinsideEXL3Config.__post_init__. The config cannot know whether the loaded modelties its output head to the input embedding, so
ModuleLooperhit itslm_head-with-tied-weights refusal after the model was loaded and thecalibration dataset was prepared:
That turned a configuration that used to work (tied head stays with the
embedding) into a late hard failure on Llama-3.2-1B/3B, Qwen2.5-0.5B..3B,
Qwen3-0.6B..4B, Gemma, SmolLM, and every other small tied model.
Contract
head_bitsremains an implied head request (so #6224 is preserved), but theimplication is resolved against the real model before calibration:
head_bits=N(defaultlm_head=None)lm_head=FalseNhead_bits=N, lm_head=TrueNotImplementedError, now raised before calibrationNhead_bits=N, lm_head=Falselm_head=False, head_bits=NoneWhy this contract:
writes
lm_head=False; if__post_init__still forcedlm_head=Trueforany
head_bits,QuantizeConfig.from_quant_config()would claim a packedhead that the checkpoint never wrote.
lm_head=Noneis therefore the"not requested" sentinel, and an explicit
Falsesurvives the round-trip.head_bits: the implied tied case logs awarning that names the shared weight, the consequence, and the opt-in
(untie before
quantize(), or load an untied-head checkpoint). Theexplicit-
lm_head=Falsecase logs that the recorded rate is not applied.BaseQModel.quantize()resolvesthe request before
_prepare_calibration_before_rotation()and before_quantize_with_calibration()prepares the calibration batches.ModuleLooper._loop_impl()keeps the same resolution for callers thatdrive the looper directly.
changes the checkpoint layout; that is an explicit user choice, not a
side effect of a rate option. The warning tells the user how to do it.
Red -> green
New
tests/test_exl3_head_bits_tied_6347.py(CPU only, no CUDA packer):head_bits=6NotImplementedError: ... tied weightsfrom_loop_impllm_head=Falselm_head=Truetiedquantize()preflightlm_head=False+head_bitslm_headis forced toTruehead_bits=6HookedLinear, packerK=6vs projectionK=4lm_head=False, head_bits=NoneThe file is red at origin/main (
4 failed, 2 passed) and green here(
6 passed). Cases (b) and (c) are preserved-behavior guards, so they passon both revisions; the regression cases are (a) and the two explicit-request
variants. Because EXL3 packing itself is CUDA/HIP-only, the test drives the
real
ModuleLooperhead-resolution/planning path with a real tiny Llama onCPU and asserts the rate that reaches
EXL3Processor._build_quant_args; itnever calls the CUDA quantizer.
Verification
All
test_exl3_*.py test_exllama*.py:576 passed, 650 skipped(GPU-only),no failures. Full
tests/qcfg:268 passed.ruff checkon the changed files: clean.module_tree/test_deepseek_v41_flash.pyfails 7 tests / errors 9 on thisbranch and identically on origin/main (
_gptqmodel_checkpoint_selectionunsupported argument); it is unrelated and pre-existing.
Manual GPU smoke test (RTX 4090, not part of the CPU test)
Tiny 2-layer tied Llama,
EXL3Config(bits=4, head_bits=6, device="cuda:0"):quantize()warns, setslm_head=False, and keepslm_heada tiedLinear(256, 128)that shares storage withembed_tokens;q_projbecomesExllamaV3Linear;logits (1, 4, 256), finite).Tiny untied Llama, same config:
lm_head=True, and the head becomesExllamaV3Linearwith trellis(8, 16, 96)(6-bit);q_projisExllamaV3Linear;Existing test update
tests/test_exl3_fractional_bits.py::test_head_bits_overrides_an_explicit_lm_head_falseis renamed to
test_head_bits_respects_an_explicit_lm_head_falseand nowasserts
lm_head is False. The old assertion encoded the reload bug: a tiedrun saves
lm_head=Falsewith itshead_bits, and forcing the implicationback to
Trueon load makes the loader expect a packed head the checkpointnever wrote.