Conditional Transformer Fine-Tuning by Adaptive Layer Skipping

Xingjian Zhang, Jiaxi Tang, Yang Liu, Xinyang Yi, Li Wei, Lichan Hong, Qiaozhu Mei, Ed H. ChiPML4LRS @ ICLR 2024

TL;DR

This paper introduces a novel method for fine-tuning Transformer models that dynamically adjusts the computational effort based on the complexity of each input sequence. By adaptively skipping layers for simpler inputs, they achieve significant training time reductions (up to 25%) without sacrificing predictive performance, making large Transformer models more efficient to train.

What Problem Does This Paper Address?

Modern deep learning models, particularly Transformers, have achieved remarkable success across various domains. However, a significant inefficiency lies in their uniform computational cost for all inputs, regardless of their inherent complexity. This means that even simple inputs are processed through the entire, computationally expensive network, leading to wasted resources. This paper aims to address this by making Transformer fine-tuning more efficient by allowing the model to adapt its computation based on the complexity of individual input sequences, mimicking how humans might allocate cognitive effort.

Methods

The core contribution is a sequence-level conditional fine-tuning framework that employs adaptive layer skipping. Instead of processing every input through all Transformer layers, this method dynamically determines how many layers an input sequence needs to pass through.

Here's a breakdown of the key components:

  • Adaptive Layer Skipping: The framework allows inputs to "exit" the Transformer at earlier layers if their complexity is deemed low. This is achieved by defining a ratio-based rule for a batch of examples, where a certain proportion of the batch (e.g., the simpler half) is configured to pass through fewer layers. This ensures a static computation graph for modern hardware like TPUs/GPUs, avoiding the inefficiencies of dynamic control flow.
  • Sequence Complexity Measurement: A crucial aspect is identifying an effective metric to gauge input complexity. The authors explore several heuristics, including sequence length and sequence diversity. Their key finding is that training loss at an early stage (specifically, "loss@1k" – training loss at 1000 steps) is a highly effective proxy for complexity. They hypothesize that early training loss is more discriminative because the loss distribution for simple and complex examples is more spread out at this stage compared to later stages where it might converge.
  • Pre-Layer Norm Transformer: The method is applied to the Pre-Layer Norm variant of the Transformer architecture, which is a common choice in modern models.

Datasets

The paper evaluates their method on two datasets:

  • ListOps: A synthetic dataset used for analyzing sequence-level input complexities. It involves list operations and requires understanding hierarchical data structures.
  • MovieLens: A real-world dataset commonly used for recommendation systems. The task here is item retrieval, where the model predicts the next movie a user will watch based on their history.

Key Insights and Ideas

  • Input Complexity Matters for Efficiency: The fundamental insight is that not all inputs require the full computational depth of a Transformer. Tailoring computation to input complexity is a viable path to significant efficiency gains.
  • Early Training Loss as a Complexity Proxy: The discovery that training loss at an early stage (loss@1k) is a surprisingly effective and practical metric for gauging sequence complexity is a key finding. This metric is more informative than sequence length or diversity for guiding adaptive layer skipping.
  • Adaptive Skipping for Hardware Efficiency: By using a ratio-based approach for layer skipping within a batch, the method maintains a static computation graph, which is crucial for efficient execution on accelerators like TPUs and GPUs.
  • Potential for Performance Improvement: Beyond just speed, the paper suggests that adaptive skipping might even lead to better performance than full fine-tuning, possibly by allowing deeper layers to specialize in more complex examples, acting like a form of "mixture of experts."

Key Results

  • Substantial Training Time Reduction: The proposed method achieves a substantial reduction in training time by at least 25% across both synthetic and real-world datasets.
  • Maintained Predictive Performance: Crucially, this speedup is achieved while maintaining the same predictive performance as full fine-tuning.
  • Outperforms Baselines: On both ListOps and MovieLens, their method demonstrates better performance-cost trade-offs compared to baselines like dropping last k layers or freezing first k layers.
  • Better than Full Fine-tuning: In some cases, the adaptive skipping method even achieved better accuracy than full fine-tuning on ListOps, despite using significantly less computation.

Limitations and Future Work

  • Inference Limitation: A major limitation is that the "loss@1k" complexity measure requires labels and training to compute, making it inaccessible during inference.
  • Future Work - Complexity Estimation: To address the inference limitation, the authors suggest developing a smaller predictor model to estimate complexity measurements, which would then guide layer skipping during inference.
  • Future Work - Threshold-Based Skipping: The current ratio-based skipping strategy relies on relatively large batch sizes. They propose adapting this to a threshold-based method by setting complexity quantiles as thresholds, which would be more practical.

Summary updated

BibTeX
@inproceedings{zhang2024conditional,
  author = {Xingjian Zhang and Jiaxi Tang and Yang Liu and Xinyang Yi and Li Wei and Lichan Hong and Qiaozhu Mei and Ed H. Chi},
  title = {{Conditional Transformer Fine-Tuning by Adaptive Layer Skipping}},
  booktitle = {PML4LRS @ ICLR},
  year = {2024},
  url = {https://openreview.net/forum?id=Rd0lJC3c9a},
}
Figure