Rewiring the Transformer with Depth-Wise LSTMs

Hongfei Xu, Yang Song, Qiuhui Liu, Josef van Genabith, Deyi Xiong

Abstract

Stacking non-linear layers allows deep neural networks to model complicated functions, and including residual connections in Transformer layers is beneficial for convergence and performance. However, residual connections may make the model “forget” distant layers and fail to fuse information from previous layers effectively. Selectively managing the representation aggregation of Transformer layers may lead to better performance. In this paper, we present a Transformer with depth-wise LSTMs connecting cascading Transformer layers and sub-layers. We show that layer normalization and feed-forward computation within a Transformer layer can be absorbed into depth-wise LSTMs connecting pure Transformer attention layers. Our experiments with the 6-layer Transformer show significant BLEU improvements in both WMT 14 English-German / French tasks and the OPUS-100 many-to-many multilingual NMT task, and our deep Transformer experiments demonstrate the effectiveness of depth-wise LSTM on the convergence and performance of deep Transformers.

Introduction

Since the landmark "Attention is All You Need" paper, the Transformer has relied on residual connections (the "Add" in Add & Norm) to train deep networks. While residual connections prevent gradients from vanishing, they are mathematically "dumb"—they simply add the input of a layer to its output.

The authors argue that this simple addition can cause the model to "forget" information from distant, earlier layers and fails to effectively fuse linguistic features captured at different levels of abstraction. Essentially, the network lacks a sophisticated way to manage its internal "memory" as data flows from the bottom layer to the top. This paper proposes "rewiring" the Transformer architecture by replacing standard residual connections and feed-forward sub-layers with Depth-Wise LSTMs. By treating the stack of layers as a sequence in time, the model uses LSTM gating mechanisms to selectively fuse information across the network's depth.

Methods

The core innovation is the Depth-Wise LSTM. Unlike a traditional LSTM that processes a sequence of words (horizontal), this LSTM processes the sequence of layers (vertical).

  1. Structural Replacement: In a standard Transformer layer, an attention sub-layer is typically followed by a Feed-Forward Network (FFN). The authors replace the FFN and the surrounding residual connections with a single Depth-Wise LSTM unit.
  2. Information Fusion: The LSTM takes the output of the current attention layer and the "hidden state" and "cell state" from the previous layer. It uses standard LSTM gates (input, forget, and output) to decide exactly how much information from the previous layers should be kept or discarded.
  3. Absorbing Components: The authors show that Layer Normalization and FFN computation can be "absorbed" into the LSTM structure. Specifically, using a 2-layer neural network (or a GLU activation) within the LSTM's hidden state computation yielded the best results.
Internal structure of the Depth-Wise LSTM unit, showing how gating and normalization are integrated.
  1. Decoder Merging: Since decoders have both self-attention and cross-attention, the authors introduced a "Merge" layer (using element-wise addition) to combine these outputs before feeding them into the Depth-Wise LSTM.

Experimental Results

The researchers evaluated their "rewired" Transformer on several standard benchmarks, including WMT 14 (En-De and En-Fr), WMT 15 (Cs-En), and the massive OPUS-100 many-to-many multilingual dataset.

Key Performance Gains

On WMT 14 En-De, the Depth-Wise LSTM improved the "Base" Transformer by +0.98 BLEU and the "Big" Transformer by +0.75 BLEU. The benefits were even more pronounced in the multilingual (OPUS-100) task, where the proposed model achieved an average improvement of +2.52 BLEU across 94 languages when translating from English.

Performance comparison on WMT 14 tasks showing consistent gains for both Base and Big models.

Insights on Depth and Efficiency

  • Gating vs. Adding: The primary insight is that the gating mechanism of an LSTM is far more effective at managing representation aggregation than simple residual addition. It allows the model to selectively "remember" useful features from the bottom of the stack even at the very top.
  • Depth Efficiency: A 12-layer Transformer using Depth-Wise LSTMs performs on par with or better than a 24-layer vanilla Transformer. This suggests that smarter connections between layers can be more effective than simply increasing depth.
  • Deep Model Stability: While vanilla Transformers often struggle to converge as they get deeper, the Depth-Wise LSTM version showed consistent improvements up to 18–24 layers.

Discussion and Conclusion

While the Depth-Wise LSTM provides significant quality improvements, there is a small trade-off in inference speed. Decoding is roughly 1.12x slower than a vanilla Transformer due to the added complexity of the LSTM unit. Additionally, the parameter count increases slightly (e.g., from 62M to 70M in the Base model).

However, the authors argue these costs are offset by the ability to achieve better results with fewer total layers. Future work may explore other recurrent units like GRUs or combine this approach with other efficiency techniques. Ultimately, introducing non-linear gates into the "vertical" path of the network provides a powerful inductive bias for hierarchical feature fusion in deep translation models.

Summary updated

BibTeX
@inproceedings{xu2024rewiring,
  author = {Hongfei Xu and Yang Song and Qiuhui Liu and Josef van Genabith and Deyi Xiong},
  title = {{Rewiring the Transformer with Depth-Wise LSTMs}},
  booktitle = {International Conference on Computational Linguistics},
  year = {2024},
  url = {https://openreview.net/forum?id=mIynIQQnaj},
}
Figure