TL;DR
Standard Non-Local (NL) blocks rely on Softmax normalization, which inadvertently forces the model to focus on vector magnitudes rather than meaningful pixel relationships. By replacing Softmax with a simple scaling factor, the authors create a "Scaled NL block" that is more accurate, robust to initialization, and computationally efficient—reducing the complexity of multi-head attention from quadratic to linear.
What Problem Does This Paper Address?
Non-Local (NL) blocks are the computer vision cousins of the Transformer's self-attention mechanism. They are designed to capture "global context"—allowing a pixel in the top-left corner of an image to "talk" to one in the bottom-right. While powerful, they suffer from two major flaws:
- Computational Cost: The memory and processing power required scales quadratically with the number of pixels ($O(N^2)$). This makes them prohibitively expensive for high-resolution images.
- The "Softmax Trap": Standard NL blocks use Softmax to normalize attention maps. The authors argue that Softmax makes the model "lazy." Instead of learning complex spatial relationships (cosine similarity), the model simply identifies a few high-magnitude "key" pixels and attends to them regardless of the query.
Methods
The authors propose the Scaled Non-Local Block. The core innovation is surprisingly simple: remove the Softmax operation.
In a standard NL block, attention is calculated as $Softmax(QK^T)V$. Because of the Softmax, you must calculate the full $N \times N$ attention matrix first. By removing Softmax and replacing it with a scaling factor ($\frac{1}{\sqrt{HW}}$) to keep gradients stable, the authors can invoke the associative law of matrix multiplication:
Instead of $(QK^T)V$, they compute $Q(K^TV)$.
This mathematical shift changes the computational complexity from $O(N^2C)$ to $O(NC^2)$. Since the number of pixels ($N$) is usually much larger than the number of channels ($C$), this makes the block significantly faster and lighter.
Datasets
The researchers evaluated their approach using standard computer vision benchmarks:
- CIFAR-10 & CIFAR-100: Small-scale image classification.
- Tiny-ImageNet: A mid-scale dataset used to verify if the improvements hold as complexity increases.
- Architectures: They integrated their blocks into PreResNet (various depths) and Wide-Residual Networks (WRN).
Key Insights and Ideas
- Vertical Line Syndrome: When visualizing standard NL attention maps, the authors noticed distinct vertical lines (see Figure 1, top row). This indicates that certain "key" pixels dominate the attention map regardless of which "query" pixel is looking at them. The model is essentially ignoring the relationship between pixels and just looking at the "loudest" ones.
- Geometric Freedom: Geometrically, Softmax limits the "angular variation" of queries. For a key to have low attention with many queries under Softmax, those queries must all point in the same direction. Without Softmax, queries only need to be orthogonal to a key to result in zero attention. This allows the model to represent much more diverse relationships in the same feature space.
- Robustness to "Magic Numbers": Standard NL blocks are notoriously sensitive to weight initialization, often requiring a specific, tuned standard deviation ($\sigma=0.01$). The Scaled NL block works out-of-the-box with standard He initialization, making it easier to train.
Key Results
The Scaled NL block outperformed the standard version across the board while being faster:
- Accuracy: On CIFAR-100 with a PreResNet56, the Scaled NL block reduced the test error from 25.12% to 24.53%.
- Efficiency: For a 4-head attention setup, the proposed method reduced memory consumption from 5229 MB to 3417 MB and cut training time per batch by roughly 24% (from 100.93ms to 76.51ms).
- Channel Efficiency: As shown in Figure 2, the Scaled NL block is much more robust when the embedding channel size is reduced, maintaining higher accuracy than the standard NL block even with very few channels.
Limitations and Future Work
While the results are promising for image classification on small-to-medium datasets, the paper does not explore:
- Large-scale benchmarks: Performance on full-scale ImageNet-1k or COCO object detection.
- NLP Tasks: Whether this "Softmax-free" approach translates well to Transformers in Natural Language Processing, where Softmax is the industry standard.
- Scaling Factor Sensitivity: The $\frac{1}{\sqrt{HW}}$ factor is derived from specific statistical assumptions; it remains to be seen if this factor needs tuning for vastly different architectures.
Summary updated