Skip to content

Fix missing f-prefix in _normalize_token error message#722

Open
HumphreySun98 wants to merge 1 commit into
google-deepmind:mainfrom
HumphreySun98:fix/normalize-token-error-message
Open

Fix missing f-prefix in _normalize_token error message#722
HumphreySun98 wants to merge 1 commit into
google-deepmind:mainfrom
HumphreySun98:fix/normalize-token-error-message

Conversation

@HumphreySun98

Copy link
Copy Markdown

Summary

_normalize_token() in gemma/gm/text/_sampler.py raises a ValueError
when a stop_token / forbidden_token string does not map to a single
token id. The message string was missing its f prefix, so {token!r}
was printed literally instead of interpolating the offending token,
making these misconfigurations hard to debug.

Fixes #658.

Change

-        'Invalid token: {token!r}. `stop_token`s and `forbidden_token`s must'
+        f'Invalid token: {token!r}. `stop_token`s and `forbidden_token`s must'

The second (implicitly concatenated) line has no placeholders, so it is
left unchanged.

Testing

Added test_normalize_token_error_message_includes_token, which drives the
error path with a fake tokenizer and asserts the message names the token.
Verified it is a real regression guard — it fails on the pre-fix code
and passes with the fix.

$ python -m pytest gemma/gm/text/_sampler_test.py -q
5 passed

The ValueError raised in _normalize_token() when a stop/forbidden token
does not map to a single token id used a plain string, so the {token!r}
placeholder was emitted literally instead of the offending token value,
making misconfigurations hard to debug.

Add the missing f-prefix and a regression test asserting the message
names the token.

Fixes google-deepmind#658
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.

Bug: Missing f-prefix in error message in _normalize_token() makes stop_tokens debugging impossible

1 participant