LLaMA-MoE v2: Exploring Sparsity of LLaMA from Perspective of Mixture-of-Experts with Post-Training

Xiaoye Qu, Daize Dong, Xuyang Hu, Tong Zhu, Weigao Sun, Yu ChengarXiv 2024 · DOI

Introduction

The landscape of Large Language Models (LLMs) is increasingly dominated by Mixture-of-Experts (MoE) architectures. By activating only a subset of parameters for any given input, MoE models achieve high capacity with manageable computational costs. However, the standard practice of training MoE models from scratch is resource-intensive. LLaMA-MoE v2 introduces a more efficient path: "upcycling" existing dense models like LLaMA3-8B into sparse MoE versions using a novel post-training strategy.

The Challenge of Efficient MoE Upcycling

Traditional upcycling methods primarily target the Multi-Layer Perceptron (MLP) layers and rely on massive continual pre-training—often involving trillions of tokens—to recover performance. This approach is computationally expensive and often overlooks the potential for sparsity within the Attention mechanism.

Comparison of the LLaMA-MoE v2 pipeline versus previous upcycling approaches.

LLaMA-MoE v2 addresses these limitations by sparsifying both Attention and MLP modules and replacing expensive pre-training with a targeted two-stage post-training pipeline.

The LLaMA-MoE v2 Architecture

The framework transforms a dense model into an "Instructed MoE" through several key structural innovations:

Detailed architecture of LLaMA-MoE v2, featuring sparsified Attention and MLP modules.
  • Attention MoE: Original attention heads are grouped into experts. A router selects the top-$K$ head groups to activate per token, recognizing that not all heads are equally critical for every task.
  • Residual MLP MoE: Instead of a simple split, this architecture employs a "shared expert" that is always active to capture fundamental knowledge, alongside "routed experts" for specialized information.
  • Optimized Initialization: Routers are initialized using balanced k-means clustering on hidden features. A gradient-based "Importance-Based Neuron Partition" determines the allocation of neurons between shared and routed experts.

Two-Stage Post-Training

The "secret sauce" of LLaMA-MoE v2 is its training efficiency:

  1. Stage 1 (General Recovery): The model is tuned on diverse conversation data to restore basic linguistic capabilities.
  2. Stage 2 (Specialization): The model is fine-tuned on math and coding datasets while maintaining a small portion of general data to mitigate catastrophic forgetting.

Architectural Findings

The researchers' exploration revealed several critical insights into model sparsity:

  • MLP vs. Attention Sparsity: The MLP module is significantly more compressible than the Attention module. Activating 25% of MLP experts (2/8) yielded better results than activating 50% of Attention experts (4/8).
  • Granularity Limits: While finer-grained experts (increasing the count from 8 to 16) generally improve performance, there is a point of diminishing returns; moving to 32 experts led to performance degradation.
  • Utility of Shared Experts: The Residual MoE approach (incorporating a shared expert) consistently outperformed standard MoE, confirming that certain "universal" knowledge should remain accessible to all tokens.

Performance Benchmarks

Evaluated on LLaMA3-8B, the resulting model activates only 3.8B parameters while maintaining high performance across a battery of benchmarks.

  • Math and Coding: LLaMA-MoE v2 achieved a score of 55.04 on GSM8K, vastly outperforming smaller dense models like Gemma-2-2b (26.31) and earlier upcycled versions.
  • Training Efficiency: The model reached these levels using only billions of tokens, a fraction of the trillions typically required for MoE recovery.
  • Instruction Following: On the IFEval benchmark, the model demonstrated that post-training effectively "heals" the performance loss typically associated with sparsification.

Future Directions

While LLaMA-MoE v2 significantly narrows the gap, the sparse model still slightly trails the original dense 8B model in general knowledge (MMLU). Future work will focus on scaling these techniques to larger models, such as the LLaMA 3.1 70B and 405B series, and deeper investigation into the specific knowledge specialization of individual experts.

Summary updated

BibTeX
@misc{qu2024llama,
  author = {Xiaoye Qu and Daize Dong and Xuyang Hu and Tong Zhu and Weigao Sun and Yu Cheng},
  title = {{LLaMA-MoE v2: Exploring Sparsity of LLaMA from Perspective of Mixture-of-Experts with Post-Training}},
  year = {2024},
  eprint = {2411.15708},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2411.15708},
}
Figure