Linear Attention and MoE: Three Engineering Practices

    This article examines three engineering practices for linear attention and large-scale sparse MoE: bounded decay parameterization for unified causal chunk GEMMs, quantile-based routing balance that reduces reliance on auxiliary losses, and chunked attention residuals that ease deep-representation bottlenecks and communication pressure. It also discusses implementation trade-offs, layered evaluation, and how to combine the techniques based on actual bottlenecks rather than stacking terms.

    Why These Three Problems Belong Together

    Long-sequence modeling and very large-scale sparse activation have moved from “can it be trained at all” to “can it be trained stably and efficiently on mainstream accelerators.” Recursive or chunked-recurrence structures such as linear attention reduce theoretical complexity from quadratic to near-linear, but once they meet limited-precision matrix multiplication and causal chunking, they expose problems such as diagonal blocks being unable to use dense matrix multiplication and cumulative decay factors underflowing. Mixture-of-Experts increases capacity, but turns routing balance into a core constraint on training stability. Deeper stacking then makes the information path between residual and attention blocks a bottleneck for deep representations and amplifies memory usage and cross-device communication.

    These three problems are discussed together not because they must belong to one model, but because they correspond to the same set of engineering trade-offs: numerical ranges should be predictable, branches should be as unified as possible, load should depend as little as possible on extra losses, and structural changes should be as local as possible. The sections below cover mechanism, benefits, and implementation notes separately.

    1. Bounded Decay Parameterization: Let All Causal Chunks Use Dense GEMMs

    Linear attention and similar “state recurrence + decay” structures usually compute cumulative decay within a chunk. If the log decay comes from an unbounded negative softplus-like mapping, the reciprocal of decay factors within a chunk may span an extremely large dynamic range. Under half precision, diagonal blocks often can only fall back to a scalar position-pair path and cannot call dense matrix multiplication on tensor cores the way non-diagonal blocks do. The result is two implementations inside the same operator: throughput is dragged down by the diagonal branch, and unified kernel fusion becomes harder.

    The core of bounded decay parameterization is to change log decay from “arbitrarily diverging in the negative direction” to a bounded mapping with a lower bound. A common form uses a scaled sigmoid to lock each step’s decay near a fixed lower bound, for example by using a small negative constant as the lower bound and multiplying it by the sigmoid output. In this way, within any fixed-length chunk, such as sixteen tokens, the reciprocal scaling factors stay in a safe interval, and diagonal and non-diagonal blocks can use the same causal chunked matrix multiplication.

    The engineering reuse value is high: the operator side no longer needs to maintain a separate position-pair path for diagonal blocks, and templated matrix multiplication such as CUTLASS can cover all causal chunks. On the training side, numerics are more stable and silent errors caused by underflow are reduced. An additional benefit is that when positional information does not rely on explicit positional encoding, long-context extrapolation is no longer tied to a special implementation for diagonal blocks, which helps keep the same kernel set when context is extended to the million-token scale.

    Three points matter in implementation. First, a lower bound that is too small approaches unbounded decay, while a lower bound that is too large weakens model expressiveness; both the validation set and long-sequence extrapolation should be checked. Second, chunk length, precision (half precision and mixed precision), and kernel tile must be designed together; otherwise “numerical safety” remains only at the formula level. Third, this parameterization should not be mistaken for a new attention theory: it is first a parameterization constraint under implementation constraints.

    Illustration (only to show the mapping shape, not an interface from any product):

    1. g_t = g_min * sigmoid(e_t) # g_min is a fixed negative lower bound; e_t is a learnable pre-activation
    2. # The reciprocal of cumulative decay within a chunk is limited to a finite range, and diagonal/non-diagonal blocks share GEMM

    2. Quantile Balancing: Reduce Auxiliary-Loss Dependence for Large-Scale Expert Load

    What MoE must solve is “large capacity but uneven expert hotness.” The traditional approach often adds an auxiliary loss that forces each expert to be selected a similar number of times. Auxiliary loss has two side effects: it competes with the main-task gradient for weight, making hyperparameters sensitive; and when the number of experts is very large and routing is very sparse, statistical noise is high and the balancing signal lags.

    The idea of quantile balancing is to dynamically adjust thresholds or biases according to quantiles on routing scores or the gating distribution, so that each expert’s load falls within a target quantile interval instead of being pulled by an extra loss. It can be viewed as “online load shaping”: based on the expert occupancy distribution in the current batch or a sliding window, raise the threshold for overheated experts and lower it for underused experts, making activation more even.

    Compared with auxiliary loss, the advantage is a more direct objective (load itself), less interference with the main loss, and faster balancing response when the number of experts reaches the thousands. In implementation, it usually only requires lightweight statistics and bias updates before or after routing, without changing the main computation graph.

    Its boundaries need to be understood clearly. A quantile window that is too short causes jitter, while one that is too long cannot keep up with data-distribution drift. It is strongly coupled with capacity factor, top-k selection, and expert parallel partitioning, and must be tested together with communication scheduling. In addition, balance is not the same as quality: excessive uniformity may hurt specialization. It is better to monitor load variance, empty-expert ratio, and downstream task metrics together rather than looking only at the balance curve.

    3. Chunked Attention Residuals: Ease Deep Representation Bottlenecks and Cut Communication

    During deep stacking, standard residuals add each attention layer’s output back to the main path, but deep layers may show too small a representation update and repeated cross-layer information, while the full attention state at every layer increases activation memory and cross-device synchronization volume. The intuitive approach of chunked attention residuals is to split the sequence or intra-layer computation into chunks and aggregate residuals at the chunk level or pass them across chunks, rather than applying full residual at the same granularity for every position and every layer.

    This has two implications. For representation, chunk-level residuals provide a coarser “shortcut” for deep layers, reducing gradient attenuation and representation collapse along depth. For systems, chunk-local computation can reduce the volume of activations that need cross-device synchronization, making it friendlier to both pipeline parallelism and sequence parallelism.

    When designing, clarify three things: whether chunks are divided by sequence, by head, or by layer; whether the residual is added to the chunk output or after reprojection; and whether it aligns with linear attention chunking. Good alignment allows the decay parameterization above and the residuals here to share the same chunk boundaries, yielding cleaner kernels and communication patterns. Misalignment may introduce extra transposes and synchronization, eroding the gains.

    How to Combine the Practices Without Stacking Buzzwords

    The three techniques can be used independently or combined according to the bottleneck. If the current pain point is that linear attention’s diagonal blocks are too slow on accelerators, prioritize bounded decay and a unified causal chunk kernel. If the pain point is idle experts and difficult auxiliary-loss tuning, prioritize routing-side quantile shaping and turn off or reduce the auxiliary term for a controlled comparison. If the pain point is that metrics stop improving as depth increases while memory and communication explode first, then consider chunk-level residuals and chunk alignment.

    Evaluation should be layered: at the kernel level, check whether diagonal and non-diagonal blocks use the same GEMM and what share of effective compute is achieved; at the training level, check loss stability, expert load histograms, and gradient norms; at the system level, check activation memory, cross-device communication volume, and long-sequence throughput. Avoid using a single throughput number to prove an “architectural victory.”

    In cloud training scenarios, object storage handles checkpoints and long-sequence data shards, container platforms handle scheduling of heterogeneous accelerators, and logs, monitoring, and alerting cover indicators such as load imbalance and numerical overflow. These are general capabilities independent of any specific model brand. Making operator numerical ranges, routing statistics, and chunk boundaries observable metrics is more reusable than chasing a particular technical claim.

    Conclusion

    Bounded decay parameterization addresses the implementation split of linear attention under finite precision and tensor-core constraints; quantile balancing addresses the dependence of very large-scale MoE on auxiliary losses; and chunked attention residuals address deep pathways plus memory and communication. All three emphasize “constrain the implementation, unify branches, add fewer losses, and align chunks.” Choose based on your own compute and model shape, validate with controlled experiments, and these ideas can be landed in general training and inference stacks.