-
Notifications
You must be signed in to change notification settings - Fork 602
Open
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!
Metadata
Metadata
Assignees
Labels
No labels