A router computed in bfloat16 can round two close logits to the same value and so change which experts a token is sent to. Simulate it: round float32 logits to bfloat16 exactly as hardware does, measure the grid spacing, and count the tokens whose top- expert set differs between an fp32 and a bf16 router.
to_bf16(x)
x to float32, then round each value to the nearest bfloat16 (8 exponent bits, 7 explicit mantissa bits) with round-to-nearest, ties-to-even, the rounding used by hardware and by torch.bfloat16. Equivalently: of the float32 bit pattern, keep the top 16 bits, rounding on the lower 16 bits, with an exact half rounding toward the candidate whose lowest kept bit is 0.bf16_spacing(x)
topk_indices(logits, k)
flip_rate(logits, k, offset=0.0)
offset to every logit (in float64), convert the result to float32: that is the fp32 router's input. The bf16 router uses to_bf16 of those same float32 values.