Top-p Sampling (Nucleus)
2026/3/9小于 1 分钟
Top-p Sampling (Nucleus)
题面
实现核采样(top-p):对 logits 做 softmax,按概率降序累加到阈值 p 的最小 token 集合作为核,重归一化后用给定随机种子在核内采样 token。
Implementation Requirements
- Use only native features (external libraries are not permitted)
- The solve function signature must remain unchanged
- 计算 softmax 时注意数值稳定性
Examples
见页面两组示例(不同 p/seed 情况)。
Constraints
- 3 ≤ vocab_size ≤ 50,000;-100.0 ≤ logits ≤ 100.0
- 0.0 < p ≤ 1.0;0 ≤ sampled_token < vocab_size
- Performance: vocab_size = 50,000