Enhancing Vision Transformer: Amplifying Non-Linearity in Feedforward Network Module

Yixing Xu, Chao Li, Dong Li, Xiao Sheng, Fan Jiang, Lu Tian, Ashish Sirasao, Emad Barsoum

TL;DR

Researchers have found a way to make Vision Transformers (ViTs) significantly leaner and faster by rethinking the often-ignored Feedforward Network (FFN) module. By replacing standard activation functions with a more powerful, learnable version called AGeLU and adding a spatial enhancement layer, they reduced computational costs (FLOPs) and parameters by roughly 10-20% across multiple state-of-the-art models without losing accuracy.

What Problem Does This Paper Address?

In the world of Vision Transformers, the Self-Attention module usually gets all the glory. It’s the part that allows the model to look at the "big picture" of an image. However, every Transformer block also contains a Feedforward Network (FFN), which typically accounts for a huge chunk of the model's parameters and computation.

Most researchers treat the FFN as a "black box" and leave it in its vanilla form. The authors of this paper argue that the FFN’s primary job is to provide non-linearity—the mathematical "flexibility" that allows neural networks to learn complex patterns. Currently, we achieve high non-linearity by making the FFN very "wide" (high hidden dimensions), which is computationally expensive. This paper asks: Can we achieve the same level of non-linearity with a narrower, more efficient module?

Methods

The authors propose the Improved FFN (IFFN) module, which consists of two main innovations designed to boost non-linearity without bloating the parameter count:

  1. Arbitrary GeLU (AGeLU): Instead of using the standard, fixed GeLU activation function, they introduced learnable parameters ($\alpha, \beta, \gamma, \theta$) that allow the function to change its shape, slope, and shift during training.
Variations of the Arbitrary GeLU (AGeLU) activation function based on learnable parameters.
  1. The "Halving" Strategy: They discovered that by running two AGeLU functions in parallel and concatenating them, they could generate the same "degree" of non-linearity as a standard FFN while cutting the hidden dimension (and thus the number of parameters in the first linear layer) in half.
  2. Spatial Enhancement: Standard FFNs process each pixel (or "patch") in isolation. The IFFN adds a Depthwise Convolution (DW Conv) block. This allows the FFN to incorporate information from neighboring pixels, further boosting the model's expressive power with minimal extra cost.

Datasets

The researchers validated their approach across three major computer vision benchmarks:

  • ImageNet-1k: The gold standard for image classification.
  • COCO 2017: Used to test object detection (using the Mask R-CNN framework).
  • ADE20K: Used to test semantic segmentation (using the UperNet framework).

They tested their IFFN module as a "plug-and-play" replacement in several popular architectures, including DeiT, Swin Transformer, PoolFormer, and LVT.

Key Insights and Ideas

  • FFN as a Non-linearity Generator: The paper provides a theoretical proof showing that the FFN is essentially a generator of non-linear functions. Its complexity is directly tied to its width.
  • Trading Width for Complexity: You don't need a massive, wide layer if your activation functions are "smarter." By making the activations learnable (AGeLU), you can shrink the layer's width without losing performance.
  • Stability Matters: Introducing learnable activations can sometimes make training unstable. The authors performed a Lipschitz constant analysis to prove that their IFFN module remains mathematically stable and robust against small input perturbations.
  • Spatial Context in FFNs: While Transformers are known for global attention, adding a tiny bit of local spatial context (via the DW Conv) inside the FFN provides a massive efficiency boost.

Key Results

The results were consistent across different model sizes and architectures:

Accuracy vs. FLOPs comparison on ImageNet-1k showing enhanced models outperforming baselines.
  • Efficiency Gains: On ImageNet-1k, the IFFN module reduced parameters and FLOPs by 10% to 21% depending on the baseline model.
  • Accuracy Maintenance: In almost all cases, accuracy stayed the same or even improved slightly. For example, Swin-Ti + IFFN reduced FLOPs by 13.8% while increasing Top-1 accuracy from 81.2% to 81.5%.
  • Downstream Tasks: On the COCO dataset, they reduced the Swin-Ti backbone by 4M parameters and 16G FLOPs while maintaining the exact same detection performance (46.0 AP). On ADE20K, they actually improved segmentation performance (+0.5 mIoU) while making the model smaller.

Limitations and Future Work

  • Hardware Efficiency: While the paper shows a reduction in theoretical FLOPs, the actual "wall-clock" speedup on specific hardware (like GPUs or mobile chips) can vary because depthwise convolutions and custom activation functions aren't always as optimized as standard matrix multiplications.
  • Hyperparameter Sensitivity: The paper doesn't deeply explore how sensitive the AGeLU parameters are to different initialization strategies.
  • Future Directions: The authors suggest that this approach could be applied to even broader ranges of Transformer-based models, potentially including Large Language Models (LLMs), where FFNs also consume a massive amount of resources.

Summary updated

BibTeX
@inproceedings{xu2024enhancing,
  author = {Yixing Xu and Chao Li and Dong Li and Xiao Sheng and Fan Jiang and Lu Tian and Ashish Sirasao and Emad Barsoum},
  title = {{Enhancing Vision Transformer: Amplifying Non-Linearity in Feedforward Network Module}},
  booktitle = {International Conference on Machine Learning},
  year = {2024},
  url = {https://openreview.net/forum?id=NV0q2jdwo0},
}
Figure