AI Hardware & Software Stack

When computing softmax exp(xi)/Σexp(xj), why is the maximum often subtracted from each xi first?

  1. ATo approximate the result for speed
  2. BTo always force the output (probability) of the largest element to 0
  3. CThe result is unchanged, and it prevents exp from overflowing to infinity
Show answer and explanation

Answer: C. The result is unchanged, and it prevents exp from overflowing to infinity

exp grows explosively; in FP16, for example, exp(x) exceeds the largest representable value once x passes about 11. Subtracting the same constant m from every x multiplies numerator and denominator by exp(-m), leaving the result unchanged. Subtracting the maximum makes every exponent 0 or less, so exp stays at most 1 and cannot overflow. It is especially important in low-precision AI computation and is used in fast attention implementations.

  • A. The result is mathematically the same.
  • B. It is the shifted input that becomes 0. The largest element's output (probability) is the biggest, not 0.
  • C. Correct. Numerator and denominator are scaled by the same factor.