Fix stop string matching for byte-fragment tokens#46530
Merged
Rocketknight1 merged 1 commit intoJun 12, 2026
Conversation
96095c7 to
c27e608
Compare
Rocketknight1
approved these changes
Jun 11, 2026
Rocketknight1
left a comment
Member
There was a problem hiding this comment.
Yes, this is nice - keeps the public API but fixes byte-level issues internally without breaking compilation. It should have no effect for non-byte-level tokenizers too. I don't see any major flaws and tests pass, so I'm happy to merge!
|
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. |
c27e608 to
715eb12
Compare
Contributor
|
CI Dashboard: View test results in Grafana |
Merged
via the queue into
huggingface:main
with commit Jun 12, 2026
a16a9c7
119 of 120 checks passed
Contributor
Author
|
Thanks! Glad this landed — the byte-fragment case was subtle, and it’s good to have it covered now. |
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?
Fixes #46519.
This fixes a case where
StopStringCriteriacan miss stop strings with byte-level tokenizers. The full generated sequence decodes correctly, but some CJK characters are split into byte-fragment tokens, and decoding those tokens one by one can produce replacement characters instead. That means the text may visibly end with the stop string while the stopping criterion still does not match it.This PR handles this during preprocessing by building the matching table in byte space for ByteLevel and SentencePiece ByteFallback tokenizers. Non-byte tokenizers keep the existing string path.
StopStringCriteria.__call__is unchanged, so the runtime matching path stays tensor-only.I ran:
Local result:
19 passed.Code Agent Policy
The Transformers repo is currently being overwhelmed by a large number of PRs and issue comments written by
code agents. We are currently bottlenecked by our ability to review and respond to them. As a result,
we ask that new users do not submit pure code agent PRs at this time.
You may use code agents in drafting or to help you diagnose issues. We'd also ask autonomous "OpenClaw"-like agents
not to open any PRs or issues for the moment.
PRs that appear to be fully agent-written will probably be closed without review, and we may block users who do this
repeatedly or maliciously.
This is a rapidly-evolving situation that's causing significant shockwaves in the open-source community. As a result,
this policy is likely to be updated regularly in the near future. For more information, please read
CONTRIBUTING.md.Before submitting
Pull Request section?
Who can review?
cc @Rocketknight1