fix: guard BEGIN_OF_TOOL_RESPONSE for Gemma2 and fix f-string in _normalize_token#590
Open
ashiksharonm wants to merge 3 commits intogoogle-deepmind:mainfrom
Conversation
…malize_token Fixes google-deepmind#568: Sampler.sample() unconditionally accessed tokenizer.special_tokens.BEGIN_OF_TOOL_RESPONSE when building end_tokens for SamplerLoop. The _Gemma2SpecialTokens enum does not define this attribute (introduced in Gemma3 for tool/function calling), causing: AttributeError: type object '_Gemma2SpecialTokens' has no attribute 'BEGIN_OF_TOOL_RESPONSE' Fix: guard the token access behind hasattr() so it is only included when the tokenizer actually defines the attribute (i.e. Gemma3+). Also fixes google-deepmind#579: the ValueError raised by _normalize_token() used a plain string literal instead of an f-string, so the error message showed the literal text '{token!r}' rather than the actual token value. Added the missing f prefix. Added two regression tests in _sampler_test.py: - test_normalize_token_error_message_contains_token_value - test_sampler_gemma2_tokenizer_no_begin_of_tool_response
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
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.
Fixes #568: Sampler.sample() unconditionally accessed tokenizer.special_tokens.BEGIN_OF_TOOL_RESPONSE when building end_tokens for SamplerLoop. The _Gemma2SpecialTokens enum does not define this attribute (introduced in Gemma3 for tool/function calling), causing:
AttributeError: type object '_Gemma2SpecialTokens' has no attribute
'BEGIN_OF_TOOL_RESPONSE'
Fix: guard the token access behind hasattr() so it is only included when the tokenizer actually defines the attribute (i.e. Gemma3+).
Also fixes #579: the ValueError raised by _normalize_token() used a plain string literal instead of an f-string, so the error message showed the literal text '{token!r}' rather than the actual token value. Added the missing f prefix.
Added two regression tests in _sampler_test.py: