Implement nucleus (top-pp) sampling with correct renormalization and edge cases

Inference & Serving3 / 5

Chapter 243 / 5

Inference & Serving

Implement nucleus (top-pp) sampling with correct renormalization and edge cases

Medium
Target interface
top_p_sample(probs, p=0.9, rng=None)

Implement the function/class skeleton in the editor. Any correct approach is accepted.

Hints0 / 2
Reference solution
Your own code stays in the editor.