Repository navigation
fix(models): stop rewriting a checkpoint's generation pad id on load (#6402) - #6411
Merged
Merged
Conversation
added 2 commits
November 29, 2026 14:42
…6402) #6386 copied the tokenizer's `pad_token_id` onto the loaded model's `generation_config` unconditionally. That discards a `generation_config.json` which pins a pad id, and turns an explicit `null` ("no pad token") into the tokenizer's id -- which changes `generate()` output. The backfill only ever existed to repair a config that an *empty* tokenizer had already rewritten (#6361). #6386 now rejects those tokenizers, and the repair happens on `config.pad_token_id` inside `load_explicit_tokenizer`, before the model is constructed, so the derived generation config already carries the repaired id. Copying the tokenizer's id over `generation_config` afterwards therefore undoes both the checkpoint policy and that repair. Drop the overwrite and document why nothing replaces it. Fixes #6402
Qubitium
marked this pull request as ready for review
November 29, 2026 15:22
This was referenced Nov 29, 2026
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 #6402
What was wrong
#6386 added this to
BaseQModel.__init__:The loader always resolves a tokenizer (from the checkpoint when the caller passes none) and hands it to
BaseQModel, so this ran on every load. It overwrote the checkpoint's owngeneration_config.json:151643→0in the ovisclip-qwen2policy);null("no pad token") became the tokenizer's id, which changesgenerate()output (qwen3marin: greedy/beam diverged at token index 10).pad_token_idis part of the generation policy, not a tokenizer detail, so a load must not rewrite it.Why the block can simply go
The backfill only ever existed to repair a config that an empty tokenizer had already rewritten to
0(#6361). Since #6386:config.pad_token_idinsideload_explicit_tokenizer, which runs inload_hf_tokenizerbefore the model is constructed.The model therefore derives its generation config from the already-repaired model config, and
autofix_hf_model_configcarries that repaired id into the on-disk config. Copying the tokenizer's id overgeneration_configafterwards undoes both. Verified by #6361's own suite: itsexpected_pad_idis151662(<|fim_pad|>), not0, and those assertions stay green without the block.Regression test
tests/test_generation_pad_token_id_6402.py(CPU-only, tiny Qwen3 checkpoint + the sharedtests/tiny_tokenizer.pybyte-level BPE, whose pad id is0):checkpoint-pinned—generation_config.jsonpinspad_token_id: 1;checkpoint-unset—generation_config.jsonpinspad_token_id: null.Both assert the tokenizer really disagrees (
pad_token_id == 0), then that the checkpoint value survives the load.Red → green
Unpatched (block restored on the same tree):
The three issue nodes on unpatched
main:With the fix (rebased on
407298ad2, main merged in):(
test_generation_pad_token_id_6402.py+test_missing_tokenizer_6361.py+ all parametrizations of the two issue nodes.)Minimal pad-id probe after the fix:
Wider run
test_generation_config_do_sample.py,test_generation_compile_policy_4669.py,test_module_replacement_generation_config_5387.py: 28 passed.Scope
gptqmodel/models/base.py(deletion + the comment that explains why nothing replaces it) and one new test file.quantize()'s pad alignment is untouched: that path is only reached when the caller supplies a tokenizer, which is the documented #6361 repair.Draft — not merged, no labels applied.