Fix StopStringCriteria byte fragment matching#46522
Closed
he-yufeng wants to merge 1 commit into
Closed
Conversation
Contributor
|
View the CircleCI Test Summary for this PR: https://huggingface.co/spaces/transformers-community/circle-ci-viz?pr=46522&sha=d3f6fb |
Member
|
No drive-by code agent PRs when the original issue author is still working on it, please! |
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
StopStringCriteriafor byte-level BPE tokens that contain only part of a UTF-8 character.ByteLevel vocab entries are now converted back to their underlying bytes during criterion preprocessing, and stop strings are matched in UTF-8 byte units for those tokenizers. The existing tensor-only runtime matcher is reused unchanged, so
StopStringCriteria.__call__remains compatible with compiled generation.This covers CJK stop strings whose final character is split across multiple byte-fragment tokens while preserving the existing behavior for non-ByteLevel tokenizers and stops that do not overlap the final token.
Closes #46519.
Coordination and duplicate search
The implementation direction was coordinated in #46519:
#46519 (comment)
Before opening this PR I searched open PRs for
46519,StopStringCriteria byte fragment, and the affected symbols. I found no overlapping implementation.Validation
pytest tests/generation/test_stopping_criteria.py -q -k stop_string(6 passed)ruff check src/transformers/generation/stopping_criteria.py tests/generation/test_stopping_criteria.pyruff format --check src/transformers/generation/stopping_criteria.py tests/generation/test_stopping_criteria.pygit diff --checktorch.compile(criteria, backend="eager", fullgraph=True)on the fragmented CJK caseThe full stopping-criteria test file also reached 13 passing tests before an unrelated local environment failure from missing optional
torchvision.AI assistance
AI assistance was used to inspect the tokenizer/runtime behavior, implement the patch, and run the validation above. I reviewed the changed code and the resulting behavior.