Key Techniques in Sparse Multimodal Large Models: Attention, Expert Routing, and Long-Context Training

    This article breaks down the core engineering challenges of sparse multimodal large models with million-token context windows and maps them to three layers: attention, expert routing, and inter-layer connections. It explains lower-bounded decay parameterization for numerically stable linear attention, gated multi-head latent attention, block-level attention residuals, and quantile balancing for auxiliary-loss-free expert load balancing. It also covers progressive context extension from 8K to 1M tokens, agentic post-training with reinforcement learning, and a reusable checklist for deployment.

    1. Background: The Triple Pressure of Sparsity, Multimodality, and Ultra-Long Context

    Once model parameters reach the trillion scale, dense architectures become impractical in both compute and memory, which makes sparse Mixture-of-Experts (MoE) the mainstream choice. However, sparsification shifts the numerical problems that used to sit inside matrix multiplications into routing balance, expert communication, and training stability. At the same time, multimodal inputs interleave visual tokens with text tokens in a single sequence, and long context pushes sequence length into the millions. When all three pressures combine, the real bottleneck is usually not whether the model is large enough, but whether the operators can saturate the hardware, whether experts collapse, and whether deep representations degrade.

    Designs for this class of system can be abstracted into three layers: the attention layer (long-context efficiency and numerical stability), the expert layer (load balancing under extreme sparsity), and the inter-layer connections (deep representations, memory, and communication).

    2. Attention Layer: Making Linear Attention Actually Saturate Tensor Cores

    2.1 Pinpointing the Pain

    Linear attention and incremental recurrent structures reduce complexity from quadratic to linear in theory, but their engineering implementations have long faced two obstacles:

    1. Numerical range issues: Chunked computation requires the reciprocal of a cumulative decay factor, which can overflow or underflow in half precision such as BF16.
    2. Branches that break parallelism: To work around the numerical issues, diagonal blocks often take a special per-position-pair path that cannot be unified with off-diagonal blocks into a dense matrix multiplication, lowering tensor core utilization.

    2.2 Lower-Bounded Decay Parameterization

    A reusable approach is to change the log-decay from an unbounded negative value into a scaled Sigmoid with a fixed lower bound, as sketched below:

    1. # gmin is a fixed lower bound (e.g., -5) that keeps the reciprocal scaling
    2. # factor inside a tile within a safe range
    3. g = gmin * torch.sigmoid(alpha * h) # log-decay, always lower-bounded
    4. decay = torch.exp(g) # 0 < decay < 1, numerically controlled

    The benefit is that the cumulative scaling inside any fixed-length chunk (for example, 16 tokens) is locked into a safe range, so diagonal and off-diagonal blocks can both call the same dense matrix multiplication. Removing the special branch improves throughput significantly. The structure also does not rely on explicit positional encoding, so it naturally supports long-context extrapolation.

    2.3 Gated Multi-Head Latent Attention

    Another main line applies low-rank latent compression to attention and adds gating: project keys and values into a low-dimensional latent space for caching, then apply per-head gating coefficients. This addresses two things at once — lower memory usage for the key-value cache, and suppression of information redundancy across heads. In practice, the ratio between latent dimension and head count matters: too low loses retrieval capability, while too high degrades into standard multi-head attention.

    2.4 Block-Level Attention Residuals

    A common degradation in deep networks is that shallow-layer information gets diluted as layers stack. Block-level residuals aggregate the attention outputs of several layers at block granularity and inject them into later layers, which is equivalent to adding an “information highway” along the depth dimension. Compared with layer-by-layer residuals, its memory and cross-device communication overhead is more controllable, making it suitable for pipeline parallelism.

    3. Expert Layer: Stability and Balance Under Extreme Sparsity

    3.1 Scale and Sparsity

    A typical configuration has trillions of total parameters, hundreds of billions of activated parameters, and hundreds to thousands of routed experts. Higher sparsity makes per-token compute cheaper, but raises the risk of routing collapse, where a few experts are selected repeatedly.

    3.2 Quantile Balancing Without an Auxiliary Loss

    The traditional approach adds an auxiliary loss to constrain the routing distribution, at the cost of interfering with the main task gradient. Quantile Balancing takes a different route: bucket the routing scores by quantile, then dynamically correct the quantile thresholds so that the selection probability across experts converges toward uniform. Its advantages are no extra loss term and almost zero additional forward-pass overhead, and it converges to a balanced state quickly even with extremely large expert counts. Sketch of the logic:

    1. # Pseudocode: correct routing bias by quantile, no auxiliary loss needed
    2. scores = router(x) # [tokens, num_experts]
    3. bias = quantile_bias(scores, q=0.5) # quantile statistics
    4. topk_idx = topk(scores + bias, k=2) # select experts after correction

    3.3 Activation Functions and Expert Sharing

    When gated linear unit activations replace the nonlinearity, the scaling coefficients must be adjusted accordingly to keep variance stable. Pairing shared experts that carry general knowledge with routed experts that carry specialized knowledge reduces wasted parameters.

    4. Training Pipeline: Multi-Stage Context Extension and Agentic Post-Training

    Context length should not be maxed out in one step. The common industry practice is progressive: finish the main pre-training at a short context (such as 8K), then advance through 64K, 256K, and 1M in sequence. Each stage adjusts position-related configuration and parallel sharding strategy to avoid the memory peaks and optimization instability caused by long sequences all at once.

    The post-training stage introduces reinforcement learning for agents. Tasks span multiple rounds of tool calls and long-range dependencies, so reward design must cover both outcome correctness and process constraints (such as step count, formatting, and verifiability), and long trajectories should use segmented advantage estimation to control variance.

    5. Reusable Checklist and Deployment Advice

    1. Change the operator first: Lower-bounded decay parameterization is a small change with direct payoff, making it a good first step for a long-context solution.
    2. Balance before scaling: Quantile balancing significantly lowers collapse probability when the expert count grows.
    3. Put residuals at block level: It balances representation quality and parallel efficiency.
    4. Decouple compute from storage: Send checkpoints, training logs, and metrics to general-purpose capabilities such as object storage, logging services, and monitoring and alerting, and use a container platform for elastic scaling.
    5. Evaluate in layers: Assess short and long context, text-only and interleaved text-image inputs, and single-turn versus multi-turn agent tasks separately, so a single average does not hide weak spots.

    When deploying in a cloud environment such as Baidu AI Cloud, the capabilities above can map to combinations of general product categories rather than any proprietary interface, which makes cross-platform migration and reproduction easier.