Repository navigation
[GPTNeoX] Fix post_processor not overridden when loading from pretrained (OLMo garbage generation) - #47988
Merged
Conversation
Collaborator
Author
|
run-slow: gpt_neox |
Contributor
|
This comment contains models: ["models/gpt_neox"] |
|
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. |
…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
force-pushed
the
fix_gpt_neox_post_processor
branch
from
August 15, 2026 12:27
e0d77e3 to
608f9a6
Compare
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: gpt_neox |
Contributor
CI recapDashboard: View test results in Grafana |
Collaborator
Author
|
Going to merge this directly to get OLMo generation working and unblock the CI fix in #47986. Rationale:
We can discuss separately whether to update the OLMo Hub repo files to make |
This was referenced Sep 3, 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.
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]>
Collaborator
Closed
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.
Root cause
GPTNeoXTokenizerhas a custom__init__that rebuilds the Rust backend tokenizer from scratch using vocab/merges, rather than loading it directly fromtokenizer.json. Because of this,convert_to_native_formatextracts the post_processor fromtokenizer.jsonand passes it to__init__so it can be applied to the rebuilt tokenizer — this is how the serialized post_processor settings are preserved.However,
_from_pretrainedalso stripsadd_bos_token/add_eos_tokenfrominit_kwargswhenever atokenizer.jsonis present, on the assumption that the post_processor inside is the source of truth and should not be overridden. This causesTokenizersBackend.__init__to never see those kwargs →explicit_bos_eos_in_kwargs = False→_should_update_post_processor = False→update_post_processor()is never called. The net result: the post_processor fromtokenizer.jsonis applied to the rebuilt tokenizer and then never overridden, even whentokenizer_config.jsonsaysadd_eos_token: false.For OLMo-7B, the
tokenizer.jsonwas saved with aTemplateProcessingpost_processor that appends<|endoftext|>(EOS, ID 50279) after every sequence. It is unclear why the repo has it — it was never actually in effect before the regression, sinceupdate_post_processor()was always called and overrode it (and the model worked correctly). After the regression, it is applied as-is and silently corrupts every input.Regression introduced
Commit
73a13f86f6("Refactor-tokenization-more", #42563, Dec 9 2025) removed the explicitself.update_post_processor()call that was at the end of the oldGPTNeoXTokenizer.__init__. That call was the only thing ensuring the Rust post_processor matchedadd_bos_token=False, add_eos_token=False.Fix
Restore
self.update_post_processor()at the end ofGPTNeoXTokenizer.__init__with an explanatory comment.Verification
Tested on A10G runner across all 4 relevant states:
9a6df2ce9c(last good commit, before regression):✅ PASS
73a13f86f6(regression commit, #42563):❌ FAIL (same bug present on
main)main(same bug as73a13f86f6):❌ FAIL
main+ this fix:✅ PASS
Impact on GPT-NeoX models
This change does not affect the GPT-NeoX models themselves (e.g.
EleutherAI/gpt-neox-20b,EleutherAI/pythia-410m-deduped). Theirtokenizer.jsonuses aByteLevelpost_processor (which adds no tokens), so callingupdate_post_processor()withadd_bos_token=False, add_eos_token=Falseproduces the same token IDs as before.The full
tests/models/gpt_neox/test suite passes withRUN_SLOW=1(223 passed, 109 skipped).Notes
This fix was discovered because
allenai/OLMo-7B-hf'stokenizer.jsonhas an unusualTemplateProcessingpost_processor that adds EOS — which the canonical GPT-NeoX repos (e.g.EleutherAI/gpt-neox-20b) do not have. For those, the regression in73a13f86f6was a silent no-op.There are arguably two sides to the fix:
update_post_processor()unintentionally; restoring it is correct regardless of OLMo.allenai/OLMo-7B-hf'stokenizer.jsonhas aTemplateProcessingpost_processor that adds EOS whiletokenizer_config.jsonsaysadd_eos_token: false— an inconsistency that only became observable after the regression removed the override. Ideally the Hub repo should also be corrected to keep things consistent.Related: #47986 (OLMo OOM fix — separate issue in same test file)