google-deepmind / google-deepmind/gemma
Chat_sampler script bug
- Dominant language
- Python
- Stars
- 5.7k
- Forks
- 1k
- Avg merge
- 10h 33m
- Merged PRs (30d)
- 2
Description
The _print_stream function had a bug where if the iterator was empty
(no states were yielded), the variable 'state' would be undefined when
accessed outside the loop, causing a NameError.
Changes:
- Track the last state during iteration in a separate variable (last_state)
- Add explicit check for empty iterator case and raise ValueError with clear message
- Preserve existing code structure with assignment to 'out' variable before return
This fixes a potential runtime error that could occur in edge cases where
the streaming iterator yields no states, such as early termination before
any states are produced.
Location: gemma/gm/text/_chat_sampler.py lines 223-240
I would be happy to make a pr for this issue for you to review. lmk!
Contributor guide
Assessment
This issue has not been assessed yet.