[Paper Review] Faster Transformer Decoding: N-gram Masked Self-Attention
This paper proposes N-gram masked self-attention to accelerate Transformer decoding by restricting the self-attention context to only the previous N−1 target tokens, reducing computational complexity from O(T²) to O(N·T). Experiments on WMT EnDe and EnFr show that N=8 achieves near-baseline BLEU scores (within 0.3–0.4 BLEU) while enabling up to 2–3× speedup and reduced memory bandwidth.
Motivated by the fact that most of the information relevant to the prediction of target tokens is drawn from the source sentence $S=s_1, \ldots, s_S$, we propose truncating the target-side window used for computing self-attention by making an $N$-gram assumption. Experiments on WMT EnDe and EnFr data sets show that the $N$-gram masked self-attention model loses very little in BLEU score for $N$ values in the range $4, \ldots, 8$, depending on the task.
Motivation & Objective
- To reduce the computational and memory overhead of autoregressive Transformer decoding without significant performance degradation.
- To investigate whether limiting the self-attention context to a fixed N-gram window preserves translation quality in neural machine translation.
- To evaluate the trade-off between inference speed, memory efficiency, and model accuracy in sequence generation.
- To explore the feasibility of using a fixed-size buffer to store only the most recent N−1 tokens during beam search, reducing memory bandwidth.
Proposed method
- Introduce an N-gram masked self-attention mechanism that restricts the attention computation in the decoder to only the previous N−1 target tokens.
- Modify the standard causal self-attention mechanism by applying a mask that excludes tokens beyond the N−1 previous positions in the target sequence.
- Implement the N-gram attention as a configurable option in the Lingvo framework, replacing the full causal attention in the decoder layers.
- Use a sliding window buffer of size N−1 to store and update the context tokens incrementally during decoding, reducing memory access overhead.
- Maintain the full encoder-decoder attention mechanism while only modifying the decoder's self-attention to be N-gram limited.
- Train and evaluate models on WMT EnDe and EnFr datasets using standard Transformer architectures with word-piece tokenization and fixed hyperparameters.
Experimental results
Research questions
- RQ1How does limiting the self-attention context to N−1 previous tokens affect translation quality in terms of BLEU score?
- RQ2What is the optimal N-gram order (N) that balances speed and performance on machine translation tasks?
- RQ3To what extent can N-gram self-attention reduce computational complexity and memory bandwidth during inference?
- RQ4Does the N-gram mechanism preserve the model's ability to capture long-range dependencies despite the context truncation?
- RQ5Can the N-gram approach be efficiently implemented with a fixed-size buffer to reduce memory access during beam search?
Key findings
- For N=8 on WMT EnDe, the model achieves a BLEU score of 22.5 on the test set, only 0.1 BLEU below the baseline (22.4) and within 0.3–0.4 BLEU of the best-performing baseline.
- On WMT EnFr, N=8 yields a BLEU score of 32.7 on test data, matching the baseline (32.9) within 0.2 BLEU and outperforming smaller N-gram models.
- The N-gram model reduces computational complexity from O(T²) to O(N·T), enabling a theoretical speedup of approximately 2–3× for sequences of length T≈16–25.
- The model with N=8 achieves a log-perplexity of 2.66 on WMT EnDe test data, only slightly higher than the baseline’s 2.64, indicating minimal degradation in language modeling capacity.
- The N-gram mechanism allows for a fixed-size memory buffer of length N−1, reducing memory bandwidth by a factor of O(T/N), which is particularly beneficial on TPU hardware.
- Performance degrades gracefully for N≥3, with N=4 already achieving 22.2 BLEU on WMT EnDe, showing that even smaller N values are viable for speed-accuracy trade-offs.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.