Skip to content

Validate top-k sampling bounds - #789

Open
sylvesterkaczmarek wants to merge 2 commits into
google-deepmind:mainfrom
sylvesterkaczmarek:fix/topk-sampling-k-validation
Open

Validate top-k sampling bounds#789
sylvesterkaczmarek wants to merge 2 commits into
google-deepmind:mainfrom
sylvesterkaczmarek:fix/topk-sampling-k-validation

Conversation

@sylvesterkaczmarek

Copy link
Copy Markdown

Summary

TopkSampling.get_next_tokens() currently passes k directly to JAX. Invalid values fail with low-level errors: k=0 produces an empty candidate set and categorical sampling fails, while negative values and values larger than the vocabulary fail inside jax.lax.top_k.

This validates k against the available vocabulary size before calling JAX and raises a clear ValueError for invalid values.

Testing

  • Added parametrized coverage for k=0, k=-1, and k larger than the vocabulary size.
  • Existing top-k and top-1/greedy sampling tests remain unchanged.

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