Sparse Multimodal LLM Architecture: Attention, MoE Routing, and Long-Context Design

    This article breaks down the engineering architecture of a sparse multimodal large language model, focusing on three core challenges: numerical stability in linear attention, load balancing in ultra-sparse Mixture-of-Experts (MoE) routing, and efficient long-context training. It explains how bounding the log-decay parameter unifies attention code paths, how block-level attention residuals reduce memory and communication overhead, how quantile balancing replaces auxiliary loss, and how staged context extension from 8K to 1M tokens combined with agentic reinforcement learning shapes post-training. Readers will find reusable design patterns and practical deployment recommendations for training and serving trillion-parameter sparse models.

    1. Why Parameter Count Is No Longer the Only Story

    Over the past two years, the main axis of large model competition has shifted from “who has more parameters” to “how much effective capability is produced per unit of compute.” Once total parameters reach the trillion scale, the inference cost of a dense architecture rises almost linearly, which becomes hard to sustain in engineering practice. Sparse Mixture-of-Experts (MoE) has therefore become the mainstream choice: total capacity can be made very large, but each token activates only a small fraction of the parameters, decoupling “capacity” from “compute.”

    Sparsity, however, is not a free lunch. It introduces three new classes of problems. First, load imbalance under massive expert counts, where a few experts are over-routed while most remain starved for long periods. Second, representation degradation from deep stacking, along with ballooning memory and communication overhead. Third, when the context grows from thousands of tokens toward the million-token range, the memory and bandwidth cost of attention becomes a hard bottleneck. A typical sparse multimodal model within a 2026 cycle (roughly 2.8 trillion total parameters, about 104 billion activated, native vision multimodality, and support for million-token context) is a systematic answer to these three problems. The sections below abstract its key designs into transferable engineering patterns.

    2. Attention Layers: Making Linear Attention Fully Utilize Matrix Compute Units

    2.1 The Problem: Numerical Range Determines Whether an Operator Can Be Quantization-Accelerated

    The core idea of linear attention / incremental linear attention (including various Delta-style variants) is to replace softmax attention with a recurrent state update, reducing complexity from quadratic in sequence length to linear. This sounds ideal in theory, but in engineering it often stalls on one detail: during chunked computation, the accumulated decay factor must be inverted for scaling, and if the decay parameter uses an unbounded form (for example, negative softplus), it easily overflows or underflows under the limited precision of BF16/FP16.

    The consequence is that implementers must write a separate slow branch for “diagonal blocks” (tiles near the diagonal) that expands over position pairs, while only off-diagonal blocks can go through dense matrix multiplication. Two code paths then coexist within the same layer, hardware utilization drops, and numerical behavior becomes harder to reproduce.

    2.2 The Solution: Add a Lower Bound to the Decay and Merge Two Paths into One

    A simple and effective approach is to change the log-decay from an unbounded function to a bounded one with a lower bound, for example using scaled Sigmoid parameterization with a fixed lower bound (commonly around -5 in engineering):

    1. # Illustration: log-decay parameterization with a lower bound
    2. g_min = -5.0
    3. g = g_min * torch.sigmoid(a * h + b) # g ∈ (g_min, 0)
    4. # The scaling factor used in chunked recurrence is constrained to a safe numerical range
    5. scale = torch.exp(g) # will not underflow to 0, nor overflow

    There are three benefits:

    • The inverse scaling within any fixed-length tile (such as 16 tokens) is locked in a safe range, requiring no special handling under BF16;
    • Diagonal and off-diagonal blocks both go through dense tensor-core GEMM, eliminating the branch and significantly improving throughput;
    • It is naturally compatible with NoPE (no positional encoding), so position terms and decay terms do not interfere with each other during long-context extrapolation.

    2.3 Combining with Gated Multi-Head Latent Attention

    A more common engineering combination is “linear attention + Gated Multi-Head Latent Attention (Gated MLA)”: the former handles cheap global information compression for the vast majority of tokens, while the latter preserves high-precision retrieval in a small number of layers. Latent (low-rank) projection compresses the KV cache into a smaller hidden space, and gating dynamically adjusts write strength according to token importance. Combined, the KV memory footprint at million-token context can drop by an order of magnitude, while accuracy loss on retrieval tasks (long-document localization, cross-file references in a codebase) stays controllable.

    3. Cross-Layer Information Sharing: Block-Level Attention Residuals

    A common problem in deep Transformers is the “deep representation bottleneck”: later layers struggle to use fine-grained information from shallow layers, and naively summing all layer outputs linearly increases memory and activation communication volume.

    The idea of Block AttnRes is grouped sharing: divide layers into several blocks, keep a standard residual stream within each block, and pass only one aggregated attention residual between blocks.

    1. # Illustration: block-level residual aggregation
    2. for block in blocks: # every 4~8 layers form a block
    3. h = run_layers(block, h) # standard residual within the block
    4. residual_pool.append(pool(h)) # keep only one aggregated result
    5. h = fuse(h, residual_pool) # fuse uniformly at the end

    The practical value is that memory and cross-device communication grow with the number of blocks rather than the number of layers; meanwhile, shallow information can reach deep layers at low cost, alleviating degradation. For training clusters, this means stacking more layers under the same bandwidth, or leaving more memory for ultra-long context under the same layer count.

    4. The MoE Side: Training 896 Routed Experts Stably

    4.1 The Stability Trio

    The stability of ultra-sparse MoE relies on three things working together:

    1. Routed expert scale and capacity: the number of routed experts can reach several hundred (such as 896), combined with shared experts that carry general knowledge to reduce routing noise;
    2. Smooth activation: use a smooth gated activation such as SiTU-GLU to avoid drastic gradient jumps at gating boundaries;
    3. Quantile Balancing (QB): dynamically calibrate based on “the quantile of the number of tokens each expert receives,” rather than relying on an auxiliary loss.

    4.2 Why “Auxiliary-Loss-Free” Matters

    The traditional approach uses a load-balancing auxiliary loss to constrain the routing distribution, but it has two side effects: first, it interferes with the main-task gradient and requires repeated weight tuning; second, in large-scale training, a slightly careless coefficient leads to “routing collapse.” QB changes the balancing objective from a “loss term” to a “direct constraint at the data and optimization level,” adjusting each expert’s receiving threshold by quantile so the distribution quickly converges to the target range, eliminating tuning while avoiding contamination of the main task. In practice, such mechanisms are usually combined with expert parallelism and a capacity factor, with overflow tokens being controllably dropped or falling back to shared experts.

    5. Context and Post-Training: The Path from 8K to 1M

    Long context is not as simple as “enlarging the window,” but a curriculum-style training that advances in stages: first stabilize and converge at 8K, then extend sequentially to 64K, 256K, and 1M. Each stage must synchronize three things: the position extrapolation strategy (NoPE or interpolation), the attention implementation (chunk size, whether to recompute), and the data mix (the proportion of long documents, code repositories, and multi-turn tool-call trajectories).

    The key to the post-training stage is million-token-level agentic reinforcement learning (Agentic RL): tasks are no longer single-turn Q&A but a long-horizon loop of “given a goal — multi-step planning — tool calls — observing results — correcting.” To make training reproducible, the following are usually needed:

    • Verifiable rewards: replace subjective scoring with objective signals such as unit tests, compilation results, and format checks;
    • Trajectory-level credit assignment: attribute final success or failure to specific steps, mitigating long-horizon sparse rewards;
    • Context management strategies: perform segmented summarization and retrieval of key fragments for ultra-long trajectories, avoiding wasting the window on low-information-density content.

    6. Reusable Checklist and Deployment Recommendations

    • Prioritize revamping the linear attention operator: add a lower bound to the decay and unify the diagonal/off-diagonal block paths; this is the highest return-on-investment step;
    • Replace full-layer residuals with block-level residuals: memory and communication grow with the number of blocks, allowing deeper stacking;
    • Prefer an auxiliary-loss-free route for load balancing: reduce main-task interference and tuning cost;
    • Extend context in stages, fixing an evaluation set at each stage for regression to prevent “long-window, short-task capability degradation”;
    • Build agentic capability on verifiable environments and trajectory-level rewards, rather than stacking human preference annotations.

    To reproduce the above on your own platform, you can rely on a combination of general capabilities: a container platform to host distributed training and elastic scaling, object storage to hold corpora and checkpoints, a message queue to decouple the data pipeline from the sampling service, and logging services with monitoring and alerting for observability of routing distribution, expert load, memory, and throughput. Baidu AI Cloud offers corresponding capabilities in these general categories and can serve as one option for the engineering foundation.

    7. Conclusion

    The competition among trillion-scale sparse multimodal models is essentially an engineering balancing act among numerical stability, load balancing, and long-context efficiency. Making three small changes solid — decay parameterization, residual aggregation, and the balancing mechanism — often determines whether training converges and whether inference is affordable more than blindly expanding parameters does.