Linear Attention Numerical Bounds and Quantile Balancing for Large-Scale MoE
Long-sequence modeling and sparse scaling place simultaneous pressure on training and inference systems. This article examines where linear attention recurrences and large mixture-of-experts (MoE) routing meet practical bottlenecks—low-precision decay, chunked parallelism, routing skew, and deep residual bandwidth—and presents three composable engineering patterns: bounded decay parameterization for numerically safe chunked attention, quantile-based routing calibration that avoids auxiliary balancing losses, and chunked attention residuals that reduce depth-wise memory and communication costs. It also outlines an implementation order and validation metrics for error, utilization, and communication.
Long-sequence modeling and sparse scaling are squeezing training and inference systems at the same time. Linear attention trades a recurrent state for approximately linear sequence complexity, while mixture-of-experts (MoE) trades conditional computation for parameter scale. When the two are combined, what blocks deployment is often not whether the formula looks more advanced, but low-precision numerics, parallel chunking, routing skew, and deep residual bandwidth. The following discussion covers mechanisms, constraints, and engineering trade-offs for three transferable practices, without tying the discussion to any specific model brand.
Where the Problems Come From
Standard self-attention grows computation and memory roughly quadratically with sequence length. During long-context training, activations, communication, and recomputation costs quickly dominate iteration time. Linear attention compresses history into a state and updates it recurrently over time, bringing complexity closer to a linear function of sequence length. That makes it a common path for long contexts. The cost is that decay, gating, and incremental updates must reproduce causal order exactly inside chunks. Chunks can run in parallel with each other, but if a special branch inside a chunk is only correct near the diagonal, dense matrix multiplication on Tensor Cores is underutilized, and the kernel is slowed down by scalar or position-wise paths.
Meanwhile, MoE replaces the feed-forward sublayer with multiple expert groups and uses routing to select a small number of experts per token. As the number of experts grows, load imbalance makes a few experts hot while most sit idle, worsening gradient variance and communication waits. The traditional approach often adds an auxiliary loss to pull load toward uniformity, but the auxiliary term requires tuning its weight and competes with the language-modeling objective for gradients. Deep stacking introduces another bottleneck: if attention output only goes through layer-by-layer residual addition, deep representations can saturate, and activations and cross-device communication expand linearly with depth.
Bounded Decay Parameterization
In linear attention or incremental state updates, a decay factor accumulated over time usually describes how much earlier tokens should still be retained. In chunked implementations, a chunk must handle both diagonal blocks (causal within the chunk) and non-diagonal blocks (history already determined across chunks). Decay for non-diagonal blocks can often be multiplied into the matrix in advance and sent directly to dense matrix multiplication. Diagonal blocks, however, must ensure that position i can only see position j ≤ i. If the logarithmic form of decay has no lower bound—for example, using negative softplus without constraint and pushing it toward a very large negative number—the accumulated decay underflows to zero in half precision, while its reciprocal overflows. At that point, the diagonal block can no longer be safely written as a uniform scaled matrix multiplication and must fall back to a special position-pair path.
A bounded parameterization changes the log decay from an unbounded negative value into a bounded scaling factor: first obtain a free variable through a linear projection, then pass it through a Sigmoid into (0,1), and multiply by a fixed negative constant as the lower bound. In this way, the log decay at any position falls within a known closed interval. For fixed-length chunks—commonly around a dozen tokens per chunk in engineering practice—the dynamic range of the reciprocal scaling factor within a chunk can be proven in advance to fall within a half-precision-representable range without severe underflow. Diagonal and non-diagonal blocks therefore share the same dense matrix multiplication dataflow. Causality only needs to be expressed during the write or mask stage, without maintaining a separate kernel for the diagonal.
The engineering meaning of this change is larger than the formula itself. With fewer kernel branches, compilation and tuning face homogeneous block matrix multiplications, making occupancy, pipelines, and memory coalescing more stable. Once the numerical range is locked, there is also no need to frequently promote to higher precision inside a chunk to compute reciprocals. This does not automatically mean that “any length works without positional information.” When no explicit positional encoding is used, length extrapolation depends on decay and state updates carrying order. A lower bound only makes this recurrence computable under low precision and chunked parallelism. Whether extrapolation is robust still depends on the training distribution, normalization, and state dimension; numerical computability must not be treated as a generalization guarantee.
For deployment, first fix the chunk length, scan the maximum and minimum decay reciprocals offline at higher precision, and then choose the lower-bound constant so that scaling under the target chunk length falls within a safe interval. Before launch, compare numerical error between the “unified matrix multiplication” and the “special diagonal branch” on the same shape, rather than looking only at throughput. A bound that is too loose reintroduces overflow; one that is too tight weakens long-range forgetting. Both should be evaluated together with effective memory length.
Quantile Balancing Without Auxiliary Loss
The ideal state for MoE is that routing still expresses “which type of expert this token should seek,” while global load does not remain concentrated on a few experts over time. Auxiliary loss can suppress utilization concentration, but it has three side effects: it is weight-sensitive, making the Pareto frontier between task loss and balancing loss unstable; auxiliary gradients rewrite routing logits and harm specialization; and when the number of experts is very large, globally counting frequencies across all experts itself carries synchronization cost.
Quantile balancing uses a different constraint. Instead of directly penalizing “frequency deviation from the mean,” it observes the distribution of routing scores or selection counts over a time window or micro-batch, uses quantiles to describe the gap between hot and cold experts, and then makes small, bounded adjustments to routing bias or sampling temperature. The core idea is to move balancing out of the loss function and turn it into dynamic calibration on routing statistics: the selection threshold for hot experts is raised slightly and that for cold experts is lowered slightly, but the calibration magnitude is controlled by the quantile gap so that routing is not flattened in one step.
Compared with a fixed auxiliary weight, this strategy is better suited to training with many experts and sharply varying token distributions within a batch. Its correctness depends on the statistics window: too short a window makes quantiles noisy and routing jittery; too long a window makes balancing lag, after hotspots have already caused in-step stragglers. In practice, statistics can be computed locally within a data-parallel group and then aggregated across groups at lower frequency, avoiding a full-network synchronization of expert histograms every step. At the same time, the main routing gradient should still come only from task loss. The calibration term should be kept as a bias or sampling-side adjustment with no gradient or stop-gradient, so that the method is truly auxiliary-loss-free rather than adding a balancing term back under another name.
When evaluating, do not look only at the variance of expert utilization. Also check whether task loss rises due to calibration, whether expert specialization remains (whether similar tokens are still concentrated), and the wait time of the slowest expert in a step. Perfectly flattened utilization often means routing has lost discriminative power; that is not the goal.
Chunked Attention Residuals
As networks get deeper, if every attention layer maps independently into the same residual stream, two kinds of waste appear in deep layers: representation updates become smaller and more gradients travel through shortcuts; each layer still must retain full activations for attention output, and memory and sequence-parallel communication accumulate with depth. Chunked attention residuals treat several consecutive layers as a block, share or merge residual writes within the block, and perform a fuller residual merge between blocks. Intuitively, layers inside a block refine the same round of context read/write, and only block boundaries commit results back to the trunk.
This has three effects. First, it reduces the number of writes to the residual stream, so activation checkpoints can be saved per block rather than per layer, making recomputation coarser and scheduling simpler. Second, with sequence parallelism or tensor parallelism, communication can be merged within a block, combining multiple small all-gather or reduce-scatter operations into fewer, larger messages and improving bandwidth utilization. Third, deep layers no longer force a full residual addition at every layer, which helps mitigate premature representation saturation and lets layers inside a block handle incremental refinement.
The risks are equally clear. If blocks are too large, the lack of residual anchors inside a block can make early training unstable; if blocks are too small, memory and communication savings are limited. Block-boundary normalization and scaling initialization must match the number of layers inside the block to avoid amplitude jumps when committing to the trunk. This approach is orthogonal to linear attention and MoE: linear attention addresses the compute form along the sequence dimension, experts address conditional computation along the width dimension, and chunked residuals address writes and communication along the depth dimension. All three can coexist in one stack, but they should be ablated separately; otherwise, it is impossible to tell where the gain comes from.
How to Deploy Them Together
It is better to change the system in dependency order rather than replacing every operator at once.
- First fix the numerical format and chunk length, complete bounded decay, make diagonal and non-diagonal paths use the same matrix multiplication, and establish an error threshold against a high-precision reference implementation.
- Introduce quantile statistics and bounded bias on the routing side, and confirm that after removing the auxiliary loss, the utilization gap remains controllable and task loss does not degrade.
- Then merge attention residuals by block, and measure peak activation memory, recomputation time, and sequence-parallel communication volume.
- Only then discuss whether to weaken or remove explicit positional encoding. A unified numerical path is only a necessary condition for extrapolation; validation sets beyond the training length are still needed to check perplexity and long-range retrieval metrics.
An illustrative decay constraint can be written as follows. It only shows the shape and is not an interface for any particular framework:
# a: [batch, heads, seq, 1] free projection# g_min: fixed negative constantlog_decay = g_min * sigmoid(a) # falls in (g_min, 0)scale = exp(cumsum(log_decay)) # cumulative within block, range can be bounded in advance
Quantile calibration stays outside routing:
scores = router(x) # task pathhot, cold = quantile_gap(scores) # stop-gradient statisticsbias = clip(update(hot, cold), ±eps)route = scores + bias # small-step balancing, no auxiliary loss
These snippets emphasize the boundaries: the lower bound is a constant constraint, and balancing is a bounded bias. Neither should be replaced by unconstrained gating or an additional loss term before validation.
Summary
For linear attention to run at full utilization on Tensor Cores, the key is to make decay reciprocals numerically safe within chunks, thereby eliminating the special diagonal path. For very large MoE, the key to stable iteration time is dynamic, weakly interventionist load calibration using distribution quantiles rather than defaulting to auxiliary losses. For deep stacking, the key to saving memory and communication is committing attention residuals by block. The three correspond to numerical range, routing statistics, and depth-wise writes. Their change surfaces are relatively local, but each must be accepted against error, utilization, and communication metrics. Designing them as composable system constraints is closer to reusable engineering results than chasing a single architecture name.
