11/29
Part 3 of 6 · Top-kLearn and do

Equal scores can let more than k through

A threshold compare has one edge case: ties.

ties = torch.tensor([[2.0, 1.0, 1.0, 0.0]])
print(keep_top_k(ties, 2))
Predict

ties is [2.0, 1.0, 1.0, 0.0] and k = 2, so the threshold is 1. How many tokens stay?

Pick one to see what it prints.
Pick an answer above to see the rest
Predict

400 rows of random logits over GPT-2's 50,257 tokens, cut to the top 50. In float32, every row keeps exactly 50. Round the rows to bf16. How many keep more than 50?

Pick one to see what it prints.
Pick an answer above to see the rest