Add warning for stop string edge case #33169
Merged
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.
In #31435 @murray-z mentions that the stop string code can throw an error with an unusual stop string: "✿RESULT✿"
The underlying cause is that the ✿ token doesn't exist in the tokenizer vocabulary anywhere. The tokenizer in question has a special-case fallback for unknown characters where it builds them out of other tokens, but the tokens it uses to compose unknown characters have different meanings when considered alone. This means that the stop string code can't figure out how to build the stop string out of the tokenizer vocabulary, because it doesn't have access to the internal special-casing logic.
I can't really see a general solution here without completely rewriting the stop string code to run
tokenizer.decode()
at each generation step, which would break the ability to compile generation or export it to non-Python environments. Since it's a fairly rare edge case, though, I'm just going to add a proper error message instead!cc @LysandreJik