LLaMA-MoE: Building Mixture-of-Experts from LLaMA with Continual Pre-training

Tong Zhu, Xiaoye Qu, Daize Dong, Jiacheng Ruan, Jingqi Tong, Conghui He, Yu Cheng · DOI

Introduction

As Large Language Models (LLMs) continue to scale, the computational cost associated with both training and inference grows exponentially. While dense models like LLaMA-2 provide impressive capabilities, their "computational tax" makes deployment at scale increasingly challenging. Sparse Mixture-of-Experts (MoE) architectures offer a solution by activating only a subset of parameters for each input token, thereby decoupling model capacity from inference cost.

However, MoEs are notoriously difficult to train from scratch, often requiring massive datasets and facing significant training instabilities. LLaMA-MoE presents a novel framework to "recycle" existing dense LLMs into sparse MoE models. By partitioning the weights of a pre-trained LLaMA-2 7B model and performing targeted continual pre-training, the researchers demonstrate a path to high-performance sparse models that significantly reduces the computational budget compared to traditional MoE training.

Methodology: From Dense to Sparse

The transformation process involves a two-stage framework: expert construction and recovery through continual pre-training.

1. Expert Construction

The core of the LLaMA-MoE approach lies in splitting the Feed-Forward Networks (FFNs) of the original dense model into multiple smaller "experts." The authors explored several partitioning strategies to determine the most effective way to distribute pre-trained knowledge:

  • Independent-Random: Neurons are assigned to experts randomly. Surprisingly, this method performed the best.
  • Independent-Clustering: Weight vectors are grouped using K-means clustering to ensure experts contain similar neurons.
  • Sharing-Inner/Inter: Importance-based methods where certain "critical" neurons are shared across multiple experts to preserve core capabilities.

To maintain numerical stability, the authors introduced a Re-scaling factor ($N/k$). Because the number of activated parameters in the MoE is smaller than in the original dense model, scaling the output by the ratio of total experts to activated experts is crucial for maintaining the output magnitude inherited from the dense model.

2. Continual Pre-training

Partitioning the weights inevitably disrupts the model's internal representations. To recover performance and allow the newly initialized "gate" networks to learn effective routing, the model undergoes continual pre-training. The authors utilized a 200B-token subset of the SlimPajama dataset. This stage is significantly more efficient than full pre-training, as the model leverages the foundational knowledge already embedded in the LLaMA-2 weights.

Key Insights and Analysis

The study yielded several vital findings for the development of efficient MoE models:

  • The Efficacy of Randomness: Counter-intuitively, the Independent-Random partitioning strategy outperformed more complex clustering or sharing methods. The researchers suggest that structured splits might introduce biases that hinder the gate networks' ability to learn optimal routing during the recovery phase.
  • Layer Specialization: Analysis of routing patterns revealed that deeper layers in the MoE exhibit much stronger specialization than shallower layers. Early layers appear to handle general feature extraction, while later layers develop domain-specific expertise.
  • Efficiency Gains: The LLaMA-MoE approach proved to be far more resource-efficient than training from scratch. The models achieved higher performance levels with a fraction of the training tokens typically required for dense or MoE models of comparable size.

Performance Results

The primary model evaluated, LLaMA-MoE-3.5B (which activates 3.5B parameters per token), was tested against a comprehensive suite of benchmarks, including MMLU, ARC, and HellaSwag.

The results indicate that LLaMA-MoE-3.5B significantly outperforms dense models of similar inference cost, such as Sheared-LLaMA-2.7B and Open-LLaMA-3B-v2. On the Open LLM Leaderboard, after instruction tuning with curated ShareGPT data, LLaMA-MoE-3.5B achieved an average score of 48.95, surpassing its dense counterparts.

Limitations and Future Work

While LLaMA-MoE demonstrates a successful transition from dense to sparse, certain challenges remain:

  • Early Layer Imbalance: In the first two layers, some experts are rarely selected by the gate networks. This suggests that these layers might be over-parameterized and could benefit from further compression or pruning.
  • Data Sampling Optimization: The choice of "reference loss" for dynamic data sampling during pre-training significantly impacts performance. Optimizing this selection remains an open area for research.
  • Advanced Partitioning: Although random splitting was most effective in this study, the authors suggest that hybrid strategies—perhaps using structured partitioning specifically for the more specialized later layers—could yield further improvements.

Conclusion

LLaMA-MoE provides a robust proof-of-concept for the efficient creation of sparse models from dense checkpoints. By bypassing the need for training from scratch, this method democratizes the development of high-performance MoE models, offering a scalable and cost-effective path forward for the next generation of Large Language Models.

Summary updated

BibTeX
@inproceedings{zhu2024llama,
  author = {Tong Zhu and Xiaoye Qu and Daize Dong and Jiacheng Ruan and Jingqi Tong and Conghui He and Yu Cheng},
  title = {{LLaMA-MoE: Building Mixture-of-Experts from LLaMA with Continual Pre-training}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2024},
  doi = {10.18653/v1/2024.emnlp-main.890},
}
Figure