[Paper Review] Length-Adaptive Transformer: Train Once with Length Drop, Use Anytime with Search
This paper proposes Length-Adaptive Transformer, a single-model framework that enables efficient, anytime inference across diverse computational budgets. By training with LengthDrop—a structured dropout that stochastically reduces sequence length at each layer—and using multi-objective evolutionary search, the model derives optimal length configurations without retraining. The method extends PoWER-BERT to token-level tasks via a Drop-and-Restore process, achieving superior accuracy-efficiency trade-offs on SQuAD 1.1, MNLI-m, and SST-2 with up to 3x speed-up.
Despite transformers' impressive accuracy, their computational cost is often prohibitive to use with limited computational resources. Most previous approaches to improve inference efficiency require a separate model for each possible computational budget. In this paper, we extend PoWER-BERT (Goyal et al., 2020) and propose Length-Adaptive Transformer that can be used for various inference scenarios after one-shot training. We train a transformer with LengthDrop, a structural variant of dropout, which stochastically determines a sequence length at each layer. We then conduct a multi-objective evolutionary search to find a length configuration that maximizes the accuracy and minimizes the efficiency metric under any given computational budget. Additionally, we significantly extend the applicability of PoWER-BERT beyond sequence-level classification into token-level classification with Drop-and-Restore process that drops word-vectors temporarily in intermediate layers and restores at the last layer if necessary. We empirically verify the utility of the proposed approach by demonstrating the superior accuracy-efficiency trade-off under various setups, including span-based question answering and text classification. Code is available at https://github.com/clovaai/length-adaptive-transformer.
Motivation & Objective
- To address the high inference cost of large pre-trained transformers, especially under constrained computational resources.
- To eliminate the need for training separate models per computational budget, enabling a single model to serve multiple deployment scenarios.
- To extend the applicability of PoWER-BERT beyond sequence-level classification to token-level tasks such as span-based question answering.
- To achieve fine-grained control over the accuracy-efficiency trade-off during inference through automated configuration search.
- To maintain model performance while significantly reducing FLOPs and wall-clock inference time across diverse NLP tasks.
Proposed method
- Introduce LengthDrop, a structured variant of dropout that stochastically drops sequence tokens at each transformer layer based on a random length ratio, enabling robustness to varying sequence lengths during inference.
- Train a single transformer model once with LengthDrop, allowing the extraction of multiple sub-models with different effective sequence lengths without retraining.
- Apply a multi-objective evolutionary search to identify length configurations that maximize accuracy while minimizing FLOPs and inference time under any given computational budget.
- Design a Drop-and-Restore process that temporarily sets aside word vectors in intermediate layers (like PoWER-BERT) but restores them at the final layer, enabling compatibility with token-level tasks.
- Use the evolutionary search to generate a full Pareto frontier of accuracy-efficiency trade-offs, enabling deployment for any target budget.
- Integrate the framework into existing HuggingFace Transformers-based models, ensuring broad compatibility and ease of deployment.
Experimental results
Research questions
- RQ1Can a single transformer model be trained once and adapted to any inference-time computational budget without retraining or fine-tuning?
- RQ2How can the accuracy-efficiency trade-off be optimized across diverse computational constraints using a unified model?
- RQ3Can PoWER-BERT’s efficiency mechanism be extended to token-level classification tasks such as span-based question answering?
- RQ4What is the performance gain in inference speed and FLOPs when using length-adaptive inference compared to standard transformers?
- RQ5How does the evolutionary search strategy compare to heuristic or threshold-based methods in finding optimal length configurations?
Key findings
- The Length-Adaptive Transformer achieves up to 3x speed-up in wall-clock inference time and FLOPs compared to standard BERT, with no drop in accuracy on SQuAD 1.1, MNLI-m, and SST-2.
- The model maintains strong performance across all tested length configurations, demonstrating robustness to sequence length variations due to LengthDrop.
- The evolutionary search successfully identifies optimal length configurations that lie on the Pareto frontier of accuracy and efficiency, outperforming heuristic or fixed-threshold approaches.
- The Drop-and-Restore process enables PoWER-BERT’s efficiency mechanism to be applied to token-level tasks, such as span-based question answering, which was previously infeasible.
- The framework achieves superior accuracy-efficiency trade-offs compared to existing methods, including Slimmable Networks and DynaBERT, across multiple NLP benchmarks.
- The approach is modular and compatible with HuggingFace Transformers, enabling easy integration into existing NLP pipelines and future extension to multimodal models.
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.