Skip to main content
QUICK REVIEW

[Paper Review] Sharing Attention Weights for Fast Transformer

Tong Xiao, Yinqiao Li|arXiv (Cornell University)|Jun 26, 2019
Topic ModelingComputer Science20 references7 citations
TL;DR

This paper proposes Shared Attention Networks (San), a method to accelerate Transformer inference by sharing attention weights across adjacent layers in both self-attention and encoder-decoder attention mechanisms. By enabling vertical reuse of hidden states and jointly learning sharing policies, San achieves 1.3× speed-up over a cached baseline and up to 16× speed-up without caching, with minimal BLEU degradation.

ABSTRACT

Recently, the Transformer machine translation system has shown strong results by stacking attention layers on both the source and target-language sides. But the inference of this model is slow due to the heavy use of dot-product attention in auto-regressive decoding. In this paper we speed up Transformer via a fast and lightweight attention model. More specifically, we share attention weights in adjacent layers and enable the efficient re-use of hidden states in a vertical manner. Moreover, the sharing policy can be jointly learned with the MT model. We test our approach on ten WMT and NIST OpenMT tasks. Experimental results show that it yields an average of 1.3X speed-up (with almost no decrease in BLEU) on top of a state-of-the-art implementation that has already adopted a cache for fast inference. Also, our approach obtains a 1.8X speed-up when it works with the extsc{Aan} model. This is even 16 times faster than the baseline with no use of the attention cache.

Motivation & Objective

  • Address the high inference latency of Transformer models caused by auto-regressive decoding and repeated dot-product attention computations.
  • Reduce redundant computation in stacked attention layers by exploiting structural similarity in attention weight distributions across adjacent layers.
  • Develop a joint learning framework that optimizes both the sharing policy and the MT model end-to-end, rather than using heuristic sharing rules.
  • Minimize memory footprint by reusing hidden states across layers through weight sharing.
  • Achieve fast inference without significant accuracy loss, especially in combination with existing acceleration techniques like attention caching.

Proposed method

  • Propose a shared attention network (San) that shares attention weights vertically across adjacent layers in both self-attention and encoder-decoder attention sub-layers.
  • Formulate the attention mechanism such that the same attention weight matrix is used across multiple stacked layers, reducing redundant computation.
  • Introduce a joint training strategy where the sharing policy is learned end-to-end with the MT model, allowing the network to automatically discover optimal sharing patterns.
  • Enable efficient reuse of hidden states by storing them in shared memory locations, reducing memory footprint and accelerating inference.
  • Integrate San with existing acceleration techniques such as attention caching and the Aan model, demonstrating orthogonal and complementary improvements.
  • Use the scaled dot-product attention mechanism as the base, with shared weights applied across layers to maintain model structure while improving efficiency.

Experimental results

Research questions

  • RQ1Can attention weight sharing across adjacent layers reduce inference time in Transformers without degrading translation quality?
  • RQ2Does joint learning of the sharing policy with the MT model lead to better performance and faster convergence than heuristic sharing strategies?
  • RQ3How effective is San when combined with existing acceleration methods like attention caching or the Aan model?
  • RQ4To what extent do adjacent layers in trained Transformers exhibit similar attention weight distributions, supporting the feasibility of weight sharing?
  • RQ5Can San reduce memory usage while maintaining or improving inference speed in sequence-to-sequence models?

Key findings

  • San achieves an average of 1.3× speed-up over a state-of-the-art Transformer implementation that already uses an attention cache, with almost no drop in BLEU score.
  • When combined with the Aan model, San achieves a 1.8× speed-up, demonstrating complementary benefits across different acceleration techniques.
  • The system with San and Aan combined is up to 16× faster than the baseline without any caching mechanism.
  • The JS divergence between attention weight distributions of adjacent layers decreases significantly during training, indicating that layers naturally converge to similar attention patterns.
  • The training likelihood of San is slightly higher than the baseline, suggesting that the model remains effective and stable under the sharing regime.
  • The method is simple to implement, orthogonal to existing techniques, and directly applicable to various Transformer variants.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.