Skip to content

Conversation

@arJ-V
Copy link

@arJ-V arJ-V commented Nov 25, 2025

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

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
@arJ-V arJ-V mentioned this pull request Nov 25, 2025
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.

1 participant