ResiDual: Transformer with Dual Residual Connections

Shufang Xie, Huishuai Zhang, Junliang Guo, Xu Tan, Jiang Bian +4 more
4/28/2023
cs.CLcs.AIcs.LG

Official code: microsoft/ResiDual (98 stars, MIT, last commit 2023-08-18).

Abstract

Transformer networks have become the preferred architecture for many tasks due to their state-of-the-art performance. However, the optimal way to implement residual connections in Transformer, which are essential for effective training, is still debated. Two widely used variants are the Post-Layer-Normalization (Post-LN) and Pre-Layer-Normalization (Pre-LN) Transformers, which apply layer normalization after each residual block's output or before each residual block's input, respectively. While both variants enjoy their advantages, they also suffer from severe limitations: Post-LN causes gradient vanishing issue that hinders training deep Transformers, and Pre-LN causes representation collapse issue that limits model capacity. In this paper, we propose ResiDual, a novel Transformer architecture with Pre-Post-LN (PPLN), which fuses the connections in Post-LN and Pre-LN together and inherits their advantages while avoids their limitations. We conduct both theoretical analyses and empirical experiments to verify the effectiveness of ResiDual. Theoretically, we prove that ResiDual has a lower bound on the gradient to avoid the vanishing issue due to the residual connection from Pre-LN. Moreover, ResiDual also has diverse model representations to avoid the collapse issue due to the residual connection from Post-LN. Empirically, ResiDual outperforms both Post-LN and Pre-LN on several machine translation benchmarks across different network depths and data sizes. Thanks to the good theoretical and empirical performance, ResiDual Transformer can serve as a foundation architecture for different AI models (e.g., large language models). Our code is available at https://github.com/microsoft/ResiDual.

View on arXivView PDF

Code Implementations(1)

microsoft/ResiDualOfficial100%
MIT

ResiDual: Transformer with Dual Residual Connections, https://arxiv.org/abs/2304.14802

987PythonMar 14, 20233 years agoMIT

Similar Papers

Cite this paper

@article{xie2023residual,
  title  = {ResiDual: Transformer with Dual Residual Connections},
  author = {Shufang Xie and Huishuai Zhang and Junliang Guo and Xu Tan and Jiang Bian and Hany Hassan Awadalla and Arul Menezes and Tao Qin and Rui Yan},
  year   = {2023},
  eprint = {2304.14802},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2304.14802v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2304.14802.svg)](https://codeofpaper.com/paper/2304.14802)

Discussion