19/29
Part 4 of 5 · Precision and top-kLearn and do

Anthropic switched to exact top-k, at a minor cost

While investigating, Anthropic found that exact top-k no longer had the prohibitive performance penalty it once had. So it switched from approximate to exact top-k, and standardized some additional operations on fp32.

The reason, in one line: "Model quality is non-negotiable, so we accepted the minor efficiency impact."

One footnote matters if you've tuned sampling. The now-correct top-k may cause slight differences in which tokens make it in near the top-p threshold. In rare cases, users may benefit from re-tuning their top-p.

Here is why. Top-k usually runs before top-p. Once top-k has cut the candidates, top-p is a share of what top-k kept. So changing the top-k step can move the top-p set at its edge.

In the editor, write nucleus(probs, kept, p): top-p on whatever top-k kept. EXACT is the true top 4, and APPROX is an approximate top 4 that lost this, so the two top-p sets at p = 0.8 differ.