Softmax in Attention: Exponential Sensitivity to Noise
The softmax function, crucial for converting attention scores into probabilities, is challenging to quantize due to its exponential nature; small input changes from quantization noise can drastically alter output probabilities. Research often recommends keeping softmax computations in higher precision (e.g., FP16 or FP32) to prevent significant distortion of attention weights.
The top 3
- Log-Sum-Exp Trick: Softmax's Numerical Stability Secret: The exponential function in softmax can lead to numerical overflow or underflow with large or small input logits; the Log-Sum-Exp (LSE) trick mitigates this by subtracting the maximum logit before exponentiation, ensuring stable and accurate probability calculations.
- Softmax Dispersion: Why Attention Loses Focus with Length: Softmax attention coefficients inherently disperse and become more uniform as the number of input items (sequence length) increases, leading to a loss of sharp focus and hindering the model's ability to make precise decisions, a phenomenon known as "softmax dispersion."
- Quantization Bias: Softmax's Hidden Accuracy Killer: When the softmax output is quantized to low bit-widths (e.g., 8-bit), up to 99% of its values can be rounded to zero, leading to a significant bias where the probabilities no longer sum to 1, which severely degrades model performance and accuracy.
Sources
Open the full topic