Reducing Transformer Depth on Demand with Structured Dropout

Angela Fan, Edouard Grave, Armand Joulin

Introduction

Transformer models have revolutionized Natural Language Processing (NLP), but they come with a heavy computational tax. They are often overparameterized, containing hundreds of millions of parameters, making them slow to run and memory-intensive.

This paper introduces LayerDrop, a structured dropout technique that randomly skips entire layers during training. This approach serves a dual purpose: it acts as a powerful regularizer allowing for the training of deeper, more stable Transformers, and it enables "on-demand" pruning. With LayerDrop, a single large model can be instantly shrunk to any desired depth at inference time without further fine-tuning.

The Problem: The "Train-Prune-Finetune" Cycle

While techniques like pruning and distillation exist to create smaller models, they typically require a tedious "train-prune-finetune" cycle for every specific target size. If a deployment scenario requires both a 6-layer model and an 8-layer model, practitioners usually have to train or distill two separate models from scratch.

The authors sought a way to train one large model that is inherently robust enough to have its layers stripped away at runtime to meet specific latency or memory constraints.

LayerDrop vs. traditional separate network training

Methods: Training with LayerDrop

The core innovation is LayerDrop, a form of structured dropout applied at the layer level.

  1. Training with LayerDrop: During training, instead of dropping individual neurons (standard Dropout) or individual weights (DropConnect), the authors randomly drop entire layers. This forces the network to learn representations that are redundant and robust across layers.
  2. Inference-Time Pruning: Because the model was trained to function even when layers are missing, layers can simply be "plucked out" at test time.

The authors explored several strategies for selecting which layers to keep during inference:

  • Every Other: Simply dropping every $n$-th layer (e.g., keeping layers 1, 3, 5...).
  • Search on Valid: Testing different combinations on a validation set to find the best-performing sub-network.
  • Data-Driven Pruning: Learning a specific drop rate for each layer.

Surprisingly, the simplest strategy—Every Other—performed remarkably well and was difficult to beat.

Key Insights and Results

The authors validated LayerDrop across a massive range of NLP tasks, including Machine Translation (WMT14, IWSLT), Language Modeling (WikiText-103), Summarization (CNN/Dailymail), Question Answering (ELI5), and Natural Language Understanding (GLUE benchmark).

  • Regularization is a "Free Lunch": LayerDrop isn't just for pruning; it's a superior regularizer. It stabilized the training of very deep Transformers (up to 40-50 layers) that otherwise would have diverged or overfit.
  • The "Sandwich" Importance: Through ablation studies, the authors found that the first and last layers of a Transformer are the most critical. The middle layers are much more redundant and are the best candidates for pruning.
  • State-of-the-Art Performance: On WikiText-103, a 40-layer Transformer with LayerDrop achieved a perplexity of 17.7, outperforming the previous SOTA (Transformer-XL).
  • Superior to Distillation: A 6-layer RoBERTa model extracted via LayerDrop outperformed DistilBERT on several GLUE tasks, despite the fact that LayerDrop requires no specialized distillation objective or secondary training phase.
Comparison of LayerDrop against baselines and DistilBERT on MNLI and SST-2
  • Efficiency and Training Speed: On WMT14, a 12-layer encoder model with LayerDrop reached 30.2 BLEU, outperforming standard 6-layer models while remaining prunable to smaller sizes on demand. Because layers are skipped during training, LayerDrop can actually speed up the training process (up to 2x faster if half the layers are dropped on average).

Limitations and Future Work

  • Focus on Depth: The paper primarily focuses on reducing depth. While they ablated dropping attention heads (width), the "on-demand" aspect is most effective for layers.
  • Task-Specific Tuning: While "Every Other" pruning works well, the authors note that for some tasks, the optimal pruning strategy might still benefit from a small amount of searching on a validation set.
  • Hardware Alignment: While reducing layers reduces theoretical FLOPs and latency, the actual wall-clock speedup depends on how the specific hardware handles the resulting architecture. Future work could involve hardware-aware LayerDrop schedules.

Summary updated

BibTeX
@inproceedings{fan2020reducing,
  author = {Angela Fan and Edouard Grave and Armand Joulin},
  title = {{Reducing Transformer Depth on Demand with Structured Dropout}},
  booktitle = {International Conference on Learning Representations},
  year = {2020},
}
Figure