Abstract
Modular Neural Networks (MNNs) demonstrate various advantages over monolithic models. Existing MNNs are generally explicit: their modular architectures are pre-defined, with individual modules expected to implement distinct functions. Recent works reveal that there exists implicit modularity in standard pre-trained transformers, namely Emergent Modularity. They indicate that such modular structures spontaneously exhibit during the early pre-training phase. Despite the benefits of modularity, most Language Models (LMs) are still treated as monolithic models in the pre-train and fine-tune paradigm, with their emergent modularity locked and underutilized. In this work, focusing on unlocking the emergent modularity in LMs, we showcase that standard LMs could be fine-tuned as their Mixture-of-Expert (MoEs) counterparts without introducing any extra parameters. Such MoEs are derived from emergent modularity and are referred to as Emergent MoEs (EMoE). Our experiments demonstrate that fine-tuning EMoE effectively improves downstream in-domain and out-of-domain generalization compared with vanilla fine-tuning. Our analysis and ablation studies further illustrate that it is robust to various configurations and can scale up to Large Language Models (i.e., Llama2-7B and Llama-30B).
Introduction
Standard Large Language Models (LLMs) are typically treated as "monolithic" blocks—every neuron is potentially updated for every input during fine-tuning. However, research into "Emergent Modularity" (EM) shows that neurons in pre-trained Transformers actually self-organize into functional groups that specialize in specific concepts or tasks.
The authors argue that by treating these models as monolithic during fine-tuning, we "lock" this modularity and underutilize the model's potential. Furthermore, updating all neurons simultaneously can lead to negative transfer, where learning a new task inadvertently degrades the specialized knowledge stored in unrelated neurons. The challenge is: how can we unlock this modularity during fine-tuning without the massive computational cost of training a Mixture-of-Experts (MoE) model from scratch or adding millions of new parameters?
Methodology: Constructing EMoE
The proposed EMoE method transforms standard Feed-Forward Networks (FFNs) into sparse MoE layers through two main steps that introduce zero extra parameters:
- Clustering-based Expert Construction: By viewing the FFN as a key-value memory system, constrained clustering is applied to the "key" vectors (the first layer of the FFN). This groups neurons that tend to be co-activated into specialized "experts."
- Avg-k Gating: Instead of training a new gating network, EMoE uses a parameter-free approach. It averages the key vectors within each cluster to create a "prototype" for that expert. At runtime, the input is compared to these prototypes, and only the top-$k$ most relevant experts are activated.
Experimental Evaluation
The researchers validated EMoE across a wide range of architectures (BERT, GPT-2, T5, ViT, and Llama) using several benchmarks:
- GLUE & GLUE-X: For standard in-domain (ID) and out-of-domain (OOD) language understanding.
- MMLU: For massive multitask evaluation on Llama-7B and Llama-30B.
- Alpaca: For instruction-tuning experiments.
- Domainbed: A vision-based benchmark for Vision Transformers (ViT).
Key Results and Insights
EMoE consistently outperformed vanilla LoRA fine-tuning. On GPT2-XL, it reduced OOD error significantly (from 5.61 down to 3.88). On Llama2-7B, it improved the MMLU score from 46.96 to 47.58 with negligible extra training time.
Preventing Negative Transfer
EMoE acts as a sophisticated gradient router. By masking irrelevant neurons during training, it prevents the "noise" of a new task from overwriting specialized knowledge in other modules. This functional specialization is observable in how different tasks select different experts.
Stability and Scaling
Traditional MoEs often struggle with "expert collapse." EMoE’s "avg-k" gating is inherently more stable because it is derived from pre-trained weights. Furthermore, the performance gains largely remain even if the model is collapsed back into a dense model for deployment, proving the benefit comes from the modular weight updates during training. The method also scales effectively to Llama-30B, making it viable for state-of-the-art LLMs.
Limitations and Future Work
While promising, EMoE currently focuses on Feed-Forward Networks. Future work could explore emergent modularity in Attention layers. Additionally, while EMoE reduces theoretical FLOPs, current hardware/software stacks (like the tutel library) still have overhead that makes it slightly slower than dense models in practice. Future research into more sophisticated decomposition algorithms and hardware-optimized kernels for sparse computation will be crucial to fully realizing EMoE's potential.
Summary updated