- Temperature and top-k commute. Dividing by a T above 0 never reorders the logits. So the same k tokens survive at any temperature, and the final weights come out the same in either order.
- Temperature and top-p don't. Top-p reads probabilities, and temperature changes them. Temperature first is the convention, so a high temperature widens the set of plausible tokens, instead of reweighting a set chosen at T = 1.
Run it the other way, top-p at T = 1 and then divide by 2:
print((keep_top_p(row, 0.9) / 2).softmax(dim=-1).round(decimals=3))
tensor([[0.5060, 0.3070, 0.1860, 0.0000, 0.0000, 0.0000]])
In the editor, keep_top_k and keep_top_p are done. Set same_k: True if dividing row by 2 and then top-k 3 gives the same probabilities as top-k 3 and then dividing by 2. Set same_p the same way, with top-p 0.9 in place of top-k 3.