Skip to content

[GPTNeoX] Fix post_processor not overridden when loading from pretrained (OLMo garbage generation) - #47988

Merged
ydshieh merged 1 commit into
mainfrom
fix_gpt_neox_post_processor
Aug 15, 2026
Merged

ydshieh merged 1 commit into
mainfrom
fix_gpt_neox_post_processor

Conversation

@ydshieh

@ydshieh ydshieh commented Aug 15, 2026 •

Copy link
Copy Markdown
Collaborator

CI

Root cause

GPTNeoXTokenizer has a custom __init__ that rebuilds the Rust backend tokenizer from scratch using vocab/merges, rather than loading it directly from tokenizer.json. Because of this, convert_to_native_format extracts the post_processor from tokenizer.json and 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_pretrained also strips add_bos_token/add_eos_token from init_kwargs whenever a tokenizer.json is present, on the assumption that the post_processor inside is the source of truth and should not be overridden. This causes TokenizersBackend.__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 from tokenizer.json is applied to the rebuilt tokenizer and then never overridden, even when tokenizer_config.json says add_eos_token: false.

For OLMo-7B, the tokenizer.json was saved with a TemplateProcessing post_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, since update_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 explicit self.update_post_processor() call that was at the end of the old GPTNeoXTokenizer.__init__. That call was the only thing ensuring the Rust post_processor matched add_bos_token=False, add_eos_token=False.

Fix

Restore self.update_post_processor() at the end of GPTNeoXTokenizer.__init__ with an explanatory comment.

Verification

Tested on A10G runner across all 4 relevant states:

9a6df2ce9c (last good commit, before regression):

input_ids: [[4749, 2881, 1691, 13, 253, 3762, 273, 39241, 3054, 326, 209]]
output:    "Simply put, the theory of relativity states that \nthe speed of light is
            the same for all observers.\n\nThe theory of relativity is a theory of
            physics that describes the \nmovement of objects in space and time.\n\n"

✅ PASS

73a13f86f6 (regression commit, #42563):

input_ids: [[4749, 2881, 1691, 13, 253, 3762, 273, 39241, 3054, 326, 209, 50279]]
                                                                            ^^^^^ spurious EOS
output:    "Simply put, the theory of relativity states that  .1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1"

❌ FAIL (same bug present on main)

main (same bug as 73a13f86f6):

input_ids: [[4749, 2881, 1691, 13, 253, 3762, 273, 39241, 3054, 326, 209, 50279]]
                                                                            ^^^^^ spurious EOS
output:    "Simply put, the theory of relativity states that  .1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1.1"

❌ FAIL

main + this fix:

input_ids: [[4749, 2881, 1691, 13, 253, 3762, 273, 39241, 3054, 326, 209]]
output:    "Simply put, the theory of relativity states that \nthe speed of light is
            the same for all observers.\n\nThe theory of relativity is a theory of
            physics that describes the \nmovement of objects in space and time.\n\n"

✅ 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). Their tokenizer.json uses a ByteLevel post_processor (which adds no tokens), so calling update_post_processor() with add_bos_token=False, add_eos_token=False produces the same token IDs as before.

The full tests/models/gpt_neox/ test suite passes with RUN_SLOW=1 (223 passed, 109 skipped).

Notes

This fix was discovered because allenai/OLMo-7B-hf's tokenizer.json has an unusual TemplateProcessing post_processor that adds EOS — which the canonical GPT-NeoX repos (e.g. EleutherAI/gpt-neox-20b) do not have. For those, the regression in 73a13f86f6 was a silent no-op.

There are arguably two sides to the fix:

  1. Transformers side (this PR): the regression removed update_post_processor() unintentionally; restoring it is correct regardless of OLMo.
  2. Hub repo side: allenai/OLMo-7B-hf's tokenizer.json has a TemplateProcessing post_processor that adds EOS while tokenizer_config.json says add_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)

@ydshieh

ydshieh commented Aug 15, 2026

Copy link
Copy Markdown
Collaborator Author

run-slow: gpt_neox

@github-actions

Copy link
Copy Markdown
Contributor

Workflow Run ⚙️

This comment contains run-slow, running the specified jobs:

models: ["models/gpt_neox"]
quantizations: []

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

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.

@github-actions

Copy link
Copy Markdown
Contributor

CI Results

Workflow Run ⚙️

Commit Info

Context Commit Description
RUN ccb8885c workflow commit (merge commit)
PR e0d77e3b branch commit (from PR)
main 96fe6dce base commit (on main)

✅ No failing test specific to this PR 🎉 👏 !

…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
ydshieh force-pushed the fix_gpt_neox_post_processor branch from e0d77e3 to 608f9a6 Compare August 15, 2026 12:27
@github-actions

Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: gpt_neox

@github-actions

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 31883204204:1
Result: success | Jobs: 1 | Tests: 94 | Failures: 0 | Duration: 4m 40s

@ydshieh

ydshieh commented Aug 15, 2026 •

Copy link
Copy Markdown
Collaborator Author

Going to merge this directly to get OLMo generation working and unblock the CI fix in #47986.

Rationale:

  • Two other tokenizers (code_llama, splinter) still use update_post_processor(), so the pattern is not forbidden.
  • The full tests/models/gpt_neox/ suite passes with RUN_SLOW=1 (223 passed), confirming nothing is broken for the canonical GPT-NeoX models.

We can discuss separately whether to update the OLMo Hub repo files to make tokenizer.json consistent with tokenizer_config.json.

@ydshieh
ydshieh merged commit ce5c8f5 into main Aug 15, 2026
30 checks passed
@ydshieh
ydshieh deleted the fix_gpt_neox_post_processor branch August 15, 2026 12:38
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]>
@itazap

itazap commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

#48641

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants