SOFT: Softmax-free Transformer with Linear Complexity

Jiachen Lu, Jinghan Yao, Junge Zhang, Xiatian Zhu, Hang Xu, Weiguo Gao, Chunjing Xu, Tao Xiang, Li Zhang

Introduction

Vision Transformers (ViTs) have set new benchmarks in computer vision, yet they are constrained by the quadratic complexity ($O(n^2)$) of the self-attention mechanism. As the number of tokens ($n$) increases with higher image resolutions, computational and memory costs grow prohibitively. While "linear" Transformers have been explored in NLP, they often struggle with vision tasks. This paper identifies the softmax operation as the primary obstacle to effective linearization and proposes SOFT (Softmax-free Transformer) to achieve true linear complexity without sacrificing accuracy.

The Softmax-Free Approach

The core innovation of SOFT is the removal of the traditional softmax-based attention. Instead, the model utilizes a Gaussian kernel to define token similarity. By setting the Query ($Q$) and Key ($K$) to be identical, the attention matrix becomes a symmetric, positive semi-definite Gram matrix. This mathematical property allows for the application of the Nyström method, a robust low-rank approximation technique that reduces complexity from $O(n^2)$ to $O(n)$.

To handle the Moore-Penrose inverse required by the Nyström method efficiently on modern hardware, SOFT employs a Newton-Raphson iterative solver. Unlike standard SVD, this approach is highly parallelizable and optimized for GPU execution.

The SOFT architecture replaces softmax with a Gaussian kernel and Nyström approximation.

Architecture and Implementation

SOFT is built upon a multi-stage pyramidal architecture, similar to modern CNNs. It uses overlapping convolutions for tokenization to better capture local structural information. The model's efficiency allows it to process sequences significantly longer than those handled by standard Transformers.

Experimental Results

Evaluation on ImageNet-1K demonstrates that SOFT achieves superior trade-offs between accuracy and computational cost.

  • Efficiency and Scaling: SOFT's memory usage scales linearly with sequence length. It can process sequences up to 8 times longer than standard Transformers on identical hardware.
  • Classification Performance: SOFT-Tiny achieves 79.3% Top-1 accuracy, outperforming PVT-Tiny (75.1%) and standard ViT-Small (79.1%) with fewer FLOPs. The largest variant, SOFT-Huge, reaches 83.3% Top-1 accuracy, rivaling state-of-the-art models like Swin-B.
  • Long-Range Modeling: On the Long Range Arena (LRA) benchmark, SOFT outperformed other efficient variants like Performer and Nyströmformer on 3 out of 4 tasks, highlighting its versatility beyond vision.
SOFT demonstrates superior accuracy-parameter trade-offs (left) and linear memory scaling (right).

Key Insights

A notable finding is that the low-rank approximation in SOFT acts as a form of implicit regularization. The authors observed that training with a full Gaussian matrix often fails to converge, whereas the approximated version focuses the model on salient information, enhancing robustness and training stability.

Conclusion and Future Work

SOFT effectively breaks the quadratic bottleneck of Vision Transformers. By replacing softmax with a mathematically sound Gaussian kernel and Nyström approximation, it enables high-resolution visual recognition with linear complexity. Future research may explore alternative kernels and address the sequential nature of Newton-Raphson iterations to further improve training speeds.

Summary updated

BibTeX
@inproceedings{lu2021soft,
  author = {Jiachen Lu and Jinghan Yao and Junge Zhang and Xiatian Zhu and Hang Xu and Weiguo Gao and Chunjing Xu and Tao Xiang and Li Zhang},
  title = {{SOFT: Softmax-free Transformer with Linear Complexity}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2021},
}
Figure