Unified Normalization for Accelerating and Stabilizing Transformers

Qiming Yang, Kai Zhang, Chaoxiang Lan, Zhi Yang, Zheyang Li, Wenming Tan, Jun Xiao, Shiliang Pu · DOI

TL;DR

This paper introduces Unified Normalization (UN), a novel method to replace Layer Normalization (LN) in Transformers. UN significantly speeds up inference and reduces memory usage by fusing normalization with linear operations, while maintaining performance comparable to LN and avoiding the training instability issues seen with other efficient normalization methods.

What Problem Does This Paper Address?

Transformers have become the go-to architecture for many tasks in Natural Language Processing (NLP) and Computer Vision (CV). A key component enabling their success is Layer Normalization (LN), which stabilizes training by normalizing activations. However, LN requires calculating statistics on-the-fly during inference, making it computationally expensive and a bottleneck for deployment, especially on hardware-constrained devices.

Attempts to replace LN with more hardware-efficient "offline" normalization methods (like Batch Normalization, BN) often lead to significant performance degradation or even complete training collapse. The authors identify the root cause of this dilemma: abnormal behaviors in activation statistics within Transformers, specifically large fluctuations and extreme outliers across layers and over training iterations. These anomalies disrupt the delicate balance needed for stable training and effective gradient estimation.

Methods

The paper proposes Unified Normalization (UN), a two-pronged approach to address the limitations of LN and other offline methods:

  • Unified Framework for Offline Normalization: UN provides a general framework to fuse offline normalization techniques with subsequent linear operations (like convolutions or fully connected layers). This fusion allows the normalization to be "baked" into the linear layer, eliminating the need for separate, on-the-fly calculations during inference.
  • Fluctuation Smoothing Strategy: To combat the large fluctuations in activation and gradient statistics, UN employs a tailored smoothing strategy. This involves using moving averages of statistics, but with a twist: it leverages the geometric mean (GM) for activation statistics (which is less sensitive to outliers than the arithmetic mean) and a combination of arithmetic mean and momentum for gradient statistics.
  • Adaptive Outlier Filtration Strategy: To further stabilize training and prevent collapse, UN introduces an adaptive outlier filtration mechanism. This strategy dynamically identifies and mitigates the impact of extreme outliers by selectively applying or dropping the moving average techniques based on a threshold derived from the AM-GM inequality. This ensures that even when outliers appear, the training process remains robust.

Datasets

The paper evaluates UN on a variety of standard benchmarks:

  • Neural Machine Translation: IWSLT14 (De-En) and WMT14 (En-Fr).
  • Image Classification: ImageNet-1K, CIFAR10, and CIFAR100.
  • Object Detection and Instance Segmentation: COCO val2017 (using Faster R-CNN and Mask R-CNN with Swin-T backbone).

No new datasets were introduced.

Key Insights and Ideas

  • Abnormal Statistics are the Culprit: The paper's core insight is that the instability and performance drop observed when replacing LN with other normalizers stem from inherent, problematic statistical behaviors (fluctuations and outliers) within Transformer activations, not just the normalization method itself.
  • Geometric Mean for Robustness: Using the geometric mean for activation statistics is a clever way to leverage the robustness of this metric against extreme outliers, providing a more stable representation than the arithmetic mean.
  • Adaptive Outlier Handling is Crucial: Simply smoothing statistics isn't enough. An adaptive mechanism to detect and handle outliers is essential for preventing training collapse, especially in deeper layers where fluctuations tend to increase.
  • Fusion is Key to Efficiency: The ability to fuse UN with linear operations is what unlocks significant inference speedups and memory reductions, making it a truly practical alternative.

Key Results

  • Performance: UN achieves performance comparable to Layer Normalization (LN) across various tasks (NMT, image classification, object detection, instance segmentation).
  • Efficiency: Transformers equipped with UN show approximately 31% inference speedup and 18% memory reduction on GPUs.
  • Stability: UN successfully avoids the training collapse and performance degradation issues encountered by other offline normalization methods like Batch Normalization (BN), MABN, and PN*.
  • Feature Similarity: UN-trained models exhibit higher feature map similarity with LN-trained models compared to BN-trained models, especially in shallower layers, suggesting it preserves more of LN's beneficial properties.

Limitations and Future Work

  • Window Size Sensitivity: While UN is generally robust, the paper notes that the choice of window size (M) for moving averages can impact performance, and moderate sizes generally yield competitive results.
  • Momentum Parameter (α): The momentum parameter α for approximating inference statistics and estimating gradients is investigated. While a range of values (0.7-0.9) works well, a small value (e.g., 0.6) can lead to training collapse on certain tasks, similar to removing momentum in the backward pass. The paper suggests α=0.9 as a good default.
  • Future Work: The authors believe UN can be a general component for efficient Transformer deployment and suggest further exploration for its application in various domains. The paper also implies that understanding and mitigating these statistical anomalies is a broader challenge in deep learning architectures.

Summary updated

BibTeX
@inproceedings{yang2022unified,
  author = {Qiming Yang and Kai Zhang and Chaoxiang Lan and Zhi Yang and Zheyang Li and Wenming Tan and Jun Xiao and Shiliang Pu},
  title = {{Unified Normalization for Accelerating and Stabilizing Transformers}},
  booktitle = {ACM Multimedia},
  year = {2022},
  doi = {10.1145/3503161.3547860},
}
Figure