LV-BERT: Exploiting Layer Variety for BERT

Weihao Yu, Zihang Jiang, Fei Chen, Qibin Hou, Jiashi Feng

Abstract

Transformer-based language models typically adhere to a rigid architectural template, stacking self-attention and feed-forward layers in a fixed, interleaved sequence. This paper introduces LV-BERT, which breaks this "stereotyped" design by incorporating Layer Variety. By expanding the primitive layer set to include dynamic convolutions and utilizing an evolutionary search to optimize layer ordering, LV-BERT achieves superior efficiency and performance. On the GLUE benchmark, LV-BERT-small outperforms ELECTRA-small by 1.8 points, demonstrating that structural diversity is a key lever for advancing pre-trained language models.

The Problem: Rigid Architectural Patterns

Since the introduction of the Transformer, models like BERT, GPT, and RoBERTa have largely followed a "one-size-fits-all" structural pattern: strictly interleaved Self-Attention (SA) and Feed-Forward (FF) layers. This approach faces two primary challenges:

  1. Computational Redundancy: Many self-attention heads focus on local dependencies. This is inefficient, as convolutions are naturally better suited and more computationally efficient for capturing local information.
  2. Suboptimal Ordering: The standard interleaved pattern lacks strong empirical justification as the global optimum. While variations like "sandwich" patterns exist, the vast search space of layer sequences—over 280 billion possibilities for a 24-layer model—remains largely unexplored due to the prohibitive cost of training each candidate from scratch.

To navigate this massive search space efficiently, the authors propose a two-stage framework:

1. Supernet Pre-training with Weight Sharing

The authors construct a "supernet" where each layer position can host one of three types: Self-Attention, Feed-Forward, or Dynamic Convolution (DC). During pre-training, a single layer type is randomly sampled at each step. This allows all possible sub-architectures to share weights within a single pre-trained model, bypassing the need for individual training.

Following supernet pre-training, an evolutionary algorithm identifies the optimal layer sequence. To avoid the slow process of fine-tuning every candidate on downstream tasks, the authors use Masked Language Modeling (MLM) accuracy on a validation set as a proxy for general language understanding.

The LV-BERT training and search pipeline: (1-2) Supernet pre-training with weight sharing, (3-6) Evolutionary search using MLM accuracy, and (7-8) Scaling the optimal architecture.

3. Scaling

The search is conducted on a "small" model scale to minimize costs. The discovered "optimal" motifs are then scaled up to "medium" and "base" configurations.

Key Results

LV-BERT consistently outperforms established baselines with comparable parameter counts and FLOPs.

  • GLUE Benchmark: LV-BERT-small achieved a score of 79.8 on the test set, significantly higher than the ELECTRA-small baseline (78.0). LV-BERT-base reached 85.1, surpassing ELECTRA-base (83.5).
  • SQuAD 2.0: The performance gap was even wider in question-answering tasks, where LV-BERT-small reached a 73.7 F1 score compared to ELECTRA-small’s 69.4.
Comparison of GLUE average accuracy on the development set across different model architectures.

Insights: The Value of Variety

The search process yielded several critical architectural insights:

  • Local-to-Global Hierarchy: The optimal architectures tended to place Dynamic Convolutions at the bottom and Self-Attention at the top. This supports the intuition that lower layers should focus on local feature extraction (words/phrases), while higher layers should handle global context fusion.
  • Structural Synergy: While adding convolutions alone improves performance, the greatest gains come from the synergy of new layer types and optimized ordering.
  • Scale Invariance: Architectures optimized at a small scale transferred effectively to larger models, suggesting that these structural motifs are fundamental to language modeling.

Conclusion and Future Work

LV-BERT demonstrates that the traditional Transformer backbone is suboptimal. By embracing layer variety and automated search, we can build more efficient and powerful models. Future research may expand the search space to include more diverse operations like linear attention or task-specific layer sequences for specialized domains.

Summary updated

BibTeX
@inproceedings{yu2021lv,
  author = {Weihao Yu and Zihang Jiang and Fei Chen and Qibin Hou and Jiashi Feng},
  title = {{LV-BERT: Exploiting Layer Variety for BERT}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2021},
  doi = {10.18653/v1/2021.findings-acl.2},
}
Figure