Introduction
Large Language Models (LLMs) scale predictably: increasing parameter count generally improves performance. However, dense models apply every parameter to every token, making scaling computationally brutal. The Mixture of Experts (MoE) architecture solves this by routing tokens to only a subset of parameters (experts), effectively decoupling model capacity from compute cost.
Unfortunately, training MoEs from scratch is notoriously expensive and prone to instability. A popular workaround is "upcycling"—taking an existing pre-trained dense model, branching it into copies, training those copies on specialized domains (like math or code), and then stitching them together into an MoE. State-of-the-art methods like Branch-Train-MiX (BTX) do this by using the specialized models' Feed-Forward Networks (FFNs) as the MoE experts. However, they simply average the attention parameters across all the specialized models. This throws away valuable domain-specific knowledge embedded in the attention layers and can actually degrade performance due to averaging divergent weights.
This paper introduces BAM (Branch-Attend-Mix), a method to efficiently upcycle pre-trained dense models into an MoE by converting both their feed-forward and attention layers into experts.
The BAM Methodology
BAM operates in three distinct phases:
- Branching a dense seed model into multiple copies.
- Continued Pre-training of each copy on specialized data domains.
- Mixture Model Training, where these specialized models initialize the MoE.
The core novelty of BAM lies in how it initializes the MoE to preserve specialized knowledge:
- Mixture of Attention (MoA): Instead of just creating FFN experts, BAM also creates Attention Experts. The attention weights from the specialized dense models are preserved as distinct experts rather than averaged.
- Soft Routing: Traditional MoEs use top-$k$ routing (picking the best 1 or 2 experts per token). BAM uses soft routing for its attention experts, meaning every token is processed by all attention experts, weighted by a routing network. This stabilizes training and avoids load-balancing issues.
- Parallel Attention Architecture: To offset the extra compute required by soft routing, BAM uses a parallel transformer architecture where attention and FFN layers are computed concurrently. This effectively "hides" the extra attention compute behind the heavier FFN computations.
BAM explores two variants for upcycling MoA layers:
- BAM (Expert KV): Every attention expert gets its own Query, Key, and Value (QKV) matrices for maximum performance.
- BAM (Shared KV): Only the Query matrices are expert-specific; Key and Value matrices are shared across all experts. This drastically reduces memory overhead and KV-cache size during inference.
Key Insights
The authors highlight that averaging attention weights is actively harmful. When models are trained on highly distinct domains (like law vs. code), their attention mechanisms learn different patterns. Uniformly averaging them to initialize an MoE dilutes this specialized knowledge. Upcycling them as distinct experts preserves it.
Furthermore, soft routing is crucial for attention experts. Using standard top-1 or top-2 routing for attention experts yielded almost no improvement over the baseline; soft routing was the secret sauce needed to surpass baseline performance by smoothing the optimization landscape.
Results and Performance
The authors tested BAM using seed models of 590 Million and 2 Billion parameters across specialized domains including Math, Code, and Law (augmented with general pre-train data).
- Perplexity: BAM consistently beat the BTX baseline across all domains under both compute-matched and data-matched regimes. For the 2B model, BAM (Expert KV) achieved an average perplexity of 3.19 compared to BTX's 3.27.
- Downstream Tasks: At the 2B scale, BAM (Expert KV) scored an average of 34.02% across all zero-shot and few-shot benchmarks, noticeably outperforming the BTX baseline (32.71%).
Limitations and Future Work
While highly effective, BAM does introduce inference overhead. Because BAM (Expert KV) maintains separate KV caches for each expert, it is slower during inference (6.17s to generate 16 tokens) compared to standard BTX (4.81s). However, the BAM (Shared KV) variant successfully mitigates this, dropping latency to 5.96s while still outperforming BTX in task accuracy. Future work may focus on optimizing the training data mixtures across the three phases of BAM and further optimizing inference code and hardware utilization to close the latency gap.
Summary updated