Scalable-Softmax Is Superior for Attention
Ken M. Nakanishi
TL;DR
Softmax attention suffers from fading as context length grows, hindering long-context capabilities. The authors propose Scalable-Softmax (SSMax), where attention scores are computed with a size-aware base, $z_i \mapsto \frac{n^{sz_i}}{\sum_j n^{sz_j}} = \frac{e^{(s\log n)z_i}}{\sum_j e^{(s\log n)z_j}}$, controlled by a per-head/layer scale $s$, enabling robust focus on key tokens across varying context sizes. Across a 162M-parameter Transformer, SSMax yields faster pretraining loss reduction, stronger generalization to longer contexts, and superior key-information retrieval, especially when used from the start of pretraining, while still offering gains when introduced mid-pretraining or post-pretraining. The results indicate SSMax can be integrated with minimal changes, suggesting it as a practical replacement for Softmax in Transformer attention to enhance length generalization and retrieval in long texts.
Abstract
The maximum element of the vector output by the Softmax function approaches zero as the input vector size increases. Transformer-based language models rely on Softmax to compute attention scores, causing the attention distribution to flatten as the context size grows. This reduces the model's ability to prioritize key information effectively and potentially limits its length generalization. To address this problem, we propose Scalable-Softmax (SSMax), which replaces Softmax in scenarios where the input vector size varies. SSMax can be seamlessly integrated into existing Transformer-based architectures. Experimental results in language modeling show that models using SSMax not only achieve faster loss reduction during pretraining but also significantly improve performance in long contexts and key information retrieval. Furthermore, an analysis of attention scores reveals that SSMax enables the model to focus attention on key information even in long contexts. Additionally, although models that use SSMax from the beginning of pretraining achieve better length generalization, those that have already started pretraining can still gain some of this ability by replacing Softmax in the attention layers with SSMax, either during or after pretraining.
