Engineering Sparse Multimodal MoE Models at Scale: Attention, Routing, and Training
\nThis article breaks down the engineering challenges of building ultra-large sparse multimodal mixture-of-experts (MoE) models, using a representative configuration with roughly 2.8 trillion total parameters, about 104 billion activated parameters per token, native vision input, and million-token context. It explains how to keep linear attention on a dense matrix-multiplication path by bounding the log decay, how block-level attention residuals reuse information across layers, and how auxiliary-loss-free quantile routing stabilizes expert selection at large expert counts. It also covers progressive context-length curricula, agentic reinforcement learning with process-level rewards, and a practical checklist for in-house teams.
\n## 1. Why Ultra-Large Sparse Multimodal Models Became a Focal Point\n\nOver the past two years, gains in large model capability have shifted away from simply stacking parameters toward lifting three curves at once: parameter count, context length, and modality coverage. A representative technical report in the industry describes a typical configuration: about 2.8 trillion total parameters, roughly 104 billion activated per token, with native support for visual input and million-token context. The significance of such a configuration lies not in the numbers themselves, but in the fact that it compresses three originally separate engineering problems into a single system.\n\nFirst, sparsification decouples parameter capacity from per-inference compute, so a model can hold enormous knowledge capacity at an acceptable inference cost. Second, ultra-long context pushes attention from local modeling toward global retrieval and long-range dependency. Third, multimodal and agentic training require the model to maintain goal consistency across tool-call chains of dozens or even hundreds of steps. Once these three are stacked, any single point of instability is amplified into either non-convergent training or unusable inference.\n\n## 2. Attention Layers: Making Linear Attention Actually Saturate Matrix Compute Units\n\nThe core tension in long context is complexity. Standard attention grows quadratically with sequence length, and engineering practice typically mitigates this through sparsification, chunking, or linearization. Linear attention and gated delta-update style approaches compress state into a fixed-size matrix, making complexity roughly linear in length, but they have long carried an underrated bottleneck on hardware.\n\nThe problem lies in the numerical range of chunked parallel computation. Chunked algorithms split the sequence into tiles, and diagonal blocks require the reciprocal of a cumulative decay factor; under finite precision such as BF16, if the decay parameter has no upper bound, that reciprocal easily overflows or underflows. Implementations are therefore forced to route diagonal blocks through a separate slow path that computes position by position, leaving the matrix multiplication units underutilized.\n\nOne validated approach is to add a lower bound to the decay parameter, changing the log decay from an unbounded negative soft-threshold function into a scaled sigmoid function with a lower bound — for example, letting the per-step log decay equal a fixed lower bound (commonly on the order of -5) multiplied by the sigmoid output:\n\npython\n# Illustrative: gated log decay with a lower bound\ng_min = -5.0\nlog_decay = g_min * sigmoid(learnable_proj(x)) # bounded below, reciprocal range stays controlled\nstate = log_decay.exp() * state + k.transpose(-1, -2) @ v\n\n\nThe payoff is structural: all causal tiles, diagonal and off-diagonal alike, can take the same dense matrix multiplication path. Removing the special branch substantially simplifies the operator implementation, improves throughput, and naturally fits a no-positional-encoding design, so extrapolation to million-level context does not depend on extra interpolation tricks.\n\nCross-layer information reuse also deserves attention. In conventional stacking, deeper layers can only read the current layer’s input, and representations tend to degrade along the depth dimension. Block-level attention residuals inject attention outputs from shallow layers, or from several layers back, into deeper layers at block granularity; this eases the depth bottleneck while using less memory and communication bandwidth than per-token residuals. In implementation, it only requires a small amount of caching and addition between layers — a low-effort, clearly beneficial optimization.\n\n## 3. Sparse Expert Layers: Stability and Load Balancing with 896 Routed Experts\n\nAs the number of experts grows, two typical failures appear: routing collapse (a few experts selected repeatedly) and training divergence (activation scales running out of control).\n\nAt the activation function level, replacing the gating branch of a gated linear unit with a smooth, non-monotonic sigmoid-family function improves expressiveness while keeping gradients stable; in practice this usually shows up as a smoother loss curve at equal compute.\n\nFor load balancing, the mainstream approach is an auxiliary loss, but its weight is hard to tune: too large harms the main task, too small breaks the balancing, and this is especially sensitive at the scale of hundreds of experts. An auxiliary-loss-free quantile balancing mechanism offers another path: set a dynamic threshold based on the quantile of routing scores along the expert dimension, turning \”pick the top k\” into \”pick everything above the quantile threshold.\” Load is naturally flattened, with no extra loss term and no hyperparameter search. Illustration:\n\npython\n# Illustrative: quantile dynamic routing (no auxiliary loss)\nscores = router(x) # [tokens, num_experts]\ntau = torch.quantile(scores, q, dim=-1, keepdim=True)\nmask = scores >= tau # per-token expert count adapts automatically\nweights = softmax(scores.masked_fill(~mask, -inf), dim=-1)\n\n\nPairing shared experts that carry general capability with routed experts that carry fine-grained knowledge can further reduce knowledge redundancy.\n\n## 4. Training and Post-Training: Curriculum-Based Context Extension and Agentic Reinforcement Learning\n\nContext capability is not switched on all at once. A relatively mature path in the industry is a progressive curriculum: first build a solid foundation in language and knowledge on short sequences (thousands of tokens), then advance in turn to tens of thousands, then hundreds of thousands, and finally to the million level; each step is paired with corresponding adjustments to the parallelism strategy and a learning rate re-warmup, avoiding gradient shocks in the early phase of long sequences.\n\nIn post-training, reinforcement learning for agents needs to extend the reward from \”answer is correct\” to \”process is compliant\”: whether tool-call arguments are valid, whether intermediate observations are correctly referenced, and whether the long-range goal drifts. Viable practices include hierarchical rewards (outcome reward plus step reward), replay of failed trajectories, and curriculum-style difficulty progression within the same task family.\n\n## 5. A Practical Checklist for In-House Teams\n\n- Quantify the bottleneck first: use operator-level profiling to confirm whether attention or expert routing limits throughput before deciding optimization priorities.\n- Prioritize numerical safety: for any gating that involves exponentials and reciprocals, add bounds before parallelizing.\n- Keep balancing simple: try the auxiliary-loss-free approach first to reduce the hyperparameter burden.\n- Stage the context: do not max out sequence length in a single training run.\n- Cover long-range in evaluation: beyond general benchmarks, add three scenarios — long-document retrieval, multi-step tool calls, and joint multimodal reasoning.\n\nTo carry the training and inference loads described above, general-purpose cloud capabilities are sufficient: a container platform handles elastic scheduling, object storage holds corpora and checkpoints, a message queue decouples the data pipeline, and logging plus monitoring with alerting covers anomaly detection. Overall, the value of this architecture lies in combining sparse capacity, linear attention, and stable routing into a reusable engineering paradigm, rather than in any single trick.
