Repository navigation
Refactor-tokenization-more - #42563
Merged
Merged
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
ArthurZucker
force-pushed
the
refactor-tokenization-more
branch
from
December 3, 2025 15:07
c339cc8 to
7fd3d4f
Compare
…tor-tokenization-more
…tor-tokenization-more
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: albert, auto, barthez, bert, big_bird, blenderbot, camembert, clip, clvp, code_llama, codegen, cohere, deberta, deberta_v2, distilbert, dpr |
SangbumChoi
pushed a commit
to SangbumChoi/transformers
that referenced
this pull request
Jan 23, 2026
* On commit to bind them all * nits * smnall update * elif * super small nit * BPE! * fix * up up up * fix? * one typo * per model updates * more model specific updates * more per model updates * more model specific updates * simplify default merges * fiuxp * update * update * style * fix * fix colpali * nits * simpler regex + big shitty bird * fixup and fix * fix codellama * up * fix pop on none * fix parkeet * fix llama * big fixup * fix markul lm * update common * fix mbart * fix seamlessm4T * fix comment * torch tests * nnits and revert UNK idx change * oh only one deberta * torch tests * add convert from spm per model! * fix last 2 for pegasus * fix torch tests * fixes * fix tests * check versioned files * fix processor auto test * fix custom tok clip * try this fix * modeling rag * fix rag * roformer the Tokenizers way * up * updatge * fix unk * update * fix roberta * if there is no mapped class and no tokenizer.json its fucked -> just have the mapped class ready! * fix the rest * fix copies * fix doc and copies * fix mbart50 * fix deberta_v2 test * fix and simplify whisper :) * fix big bird default was worng * fix final * fixup * small nit * a weird way to fix fuyu? * default xlm roberta to fix kosmo behaviour! * remove small errors * last fix? * fix pixtral * style * fix * quality ta radce * fix? * remove something * remov one code that shouldd not have been there! * fix ? * fixup * update * fix for custom code * add a custom model path to make sure custom stuff is registe * fix trust remote code * exceeded * don't * ouppsy for cohere * why is this one also affected * fixup * fixup * nits * fix idefics3 tests * okay read the processor * fix the layout.... models * nits * codellama needs the bos passed * fix dpr * fix? * fixup * distilbert defaults * fix * clvp update to PythonTokenizer * bloom * style * layoutxlm * style * olmo * only pop when we don't convert from tokenizer.json * fixup * hub issue * id * fix --------- Co-authored-by: itazap <[email protected]> Co-authored-by: [email protected] <[email protected]>
tomaarsen
reviewed
Jan 26, 2026
Comment on lines
-2085
to
-2093
| # If tokenizer_file exists and tokenizer has a TokenizersBackend, replace the blank tokenizer with tokenizer.json | ||
| if tokenizer_file is not None and hasattr(tokenizer, "_tokenizer"): | ||
| from tokenizers import Tokenizer as TokenizerFast | ||
|
|
||
| tokenizer._tokenizer = TokenizerFast.from_file(tokenizer_file) | ||
| # Re-run post-initialization if the tokenizer has it | ||
| if hasattr(tokenizer, "_post_init"): | ||
| tokenizer._post_init() | ||
| # If only SPM exists, try to get vocab and merges and init to load a tokenizers-backend |
Member
There was a problem hiding this comment.
I believe this code should not have been removed. Opening a PR now.
2 of 5 tasks
Closed
2 of 4 tasks
Closed
4 tasks
ydshieh
added a commit
that referenced
this pull request
Aug 15, 2026
…retrained `_from_pretrained` strips `add_bos_token`/`add_eos_token` from init_kwargs when a tokenizer.json is present, so `TokenizersBackend.__init__` sees no explicit bos/eos kwargs and skips calling `update_post_processor()`. For GPTNeoX (which rebuilds its Rust tokenizer from scratch rather than loading it directly from tokenizer.json), the post_processor from the JSON file is applied as-is and is never overridden — causing OLMo-7B to receive an unexpected EOS token appended to every input, producing garbage generation. Restore the explicit `update_post_processor()` call at the end of `GPTNeoXTokenizer.__init__` so the Rust post_processor always reflects the `add_bos_token`/`add_eos_token` settings. Regression introduced by #42563 (commit 73a13f8). Fixes OlmoIntegrationTest::test_model_7b_greedy_generation producing `.1.1.1.1.1...` garbage instead of coherent text. Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
ydshieh
added a commit
that referenced
this pull request
Aug 15, 2026
…ned (OLMo garbage generation) (#47988) [GPTNeoX] Fix post_processor not being overridden when loading from pretrained `_from_pretrained` strips `add_bos_token`/`add_eos_token` from init_kwargs when a tokenizer.json is present, so `TokenizersBackend.__init__` sees no explicit bos/eos kwargs and skips calling `update_post_processor()`. For GPTNeoX (which rebuilds its Rust tokenizer from scratch rather than loading it directly from tokenizer.json), the post_processor from the JSON file is applied as-is and is never overridden — causing OLMo-7B to receive an unexpected EOS token appended to every input, producing garbage generation. Restore the explicit `update_post_processor()` call at the end of `GPTNeoXTokenizer.__init__` so the Rust post_processor always reflects the `add_bos_token`/`add_eos_token` settings. Regression introduced by #42563 (commit 73a13f8). Fixes OlmoIntegrationTest::test_model_7b_greedy_generation producing `.1.1.1.1.1...` garbage instead of coherent text. Co-authored-by: ydshieh <[email protected]>
This was referenced Aug 20, 2026
PranshulSoni
added a commit
to PranshulSoni/transformers
that referenced
this pull request
Sep 5, 2026
…t-processor disagree huggingface#42563 stripped add_bos_token/add_eos_token from the init kwargs whenever a tokenizer.json exists, and huggingface#47988 restored GPT-NeoX's unconditional update_post_processor() call to fix allenai/OLMo-7B-hf. Together they break checkpoints of the opposite polarity: blab-jhu/test-32m-dec declares add_bos_token: true next to a [CLS]...[SEP] template, so the flag-driven rebuild with stripped flags dropped the [CLS] prefix and shifted every recorded ModernBertDecoder integration expectation (failing on main since huggingface#47988). _from_pretrained now keeps the flags, and update_post_processor reconciles per side: a side whose flag is explicitly declared follows the flag, an undeclared side keeps the serialized behavior, and a backend without a serialized TemplateProcessing rebuilds exactly as before. Verified against real checkpoints (blab-jhu restored to the recorded contract, OLMo-7B-hf keeps the huggingface#47988 fix, llama-2/mistral/pythia/gpt-neox-20b/OLMo-2 unchanged) and added offline regression fixtures covering both polarities.
2 of 4 tasks
tarekziade
added a commit
that referenced
this pull request
Sep 7, 2026
…the rebuild Skipping `update_post_processor()` whenever `tokenizer.json` ships a post-processor makes the call added by #47988 dead code -- the base class already updates the post-processor in exactly those cases (`_should_update_post_processor`, `tokenization_utils_tokenizers.py`) -- so it reintroduces the OLMo bug. Verified on `allenai/OLMo-7B-hf`: with that patch every input gets `<|endoftext|>` appended again. The actual root cause is that `_from_pretrained` drops `add_bos_token`/`add_eos_token` from the init kwargs when a `tokenizer.json` is present, so #47988 rebuilds the post-processor from flags that have just been erased. The result is "no bos, no eos" for every GPTNeoX checkpoint: correct for OLMo (which saves `false`/`false`), wrong for any checkpoint whose post-processor adds special tokens -- `blab-jhu/test-32m-dec` went from `[CLS] Paris is the capital of` to `Paris is the capital of`. Keep the flags for the tokenizers whose class opts in, and let the base class rebuild the post-processor from them. This restores the pre-#42563 behaviour on both checkpoints (verified locally): - `allenai/OLMo-7B-hf` (`add_bos_token=false`, `add_eos_token=false`): no EOS appended. - `blab-jhu/test-32m-dec` (`add_bos_token=true`): `[CLS] Paris is the capital of`, i.e. 6 tokens. The trailing `[SEP]` its `tokenizer.json` adds is the same pathology as OLMo's EOS on a causal LM, and 6 was the expected value from #38967 until #43764 bumped it to 7 as collateral of the tokenizer refactor. The expected logit slices are unchanged, as only the trailing token disappears. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
3 of 4 tasks
5 tasks
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.
What does this PR do?
TokenizersBackendto simplify converting from sentencepiece.modelattribute to guide the conversion.convert_from_spmfor special cases when the spm is not straight forward.