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

Abstract

Scaling Large Language Models (LLMs) traditionally incurs massive computational costs. Mixture-of-Experts (MoE) architectures offer a solution by activating only a subset of parameters per token, yet training them from scratch is often unstable and data-intensive. This paper introduces LLaMA-MoE, a framework designed to "upcycle" existing dense models like LLaMA-2 into sparse MoE versions. By partitioning the original model's Feed-Forward Networks (FFNs) into experts and applying continual pre-training, the authors produce models that outperform dense counterparts of similar active-parameter sizes while utilizing only ~58% of the original inference compute.

Introduction

Modern LLM scaling involves increasing parameter counts, which leads to ballooning inference costs. MoE architectures decouple model capacity from inference cost by activating only a subset of experts for any given input. However, MoE models are notoriously difficult to train from scratch, often suffering from training instability and requiring vast datasets to converge. While previous work explored converting dense models to MoE, they primarily focused on older architectures like BERT or T5. LLaMA-MoE addresses the challenge of efficiently transforming a modern, high-performing dense decoder (LLaMA-2-7B) into a sparse MoE model using SwiGLU activations.

Methodology

The LLaMA-MoE framework consists of a two-stage process: Expert Construction and Continual Pre-training.

Expert Construction

The Feed-Forward Networks (FFNs) of a dense LLaMA-2-7B model are split into $n$ smaller experts. The authors evaluated several partitioning strategies, including random assignment, K-means clustering on weights, and neuron sharing. Surprisingly, IndependentRandom—randomly assigning neurons to experts—performed best, suggesting that knowledge in dense FFNs is sufficiently distributed for random subsets to specialize effectively during recovery. To maintain hidden state magnitude consistency immediately after splitting, a Scale Factor ($n/k$) is applied to the output of the $k$ activated experts.

Overview of the LLaMA-MoE framework, illustrating (a) the partitioning of dense FFNs into experts and (b) the subsequent continual pre-training process with a gating mechanism.

Continual Pre-training

Following construction, the model undergoes "recovery" through training on 200 billion tokens from the SlimPajama dataset. A lightweight Gate Network is added to each layer to learn token routing. This stage ensures the newly formed experts and the gating mechanism align to optimize performance.

Evaluation and Results

The models were evaluated across a wide battery of downstream tasks, including ARC, PIQA, HellaSwag, and MMLU, as well as instruction-following capabilities via MT-Bench.

Performance and Efficiency

LLaMA-MoE-3.5B (activating 4 out of 16 experts) achieved an average score of 57.7 across downstream tasks, outperforming competitive dense models like Sheared-LLaMA-2.7B (56.4) and OpenLLaMA-3B-v2 (55.6). Crucially, the model consumes only 57.7% of the FLOPs compared to the original LLaMA-2-7B.

Performance comparison and training loss curves for LLaMA-MoE variants against dense baselines and training-from-scratch models.

Key Insights

  • Fast Convergence: Upcycling dense weights allows the MoE model to converge significantly faster than training a similar MoE architecture from scratch.
  • Layer-wise Specialization: Deeper layers exhibit stronger expert specialization than shallow layers. While shallow layers capture general features, deep layers act as specialists for specific domains like code or natural language.
  • Instruction Following: After fine-tuning on ShareGPT, LLaMA-MoE-3.5B (2/8) scored 4.72 on MT-Bench, significantly higher than Sheared-LLaMA-2.7B (4.06), demonstrating high amenability to alignment.

Conclusion and Future Work

LLaMA-MoE demonstrates that "upcycling" dense models into sparse MoE architectures is an efficient path toward high-capacity, low-latency LLMs. Future work includes extending this framework to newer models like LLaMA-3, exploring the scaling laws of expert configurations more granularly, and investigating the potential for pruning rarely-selected experts in early layers to further compress the model.

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