LEAP: Layer-wise Exit-Aware Pretraining for Efficient Transformer Inference

Shashank Kapadia, Deep Narayan Mishra, Sujal Reddy Alugubelli, Haoan Wang, Saipraveen Vabbilisetty, Rishi Bhatia, Anupriya Sharma

TL;DR

This paper introduces LEAP, a novel pre-training objective that resolves a fundamental incompatibility between knowledge distillation and early exit mechanisms in transformers. LEAP enables distilled models to achieve significant inference speedups (up to 1.61x) without sacrificing performance, a feat previously unattainable.

What Problem Does This Paper Address?

Modern NLP models, especially transformers, are computationally expensive. Two popular approaches to make them more efficient are:

  1. Knowledge Distillation: Training smaller "student" models to mimic larger "teacher" models. This often involves aligning the representations of intermediate layers in the student to the corresponding layers in the teacher.
  2. Early Exit: Allowing transformer models to stop processing a sequence at an intermediate layer if its representation has sufficiently "converged," meaning it's unlikely to change much in subsequent layers. This saves computation by skipping later layers.

The problem is that these two approaches, when combined, don't work as expected. The authors found that standard layer-aligned distillation actually prevents early exit from being effective. By forcing intermediate layers to mimic their teacher counterparts, the student model's representations become too uniform and never stabilize early, thus negating the benefits of early exit. This leads to a situation where practitioners deploy early exit on distilled models, observe early exits, but measure no actual speedup.

Methods

The core contribution is LEAP (Layer-wise Exit-Aware Pretraining), an auxiliary training objective that augments standard distillation. LEAP doesn't require any architectural changes to the transformer or introduce new parameters during inference. Its key innovation is a single constraint:

  • Ensuring Intermediate Layers Approximate Final-Layer Representations: LEAP adds a loss term that encourages intermediate student layers to produce representations similar to the final layer of the student model, not just their corresponding teacher layer. This promotes representational convergence, which is crucial for early exit.

The LEAP loss function combines:

  • Final Layer Distillation ($L_{final}$): Standard matching of the student's final output to the teacher's.
  • Intermediate Layer Distillation ($L_{inter}$): Standard layer-wise matching.
  • Early Exit Quality Loss ($L_{exit}$): The novel component that trains intermediate layers to approximate the final output, using a soft margin loss.
  • Contrastive Distillation ($L_{contrast}$): Aligns similarity structures.

For inference, LEAP uses a k-skip patience-based early exit mechanism. This compares the current layer's representation to that of k layers prior to detect convergence.

Datasets

  • Training: The models were trained on a combination of 1.5 million sentences from various sources:
  • SNLI (Stanford Natural Language Inference)
    • MultiNLI (Multi-Genre NLI)
    • QQP (Quora Question Pairs)
    • MRPC (Microsoft Research Paraphrase Corpus)
    • XNLI (Cross-lingual NLI)
  • Evaluation:
    • STS-B (Semantic Textual Similarity Benchmark): Used for evaluating sentence similarity quality.
  • BEIR (Benchmarking Information Retrieval): A collection of datasets used for evaluating retrieval performance.

Key Insights and Ideas

  • Distillation vs. Early Exit Incompatibility: The paper empirically demonstrates that standard layer-aligned distillation actively suppresses the representational redundancy that early exit mechanisms rely on. This is a critical finding for anyone trying to optimize transformer inference.
  • LEAP Reconciles the Conflict: By explicitly training intermediate layers to approximate the final student representation, LEAP creates the necessary conditions for early exit to be effective, even on distilled models.
  • Early Exit Zone: LEAP creates a distinct "early exit zone" in the model (layers 6-8 in their experiments) where representations stabilize, allowing for consistent and meaningful early exits.
  • Quality-Speedup Tradeoff is Controllable: The exit threshold ($\theta$) allows practitioners to tune the balance between speedup and quality. A higher threshold means later exits and better quality, while a lower threshold yields faster inference with a potentially small quality drop.
  • Distillation Method Matters: Output-only distillation (like in DistilBERT) preserves early exit capabilities, while layer-aligned distillation (like in MiniLM, TinyBERT) breaks it. LEAP specifically targets the latter.

Key Results

  • Speedup: LEAP-MiniLM achieves a 1.61x measured wall-clock speedup (batch=1, NVIDIA L4) at an exit threshold of $\theta=0.95$. This corresponds to a 1.80x theoretical layer reduction.
  • Exit Rate: 91.9% of samples exit by layer 7 with LEAP at $\theta=0.95$.
  • Quality: LEAP-MiniLM maintains high quality, achieving a STS-B correlation of 0.760 ± 0.006, only a slight drop from the baseline (0.777) which offers no speedup.
  • Retrieval: LEAP shows competitive or improved performance on BEIR retrieval benchmarks compared to the baseline, with minimal quality cost.
  • Baseline Failure: Standard distilled models (MiniLM baseline) showed zero effective speedup when combined with early exit.

Limitations and Future Work

  • Requires Retraining: LEAP cannot be applied to existing pre-trained distilled checkpoints; it requires retraining the model with the LEAP objective. This is a one-time cost that amortizes over inference.
  • Embedding-Level Exit: LEAP is designed for embedding-level tasks (similarity, retrieval). For token-level tasks (NER, QA), a different approach for exit criteria might be needed.
  • Domain-Specific Evaluation: Current results are on English sentence similarity and BEIR. Performance on specialized domains (legal, medical, multilingual) may differ and requires validation.
  • Scale and Architecture: Most experiments were on 12-layer models. Extending to larger models (24+ layers) or different architectures (encoder-decoder, decoder-only) is future work.
  • Cross-Method Validation: While LEAP was tested on MiniLM, extending it to TinyBERT's MSE objective and evaluating on BERT-base are suggested.
  • Statistical Rigor: More extensive statistical validation (bootstrap confidence intervals, significance testing across hardware) is planned.

Summary updated

BibTeX
@inproceedings{kapadia2026leap,
  author = {Shashank Kapadia and Deep Narayan Mishra and Sujal Reddy Alugubelli and Haoan Wang and Saipraveen Vabbilisetty and Rishi Bhatia and Anupriya Sharma},
  title = {{LEAP: Layer-wise Exit-Aware Pretraining for Efficient Transformer Inference}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2026},
  url = {https://openreview.net/forum?id=oZ9tIHm3dw},
}
Figure