Solving Linear Attention Underflow and MoE Load Imbalance in LLMs

    As long-context and ultra-large Mixture-of-Experts (MoE) models become standard configurations for large language models, addressing numerical underflow in linear attention and expert load imbalance is critical. This article examines three practical architecture modifications: lower-bound decay parameterization, quantile balancing routing, and block-level attention residual. It details the underlying problems, technical mechanisms, and verification methods for each modification, providing an implementation roadmap for improving computational efficiency, training stability, and representation depth.

    Why These Architecture Modifications Matter

    Long-context and ultra-large Mixture-of-Experts (MoE) models are increasingly becoming standard configurations for large language models. In this context, three specific architecture modifications have garnered significant attention: lower-bound decay parameterization, quantile balancing routing, and block-level attention residual. They address challenges in computational efficiency, training stability, and representation depth, respectively. While all three modifications have relatively low code invasiveness, each depends heavily on specific precision, scale, and hardware conditions. Therefore, empirical testing before deployment is essential. This article will break down each modification, categorized by “Problem, Mechanism, and Verification Method.”

    1. Lower-Bound Decay Parameterization: Enabling Dense Matrix Multiplication for Linear Attention Chunked Computation

    Problem

    Linear attention and its variants (such as incremental rule networks) split sequence computation into chunks, making the complexity grow approximately linearly with sequence length. Intra-chunk computation requires accumulating the reciprocal of decay factors. Under limited precision formats like BF16, this reciprocal can overflow or underflow. To circumvent these numerical issues, diagonal blocks are often implemented using explicit position-pair-wise computation, which prevents the direct invocation of Dense Matrix Multiplication (GEMM). Consequently, Tensor Core utilization drops significantly.

    Mechanism

    Traditional methods use Negative-Softplus to map the decay value to the negative real number domain, which theoretically can approach negative infinity. The lower-bound approach replaces this with a scaled Sigmoid and fixes a lower bound:

    g = g_min × σ(s × x)

    Where g is the log-domain decay value, g_min is the fixed lower bound (e.g., -5), σ is the Sigmoid function, s is the scaling coefficient, and x is the linear output of the gating network. Since the output of Sigmoid is between (0, 1), g is restricted to the range of (g_min, 0).

    This lower bound narrows the scaling range of the reciprocal. If the chunk length is L, the maximum intra-chunk scaling is approximately exp(-L × g_min). Taking L=16 and g_min=-5, this value is about exp(80), or 5.5×10^34. This number can be represented within the dynamic range of BF16 (upper limit around 3.4×10^38) but would overflow in FP16 (upper limit around 65504). Therefore, the lower bound and chunk length must be determined in conjunction with the target precision, rather than looking at a single parameter in isolation.

    Verification Method

    • Test the maximum intra-chunk scaling value with extreme inputs (all negative or all positive gate outputs) to confirm it does not exceed the target precision’s upper limit.
    • Compare the relative error of the output against an FP32 reference implementation.
    • Record the throughput and Tensor Core utilization for both diagonal and non-diagonal blocks separately to confirm the actual gains after switching to a unified GEMM path.

    2. Quantile Balancing: MoE Load Balancing Without Auxiliary Loss

    Problem

    MoE expands model capacity through sparse activation, but uneven expert loads cause two types of problems. First, popular experts become overloaded, slowing down the entire batch’s computation and causing imbalanced communication across devices. Second, common auxiliary load balancing losses conflict with the main task’s gradients. The more experts there are, the harder the hyperparameter tuning becomes, sometimes requiring a trade-off of model quality for load balance.

    Mechanism

    Quantile balancing does not modify the loss function; it only adjusts the bias during the routing phase. The main steps are as follows:

    1. Within a sliding window, count the load of each expert and calculate load quantiles (such as the median and high quantiles).
    2. Decrease the routing bias for experts with loads above the target value and increase it for those below the target. The adjustment magnitude is controlled by step size η.
    3. Update the bias every few training steps. The update frequency and window length need to be set together.
    4. The bias only participates in Top-K selection and does not enter the gating weighted sum and gradient paths. Therefore, the optimization objective of the main task remains unchanged.

    The capacity factor C determines the maximum number of tokens an expert can receive. Excess tokens are either dropped or routed to other paths. The token drop rate is a crucial indicator for judging the balancing effect. The bias is updated during training and typically frozen during inference. If it continues to update during inference, the output for the same input would vary across different batches.

    Comparison with Auxiliary Loss

    Dimension Auxiliary Loss Quantile Balancing
    Impact on main task gradient Conflict exists, requires trade-off No gradient interference
    Key hyperparameters Loss coefficient Step size η, update frequency, window length
    Convergence speed Depends on loss coefficient Depends on step size, requires testing
    Statistical overhead Low Requires cross-device load aggregation

    This table serves as a qualitative comparison; specific differences must be measured experimentally on the target model.

    Common Failure Modes

    • An excessively large step size causes bias oscillation, flipping expert loads back and forth between two states.
    • A window that is too short introduces significant statistical noise, leading to frequent misadjustments of the bias.
    • Over the long-term accumulation of bias, popular but effective experts may be continuously suppressed.
    • In distributed training, if each GPU card independently calculates statistics, the global load view may become distorted.

    Monitoring Metrics

    It is recommended to simultaneously record expert load variance, the ratio of maximum load to mean, the token drop rate, and the bias drift magnitude. These four metrics reflect the degree of balancing, tail drag, capacity pressure, and parameter stability, respectively.

    3. Block-Level Attention Residual: Mitigating Representation Degradation in Deep Transformers

    Problem

    As the number of layers increases, deep representations using standard residual connections tend to become similar. The increase in model depth yields limited improvement in effective representation. Furthermore, ultra-long contexts cause attention intermediate results to consume substantial memory, and multi-GPU parallelism increases the transmission volume of inter-layer activations.

    Mechanism

    Block-level attention residual expands the granularity of residual connections from a single layer to a block. Several layers form a block; each layer within the block, in addition to receiving the output of the previous layer, also accesses the input at the beginning of the block. This allows deep modules to directly reuse shallow features, reducing the degradation accumulated across intermediate layers.

    The block size B is the primary design parameter. A smaller B results in denser cross-layer connections and better representation retention, but implementation and communication become more complex. When B approaches the total number of layers, the structure resembles standard residuals.

    Reusing partial attention intermediate results within the block can reduce redundant computation and activation caching. However, this benefit depends on the specific implementation and cannot be assumed directly.

    Verification Method

    • Compare the perplexity and downstream task performance between standard residual and block-level residual under the condition of identical parameter counts and training token volumes.
    • Record peak memory usage to compare differences under the same batch size.
    • Count the number of communication bytes across cards per training step to confirm changes in activation transmission volume.

    4. Implementation Order and Checklist

    Since the three modifications have different dependencies, it is recommended to evaluate them in the following order:

    1. First, evaluate lower-bound decay parameterization. This modification is confined to the parameterization layer and can be verified through direct numerical testing.
    2. Next, evaluate quantile balancing. It relies on routing statistics and cross-device aggregation, requiring coordination with a monitoring system.
    3. Finally, evaluate block-level residual. This alters the network structure and requires a complete comparative training experiment.

    Before starting each step, confirm the target precision, hardware model, model scale, and available training budget. The network topology and communication bandwidth of general cloud platforms versus self-built clusters vary greatly; the same solution might yield different results. Every modification should be accompanied by comparative experiments and monitoring data before deciding whether to scale up its application.