[Paper Review] Pay Attention when Required
This paper proposes PAR Transformer, a more efficient Transformer architecture that reduces self-attention blocks by 63% while maintaining state-of-the-art perplexity on WikiText-103. Using differentiable neural architecture search, it identifies that self-attention is only needed in the first two-thirds of layers, achieving 35% lower inference latency with no accuracy drop across multiple datasets and models including BERT.
Transformer-based models consist of interleaved feed-forward blocks - that capture content meaning, and relatively more expensive self-attention blocks - that capture context meaning. In this paper, we explored trade-offs and ordering of the blocks to improve upon the current Transformer architecture and proposed PAR Transformer. It needs 35% lower compute time than Transformer-XL achieved by replacing ~63% of the self-attention blocks with feed-forward blocks, and retains the perplexity on WikiText-103 language modelling benchmark. We further validated our results on text8 and enwiki8 datasets, as well as on the BERT model.
Motivation & Objective
- To optimize Transformer architecture by rethinking the placement and proportion of self-attention and feed-forward blocks.
- To reduce computational cost and inference latency in large-scale language models without sacrificing performance.
- To identify optimal architectural patterns through automated search, focusing on block ordering and composition.
- To validate the generalization of findings across multiple datasets (WikiText-103, enwiki8, text8) and model types (BERT, Transformer-XL).
- To provide an explainable, automated method for designing efficient Transformer families using differentiable neural architecture search.
Proposed method
- Employed differentiable neural architecture search (NAS) with a search space of three block types: self-attention, feed-forward, and identity.
- Constructed a super-network where each layer is a differentiable weighted combination of the three block types, using Gumbel-Softmax to sample during training.
- Trained a single supernet to jointly optimize for accuracy and efficiency, enabling linear-complexity search across 3^32 possible architectures.
- Used the learned attention probabilities to derive design rules: self-attention is only needed in the first two-thirds of layers, and a p:1 ratio (p=5) of self-attention to feed-forward blocks is optimal.
- Applied the derived rules to create PAR Transformer and PAR BERT models with reduced attention blocks but retained performance.
- Validated results across multiple benchmarks (WikiText-103, enwiki8, text8) and tasks (language modeling, QA, sentiment analysis) using standard hyperparameters and inference settings.
Experimental results
Research questions
- RQ1What is the optimal ordering and proportion of self-attention and feed-forward blocks in a Transformer encoder?
- RQ2At what point do additional self-attention blocks provide diminishing returns in terms of performance gain?
- RQ3Can a reduced number of self-attention blocks maintain model accuracy while significantly lowering inference cost?
- RQ4Does the optimal architecture pattern generalize across different datasets and model architectures (e.g., BERT, Transformer-XL)?
- RQ5Can differentiable NAS be used to derive explainable, efficient architectural design rules for Transformers?
Key findings
- PAR Transformer reduces self-attention blocks by 63% compared to Transformer-XL, achieving 35% lower inference latency on WikiText-103 with identical perplexity.
- The optimal architecture uses self-attention only in the first two-thirds of layers, with a 5:1 ratio of feed-forward to self-attention blocks.
- On the WikiText-103 dataset, PAR Transformer Base maintains the same test perplexity as Transformer-XL Base while reducing latency to 0.65x.
- The PAR design rules generalize to other datasets: PAR Transformer achieves comparable performance on enwiki8 and text8 with reduced compute.
- PAR BERT Base matches BERT Base performance on pre-training loss and MRPC/SST-2 fine-tuning, with 1% accuracy drop on SQuAD v1.1, despite using half the self-attention blocks.
- PAR BERT achieves comparable latency to DistilBERT while using twice as many layers and a simpler training paradigm, suggesting architectural efficiency without distillation.
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.