LaDiMo: Layer-wise Distillation Inspired MoEfier

Sungyoon Kim, Youngjun Kim, Kihyo Moon, Minsung JangarXiv 2024 · DOI

Abstract

LaDiMo (Layer-wise Distillation Inspired MoEfier) is a novel algorithm designed to efficiently convert dense, pre-trained Transformer models into sparse Mixture-of-Experts (MoE) architectures. By leveraging layer-wise knowledge distillation and a training-free adaptive router, LaDiMo reduces activated parameters by over 20% and increases throughput by 10% while retaining 97% of the original model's accuracy. Notably, this transformation is achieved using only 100K tokens of training data, making it a highly cost-effective solution for model sparsification.

Introduction

Large Language Models (LLMs) have revolutionized natural language processing but are constrained by massive computational costs and environmental footprints. Sparse Mixture-of-Experts (MoE) architectures offer a solution by activating only a subset of parameters (experts) for any given input. However, training MoE models from scratch is prohibitively expensive.

Existing methods for "MoEfying" dense models face several hurdles: architecture constraints (e.g., dependence on ReLU activations), high resource intensity for retraining, and inefficient static routing policies. LaDiMo addresses these challenges with a two-stage pipeline that transforms dense models into efficient MoE structures with minimal data and compute requirements.

Methodology

Layer-wise Expert Construction

Instead of training from scratch, LaDiMo initializes experts by splitting the existing Feed-Forward Network (FFN) weights of a dense layer into $N$ smaller sub-matrices. It then employs Layer-wise Knowledge Distillation. In this setup, the original dense layer acts as a "teacher," and the new MoE block acts as the "student." The student is trained to minimize the Mean Squared Error (MSE) between its output and the teacher's output for the same input.

The LaDiMo framework: splitting dense FFNs into MoE blocks and using MSE loss to mimic the original layer's output.

Adaptive Routing Policy

The authors developed a training-free Adaptive Router. Rather than always selecting a fixed number of experts (e.g., top-2), the system profiles the distribution of routing weights using global and local quantiles. This allows for layer-specific policies:

  • Static top-k: Used if a layer consistently favors a specific number of experts.
  • Token-wise Dynamic: Used if a layer's needs vary per token, selecting the number of experts on the fly based on the confidence of the router's output.

Experimental Setup

Datasets

  • Training: Hidden states for distillation were gathered using the Chatbot Instruction Prompts dataset (approx. 100K tokens).
  • Evaluation: Performance was measured across standard benchmarks including MMLU (general knowledge), GSM8K (math), Winogrande (reasoning), and ARC Challenge.
  • Profiling: The PILE dataset was utilized to analyze routing weight distributions for the adaptive router.

Key Results

When applied to the LLaMA2-7B model, LaDiMo achieved the following:

  • Efficiency: Converted 12 dense layers into MoE layers, reducing activated parameters from 7B to 5.5B (a >20% reduction).
  • Throughput: Realized a 10% increase in throughput during inference.
  • Accuracy: Maintained 97% of the original MMLU accuracy.
  • Low Cost: The conversion required only 100K tokens and approximately 5 hours of training per layer on a single A100 GPU.

Discussion and Insights

  • Initialization Strategy: Initializing experts by splitting pre-trained dense weights leads to significantly faster convergence and lower loss compared to random initialization.
  • Layer Sensitivity: The authors observed a "bottom-heavy" strategy is most effective; replacing layers closer to the output (bottom-most) with MoE blocks has a lower negative impact on accuracy than replacing earlier layers. This suggests early layers hold more fundamental, non-redundant features.
  • Domain Recovery: If accuracy drops in specific domains (e.g., mathematics), training MoE blocks on a small amount of domain-specific data (like GSM8K) can recover performance without compromising general capabilities.
  • Training-Free Adaptivity: Unlike most adaptive routers that require extra training, LaDiMo's quantile-based approach allows for dynamic expert selection based purely on the statistical distribution of existing router weights.

Conclusion

LaDiMo provides a practical and efficient framework for converting dense LLMs into sparse MoE models. By focusing on layer-wise distillation and adaptive routing, it achieves significant gains in efficiency with minimal loss in performance. Future work will explore automated sensitivity analysis for layer selection and the impact of larger expert pools.

Summary updated

BibTeX
@misc{kim2024ladimo,
  author = {Sungyoon Kim and Youngjun Kim and Kihyo Moon and Minsung Jang},
  title = {{LaDiMo: Layer-wise Distillation Inspired MoEfier}},
  year = {2024},
  eprint = {2408.04278},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2408.04278},
}
Figure