Implement Top-p (Nucleus) Sampling in PyTorch

Mediumllm-decodingauto-graded

Sort logits, compute cumulative probabilities, mask tokens below the nucleus threshold, and sample from the filtered distribution.

Solve it

Check your answer

The grader verifies properties of your implementation, so a correct solution written differently from ours still passes.

pip install torchleet

from torchleet import check
check("top-p-sampling", top_p_sample)

Company tags

How these tags are sourced