TL;DR
Linear-MoE is an open-source, production-ready system that merges Linear Sequence Modeling (linear attention, SSMs, and linear RNNs) with sparsely activated Mixture-of-Experts (MoE). By replacing quadratic softmax attention with linear-complexity recurrent updates in an MoE framework, it maintains stable throughput and flat GPU memory usage as sequence lengths scale, matching or outperforming standard Transformer-MoE models on standard language benchmarks.
What Problem Does This Paper Address?
While modern Mixture-of-Experts (MoE) architectures achieve impressive parameter scaling by selectively routing tokens to a subset of Feed-Forward Network (FFN) "experts," their sequence-mixing layers still almost universally rely on standard softmax self-attention. This poses two major hurdles:
- Quadratic training complexity: Softmax attention scales as $\mathcal{O}(N^2)$ with sequence length $N$, leading to severe memory and throughput bottlenecks when training on long contexts.
- Inference memory footprint: The escalating size of the key-value (KV) cache limits concurrent serving and context scaling.
Although Linear Sequence Modeling (LSM) methods—such as linear attention, State Space Models (SSMs like Mamba), and linear RNNs (like RWKV)—solve this by achieving $\mathcal{O}(N)$ compute complexity and constant-size recurrent states, there was previously no unified, production-grade distributed system designed to scale LSM and MoE together.
Methods
The authors introduce Linear-MoE, built non-intrusively on top of Megatron-Core:
-
Unified Recurrent Abstraction: The modeling subsystem maps multiple linear architectures (Basic Linear Attention, RetNet, GLA, DeltaNet, Mamba/Mamba2, HGRN2, RWKV6/7) under a single recurrence update formula: $$\tilde{M}_s = f(K_s^\top, V_s), \quad M_s = \Theta_s \diamond M_{s-1} + \tilde{M}_s$$ where $M_s \in \mathbb{R}^{d \times d}$ is the memory state and $\Theta_s$ is a decay coefficient.
-
Pure and Hybrid Architectures: Models can be built entirely with Linear-MoE layers or as hybrid configurations (e.g., interleaving three LSM layers with one standard softmax attention layer, denoted as
LLLN). - Specialized Parallelism:
- Sequence Parallelism (SP): Implements LASP-2 for LSM layers by using a single collective
AllGatheroperation on the compact memory state matrix $M_s$, making communication overhead independent of sequence length. For standard attention layers in hybrid models, it uses an all-gather context parallelism (CP) strategy tailored for grouped query attention (GQA). - MoE Acceleration: Integrates MegaBlocks (block-sparse GPU kernels) and Grouped GEMM to mitigate expert load imbalance and accelerate sparse routing operations.
- Native support for Tensor (TP), Pipeline (PP), Expert (EP), and Data Parallelism (DP), as well as FP8 training on Hopper GPUs.
Datasets
- Pretraining: Pretrained from scratch on subsets of the SlimPajama dataset (using the Qwen2 tokenizer), testing at 15-billion token (A0.3B-2B models) and 100-billion token (A1B-7B models) scales.
- Evaluation: Evaluated zero-shot using OpenCompass across several commonsense and reasoning benchmarks: PIQA, HellaSwag, WinoGrande, ARC-easy, ARC-challenge, and 5-shot MMLU.
Key Insights and Ideas
- Memory Decoupling from Sequence Length: Unlike standard attention—where GPU memory explodes and throughput plummets as sequence lengths increase from 2K to 16K tokens—Linear-MoE models maintain near-constant GPU memory allocation and flat throughput for a fixed token budget per batch.
- Hybrid Architectures Stabilize Training: Pure LSM-MoE models are competitive, but periodically injecting a standard attention layer (such as the 3:1
LLLNhybrid pattern) yields smoother loss convergence curves and higher downstream task accuracy. - Complementary Efficiency: Grouped GEMM and MegaBlocks are critical; combining them with LSM modules slashes per-iteration latency on an 8-GPU node from 1565.6 ms down to 348.8 ms.
Key Results
- Throughput & Memory Stability: At a constant batch token budget of 16K (scaling from $2\text{K} \times 8$ to $16\text{K} \times 1$):
- Standard baseline attention throughput dropped from 102.1K to 49.4K tokens/s, while memory grew from 40.7 GB to 47.1 GB.
- Linear-MoE models remained steady: RWKV6 achieved roughly 134K–137K tokens/s throughout, and DeltaNet maintained ~110K–120K tokens/s, all while memory stayed flat at ~43–47 GB.
- Downstream Accuracy:
- On the A0.3B-2B scale (15B tokens), the standard attention baseline achieved an average benchmark score of 37.99 (excluding MMLU). Pure Mamba2-MoE reached 45.76, and hybrid GLA-MoE reached 46.52.
- On the larger A1B-7B scale (100B tokens), hybrid and pure Linear-MoE models matched or beat baseline capabilities across benchmarks (e.g., Mamba2 achieved 48.11 average non-MMLU accuracy vs. BLA's 45.91).
Limitations and Future Work
- Scale of Evaluation: Pretraining was evaluated up to 100B tokens on 7B-parameter sparse models (1B active); evaluation on frontier-scale models (tens or hundreds of billions of parameters) trained on trillions of tokens remains to be verified.
- Optimal Hybrid Scheduling: The 3:1 interleaving pattern was empirically chosen; formal exploration into the optimal ratio, placement, and interaction of standard vs. linear layers is left for future work.
- Need for Hardware-Specific Kernels: While Triton kernels were used, fully extracting hardware efficiency across different non-NVIDIA accelerators remains an ongoing engineering challenge.
Summary updated