Accelerating Transformer Decoding via a Hybrid of Self-attention and Recurrent Neural Network

Chengyi Wang, Shuangzhi Wu, Shujie LiuarXiv 2019

Introduction

While the Transformer architecture has revolutionized natural language processing through its highly parallelizable training, it faces a significant efficiency hurdle during inference. This "Transformer tax" arises from the auto-regressive nature of decoding: generating a sequence one token at a time requires the model to re-attend to the entire generated history at every step. As sequences grow longer, the computational cost of multi-head attention and feed-forward layers in the decoder scales poorly.

This paper proposes a hybrid approach that combines the best of both worlds: the powerful context modeling of a Transformer encoder with the sequential efficiency of a Recurrent Neural Network (RNN) decoder.

The Hybrid Architecture

The core innovation is a structural shift in the sequence-to-sequence framework. Instead of a symmetric Transformer-to-Transformer setup, the authors utilize a hybrid design that optimizes for both encoding depth and decoding speed.

The hybrid architecture: a multi-layer Transformer encoder paired with a simple RNN decoder.
  • Transformer Encoder: A deep (typically 6-layer) encoder that leverages self-attention to capture complex, long-range dependencies in the source text.
  • RNN Decoder: A lightweight, single-layer Gated Recurrent Unit (GRU). Unlike the Transformer decoder, the GRU compresses the generation history into a fixed-size hidden state, avoiding the need to re-scan the entire target history for every new word.

The authors experimented with various attention mechanisms to bridge the encoder and decoder, including additive, dot-product, and multi-head attention, finding that the choice of attention can further tune the balance between speed and accuracy.

Bridging the Performance Gap: Knowledge Distillation

A primary challenge with using a simple RNN decoder is the potential loss in translation quality compared to a full Transformer. To mitigate this, the authors employ a two-stage training process:

  1. Maximum Likelihood Estimation (MLE): Initial training on bilingual corpora.
  2. Knowledge Distillation (KD): A pre-trained, high-performing Transformer acts as a "teacher." The hybrid "student" model is trained not just on the ground-truth labels, but to mimic the full probability distribution (soft targets) of the teacher. This allows the simpler decoder to inherit the sophisticated logic of the Transformer.

Experimental Results

The hybrid model was evaluated on the NIST OpenMT (Chinese-English) and WMT 2017 benchmarks. The results demonstrate that the hybrid architecture effectively eliminates the decoding bottleneck, which the authors found accounts for nearly 88% of total decoding time in standard Transformers.

Performance comparison on the NIST dataset, showing speedups and translation quality (BLEU/NIST scores).

Key findings include:

  • Massive Speedup: The 6-layer hybrid model achieved up to a 4.1x speedup over the standard Transformer teacher on the NIST tasks and a 3.9x speedup on WMT17.
  • Comparable Quality: Through Knowledge Distillation, the performance gap is nearly closed. On WMT17, the hybrid model achieved a BLEU score of 22.93, compared to the teacher's 23.08—a negligible difference in exchange for a 4x throughput increase.
  • Efficiency: The hybrid model even outperformed traditional RNN-based NMT models in both speed and quality, proving that the Transformer encoder provides a superior foundation for the RNN decoder.

Conclusion

By identifying the decoder as the primary bottleneck in Transformer inference, the authors demonstrate that a hybrid architecture is a viable path toward real-time, high-quality machine translation. The combination of a Transformer's encoding power and an RNN's decoding speed, bolstered by knowledge distillation, provides a practical solution for deploying state-of-the-art NLP models in latency-sensitive environments.

Summary updated

BibTeX
@misc{wang2019accelerating,
  author = {Chengyi Wang and Shuangzhi Wu and Shujie Liu},
  title = {{Accelerating Transformer Decoding via a Hybrid of Self-attention and Recurrent Neural Network}},
  year = {2019},
  eprint = {1909.02279},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1909.02279},
}
Figure