Abstract
Softmax attention in Transformers often suffers from vanishing gradients when attention scores become highly polarized. This paper introduces "Self-Adjusting Softmax" (SA-Softmax), a simple drop-in replacement that multiplies the softmax output by a normalized version of its input. This modification significantly improves gradient flow, lowers perplexity across various model sizes (up to 2.7B parameters), and boosts downstream task performance without requiring major architectural changes.
Introduction
At the heart of the Transformer architecture is the self-attention mechanism. It uses the softmax function to convert raw attention scores (logits) into a probability distribution. However, softmax has a well-known Achilles' heel: the vanishing gradient problem. When the model becomes highly confident—meaning one token's attention score approaches 1 while others approach 0—the mathematical derivative of the softmax function flattens out. During backpropagation, these near-zero gradients prevent effective weight updates, slowing down or halting learning, especially in deep networks or long-context scenarios.
Methods: Self-Adjusting Softmax (SA-Softmax)
To keep gradients alive, the authors propose Self-Adjusting Softmax (SA-Softmax). Instead of outputting $softmax(x)$, the core idea is to multiply the softmax output by its pre-softmax input: $x \cdot softmax(x)$. By injecting the raw input $x$ into the output, the chain rule ensures the gradient is amplified by $x$, preventing it from vanishing even when probabilities saturate.
To ensure training stability, the authors refine this into a normalized variant (Variant 3) that bounds the multiplier between 0 and 1:
$$ \text{Output} = \frac{x - \min(x_{min}, 0)}{\max(0, x_{max}) - \min(x_{min}, 0)} \cdot softmax(x) $$
This dynamic scaler stabilizes early training while allowing larger gradients later, serving as a direct replacement for standard softmax.
Evaluation and Datasets
The authors evaluated SA-Softmax across a robust mix of tasks:
- Pre-training: Arxiv and Books3 subsets of The Pile.
- Downstream Classification: AG-News, DBPedia, Yelp-Review, YahooNews, and AmazonNews.
- Zero-shot Reasoning: Lambda, WikiText, ARCEasy, HellaSwag, PiQA, OpenBookQA, SciQ, and Winogrande.
Key Results
Scalability and Perplexity
SA-Softmax consistently lowered perplexity across all tested scales, from 125M up to 2.7B parameters. For instance, on the Books dataset with a 2.7B parameter model, perplexity improved from 29.98 to 29.15.
Downstream Performance
The modified attention mechanism translated to tangible gains in zero-shot reasoning and classification. It achieved a significant +6.25% accuracy jump on the AmazonNews dataset and showed consistent improvements across benchmarks like SciQ and Winogrande.
Universal Compatibility and Context Length
The method is agnostic to positional encoding (PE) types, showing improvements with RoPE, ALiBi/Kerple, FIRE, and DAPEV2-Kerple. It also maintained its edge on longer sequences up to 2048 tokens, proving robust for long-context modeling.
Conclusion and Future Work
SA-Softmax demonstrates that Transformers can learn effectively even if attention scores are not strictly positive and rows do not sum to one. By using the pre-softmax input as a self-adjusting scaler, it keeps the training signal flowing.
The primary limitation is the slight computational overhead from calculating min/max values across the sequence dimension. Future work may involve optimizing these calculations via custom kernels (e.g., FlashAttention) and testing on frontier-scale models exceeding 100B parameters.
Summary updated