Rethinking Skip Connection with Layer Normalization in Transformers and ResNets

Fenglin Liu, Xuancheng Ren, Zhiyuan Zhang, Xu Sun, Yuexian Zou

Abstract

Skip connection is a widely-used technique to improve the performance and the convergence of deep neural networks, which is believed to relieve the difficulty in optimization due to non-linearity by propagating a linear component through the neural network layers. However, from another point of view, it can also be seen as a modulating mechanism between the input and the output, with the input scaled by a pre-defined value one. In this work, we investigate how the scale factors in the effectiveness of the skip connection and reveal that a trivial adjustment of the scale will lead to spurious gradient exploding or vanishing in line with the deepness of the models, which could be addressed by normalization, in particular, layer normalization, which induces consistent improvements over the plain skip connection. Inspired by the findings, we further propose to adaptively adjust the scale of the input by recursively applying skip connection with layer normalization, which promotes the performance substantially and generalizes well across diverse tasks including both machine translation and image classification datasets.

Introduction

Skip connections, or identity mappings, have become a fundamental component in modern deep neural network architectures, such as ResNets and Transformers. By allowing gradients to bypass non-linear transformations, they mitigate the vanishing gradient problem in very deep models. The standard implementation follows the form $y = x + \mathcal{F}(x)$, where $x$ is the input and $\mathcal{F}(x)$ is the residual function.

Standard skip connection implementations in ResNet, Highway Net, PreAct-ResNet, and Transformer architectures.

Despite their success, the fixed 1:1 ratio between the shortcut and the residual branch is often taken for granted. This paper explores whether adjusting the scale of the input signal can further optimize performance and how to stabilize such modifications during training.

Methodology

The authors investigate the general formulation $y = \mathcal{G}(\lambda x + \mathcal{F}(x, W))$, where $\lambda$ is a scaling factor.

Expanded Skip Connection (xSkip)

Setting $\lambda > 1$ directly emphasizes the linear component. However, empirical tests show this approach is highly unstable, often leading to gradient malformation (exploding or vanishing gradients) as depth increases.

Expanded Skip with Layer Normalization (xSkip+LN)

To stabilize the expanded skip connection, the authors propose applying Layer Normalization (LN) after the addition. This configuration helps maintain stable signal propagation even with $\lambda > 1$.

Proposed modification of the skip connection using a scale factor $\lambda$ and Layer Normalization (LN).

Recursive Skip Connection with LN (rSkip+LN)

The primary contribution of this work is the Recursive Skip Connection with LN (rSkip+LN). Instead of a single large $\lambda$, the shortcut is added and normalized recursively. For $\lambda=2$, the process is:

  1. $y_1 = LN(x + \mathcal{F}(x))$
  2. $y_2 = LN(x + y_1)$

This recursive structure allows the gain parameters within the LN layers to act as learnable, adaptive ratios. This enables the model to dynamically determine the optimal balance between the input signal and the residual transformation at each stage.

Experimental Setup

The proposed methods were evaluated on two major benchmarks:

  • Computer Vision: Image classification on CIFAR-10 and CIFAR-100 using ResNet architectures ranging from 20 to 110 layers.
  • Natural Language Processing: Machine translation tasks on IWSLT 2015 (English-Vietnamese) and WMT 2014 (English-German and English-French) using the Transformer architecture.

Discussion and Insights

  • The Linear Advantage: Increasing the weight of the skip connection smooths the optimization landscape by prioritizing the linear path, provided that normalization prevents gradient instability.
  • Layer Normalization vs. Batch Normalization: The authors observe that LN is superior to BN for expanded skip connections. LN operates in the feature space, allowing it to adaptively scale specific features even when the residual branch produces noisy outputs.
  • Implicit Adaptivity: Mathematical analysis of the recursive formula reveals that the LN parameters ($w$ and $\sigma$) effectively create a learnable ratio, allowing the model to adjust the "importance" of the shortcut based on the data distribution.
  • Efficiency Gains: A significant finding is that rSkip+LN allows shallower models to match or exceed the performance of much deeper standard counterparts.

Results

The rSkip+LN method demonstrated consistent improvements across all tasks:

  • ResNet: On CIFAR-10, rSkip+LN ($\lambda=2$) improved the error rate of PreAct-ResNet-110 from 6.37% to 6.02%. On CIFAR-100, it provided an absolute accuracy boost of up to 1.02%.
  • Transformer: In WMT-14 English-German translation, the method improved Transformer-Base and Transformer-Big scores by 0.7 and 0.5 BLEU, respectively.
  • Parameter Efficiency: A 2-block Transformer using rSkip+LN achieved a BLEU score of 30.49, outperforming a standard 6-block Transformer (30.31).

Conclusion

This work demonstrates that the traditional 1:1 skip connection ratio is not necessarily optimal. By introducing Recursive Skip Connection with Layer Normalization, the authors provide a robust way to amplify the input signal, leading to improved performance and greater parameter efficiency. Future work may explore continuous, automated methods for determining the optimal scaling factor $\lambda$ during training.

Summary updated

Abstract

Skip connection, is a widely-used technique to improve the performance and the convergence of deep neural networks, which is believed to relieve the difficulty in optimization due to non-linearity by propagating a linear component through the neural network layers. However, from another point of view, it can also be seen as a modulating mechanism between the input and the output, with the input scaled by a pre-defined value one. In this work, we investigate how the scale factors in the effectiveness of the skip connection and reveal that a trivial adjustment of the scale will lead to spurious gradient exploding or vanishing in line with the deepness of the models, which could be addressed by normalization, in particular, layer normalization, which induces consistent improvements over the plain skip connection. Inspired by the findings, we further propose to adaptively adjust the scale of the input by recursively applying skip connection with layer normalization, which promotes the performance substantially and generalizes well across diverse tasks including both machine translation and image classification datasets.
BibTeX
@inproceedings{liu2020rethinking,
  author = {Fenglin Liu and Xuancheng Ren and Zhiyuan Zhang and Xu Sun and Yuexian Zou},
  title = {{Rethinking Skip Connection with Layer Normalization in Transformers and ResNets}},
  booktitle = {International Conference on Computational Linguistics},
  year = {2020},
  doi = {10.18653/v1/2020.coling-main.320},
}
Figure