Abstract
The large attention-based encoder-decoder network (Transformer) has become prevailing recently due to its effectiveness. But the high computation complexity of its decoder raises the inefficiency issue. By examining the mathematic formulation of the decoder, we show that under some mild conditions, the architecture could be simplified by compressing its sub-layers, the basic building block of Transformer, and achieves a higher parallelism. We thereby propose Compressed Attention Network, whose decoder layer consists of only one sub-layer instead of three. Extensive experiments on 14 WMT machine translation tasks show that our model is 1.42x faster with performance on par with a strong baseline. This strong baseline is already 2x faster than the widely used standard baseline without loss in performance.
Introduction
While Transformers have revolutionized Natural Language Processing, they face significant challenges during inference due to the autoregressive nature of the decoder. Generating text one token at a time requires each token to pass through multiple layers, each containing three sequential sub-layers: Self-Attention, Cross-Attention, and a Feed-Forward Network (FFN). This sequential "triple-decker" structure creates a computational bottleneck. Previous attempts to mitigate this often involved reducing decoder depth at the cost of accuracy. This paper introduces the Compressed Attention Network (CAN), which increases parallelism within the layer itself to achieve substantial speedups without sacrificing translation quality.
The Compressed Attention Network (CAN)
The core innovation of CAN is the mathematical collapse of the three traditional sub-layers into a single parallelized unit. The architecture is simplified based on two key observations:
- Parallelizing Attentions: Empirical analysis shows that inputs to self-attention and cross-attention sub-layers are highly similar (cosine similarity > 0.9). By assuming these inputs are identical, both mechanisms can be computed in parallel, sharing the "Query" projection and concatenating "Key" and "Value" projections.
- Merging the FFN: By exploiting the linearity of the initial FFN projection and the weighted-sum nature of attention, the authors mathematically fold the FFN's first step into the attention's value projection, removing redundant matrix multiplications.
Theoretical Justification
The "similarity assumption" is central to CAN's efficiency. Residual connections in standard Transformers keep representations stable enough that the input to the first sub-layer serves as an effective proxy for subsequent sub-layers within the same block. Heatmaps of the correlation between sub-layers demonstrate that the representations are highly correlated, justifying the compression of these operations into a single parallel step.
Experimental Results
CAN was evaluated on 14 machine translation tasks from the WMT14 and WMT17 benchmarks, covering diverse language pairs like English↔German and English↔French.
- Speed: CAN achieves a 1.42× speedup over a strong deep-encoder/shallow-decoder baseline and a 2.82× speedup over the standard 6-layer/6-layer Transformer.
- Quality: Translation quality remains robust. On WMT14 En-De, CAN achieved a BLEU score of 27.32, a negligible 0.14-point drop from the baseline. Performance gaps further narrow when using Knowledge Distillation.
- Efficiency: The model reaches maximum GPU utility at smaller batch sizes, making it ideal for real-time applications where large-batch processing is impractical.
Conclusion
By rethinking the internal linear algebra of the Transformer block, the Compressed Attention Network significantly reduces inference latency. While it shows a slight performance dip on very short sentences, its ability to maintain high-quality translation at nearly triple the speed of standard models marks a significant step forward for efficient NLP deployment. Future work may involve optimizing custom kernels to better leverage the high degree of parallelism offered by this architecture.
Summary updated