Skip to content

Fix : division by zero in sampling when temperature is 0.0 #563

Open
KumarADITHYA123 wants to merge 1 commit intogoogle-deepmind:mainfrom
KumarADITHYA123:fix/zero-temperature-crash
Open

Fix : division by zero in sampling when temperature is 0.0 #563
KumarADITHYA123 wants to merge 1 commit intogoogle-deepmind:mainfrom
KumarADITHYA123:fix/zero-temperature-crash

Conversation

@KumarADITHYA123
Copy link

closes issue #562
This PR addresses a potential crash/undefined behavior where setting temperature=0.0 causes a division by zero in RandomSampling, TopkSampling, and TopPSampling.

Changes:

Added a guard clause to get_next_tokens in all three sampling classes.
If temperature < 1e-6, it now delegates to Greedy sampling (argmax), which is the expected behavior for zero temperature.
Added a unit test test_zero_temperature_behavior to _sampling_test.py to verify correctness.
This ensures deterministic output and prevents NaN or Inf values in logits when users explicitly request greedy decoding via temperature=0.0.

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