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

Two precisions can disagree about the top token

In December 2024, the TPU code sometimes dropped the top token

Claude samples with top-p: it keeps only the most likely tokens, up to the point where their probabilities add up to a threshold, typically 0.99 or 0.999.

On TPUs the model is too large for one chip. It's split across tens of chips or more, and each chip computes some of the probabilities. So finding the top tokens means a sort across chips, a distributed sort.

In December 2024, Anthropic found that its TPU code would occasionally drop the most probable token when temperature was zero. It deployed a workaround for that case.

The root cause came later. It was mixed precision:

  • The model computes next-token probabilities in bf16, a 16-bit floating point format.
  • The TPU's vector processor works natively in fp32, 32-bit floats.
  • So the TPU compiler, XLA, can speed things up by converting some operations to fp32. A flag turns that on, xla_allow_excess_precision, and it defaults to true.

The result: operations that should have agreed on the top token ran at different precisions (1 source). They didn't agree on which token had the highest probability. So the top token sometimes disappeared from consideration entirely.

In the editor, write local_top(shard, k), the top tokens on one chip, and global_top(shards, k), the merge a distributed sort does. Each dict in SHARDS is one chip's share of the vocabulary, token to probability.