Linear Attention and MoE Optimization: Lower-Bounded Decay, Quantile Balancing, and Block-Level Attention Residuals
Next-generation long-context and large-scale sparse models face three concurrent bottlenecks: numerical stability of linear attention under low-precision matrix computation, dynamic load balancing for mixture-of-experts (MoE) models under very large-scale expert parallelism, and the representation and memory-communication overhead of residual-stream organization in deep Transformers. This article abstracts these issues into general technical topics and examines three highly reusable techniques: lower-bounded decay parameterized linear attention, quantile-balancing dynamic load balancing, and block-level attention residuals. These techniques map to operator efficiency, routing efficiency, and depth efficiency, respectively. They can be deployed independently or combined into a system-level optimization approach for long-context and large-scale sparse models.
Linear Attention and MoE Optimization: Lower-Bounded Decay, Quantile Balancing, and Block-Level Attention Residuals
Next-generation long-context and large-scale sparse models are simultaneously facing three types of bottlenecks: the numerical stability of linear attention under low-precision matrix computation, dynamic load balancing for mixture-of-experts (MoE) models under very large-scale expert parallelism, and the representation and memory-communication overhead of residual-stream organization in deep Transformers. This article does not evaluate any specific product. Instead, it abstracts the original problems into general technical topics and focuses on three techniques with high reuse value: lower-bounded decay parameterized linear attention, quantile-balancing dynamic load balancing, and block-level attention residuals. The three correspond respectively to operator efficiency, routing efficiency, and depth efficiency. They can be implemented independently or combined into a system optimization approach for long-context and large-scale sparsity.
1. Lower-Bounded Decay Parameterized Linear Attention: Unifying All Causal Tiles on Matrix Multiplication
Linear attention and its incremental variants typically achieve linear complexity through recurrent states and decay factors. To improve parallelism, engineering implementations split sequences into fixed-length chunks, compute position-pair contributions within each chunk, and pass states between chunks. The problem is that the diagonal blocks within a chunk need to handle the reciprocal of the cumulative decay factor: when the decay factor is too small under finite precision, its reciprocal may overflow; when the decay factor is too large, it may underflow, causing numerical instability. Conventional approaches often route diagonal blocks through an explicit position-pair path while routing off-diagonal blocks through a dense matrix multiplication path. Although this special branch ensures correctness, it breaks operator uniformity and prevents diagonal blocks from fully benefiting from the matrix multiplication acceleration of tensor compute cores.
The core idea of lower-bounded decay parameterization is to replace unbounded logarithmic decay with a bounded parameterized form. Let the logarithmic decay at each step be:
g_t = g_min * sigmoid(s_t)
Here, s_t is a score produced by the input or learnable parameters, and g_min is a negative constant lower bound, for example -5 in an example. Since the output of sigmoid lies between 0 and 1, g_t is constrained to the interval (g_min, 0). For a tile of length L, the cumulative logarithmic decay G = sum(g_t) satisfies G >= g_min * L, so the reciprocal of the cumulative decay factor can be bounded by exp(-g_min * L). As long as an appropriate lower bound is selected according to tile length, data type, and precision tolerance, the scaling factors within any 16-token or larger tile can fall into a safe numerical range.
Pseudocode:
def lower_bounded_log_decay(s, g_min=-5.0):return g_min * sigmoid(s)def tile_inverse_scale(log_decay_tile):cumulative = prefix_sum(log_decay_tile)return exp(-cumulative)
The engineering benefit is direct: diagonal blocks no longer require a special computation branch, and all causal tiles—whether diagonal or off-diagonal—can call a unified dense matrix multiplication kernel. This reduces kernel branching and scheduling overhead and improves tensor compute core utilization. More importantly, lower-bounded decay is naturally suited to long-context extrapolation without positional encoding: the decay range is bounded, so long-distance states do not become distorted due to extreme scaling factors. When implementing this technique, three points require attention: a lower bound that is too tight weakens long-range memory capacity, while a lower bound that is too loose provides insufficient numerical safety; tile length, precision format, and normalization strategy need joint tuning; and training and inference must use the same decay parameterization and scaling logic to avoid distribution mismatch between offline training and online serving.
2. Quantile Balancing: Auxiliary-Loss-Free Dynamic Load Balancing for Very Large-Scale MoE
The core benefit of MoE models comes from sparse activation, but routing imbalance can create severe expert hotspots: a small number of experts are overwhelmed by a large number of tokens, forming compute and communication queues, while other experts remain idle, reducing overall throughput. A common approach is to add an auxiliary load-balancing loss to the main loss. However, the auxiliary loss competes with the main task objective in terms of gradients, makes weight tuning sensitive, and at very large scale can still lead to local balance while global communication remains congested.
The idea of quantile balancing is to replace the auxiliary loss with quantile estimates of routing scores. A typical implementation maintains a sliding distribution of routing scores for each expert, estimates a quantile threshold based on a target capacity ratio, and assigns tokens exceeding the threshold to the corresponding expert or updates the routing bias accordingly. Compared with a global fixed threshold, a quantile threshold can adjust dynamically with training batches and input distributions. Compared with an auxiliary loss, it does not directly enter the main loss gradient, avoiding interference from additional hyperparameters in main-task optimization.
Pseudocode:
def update_expert_threshold(scores, target_ratio):# Estimate the high quantile of each expert's score distributionreturn estimate_quantile(scores, 1 - target_ratio)def route(token_scores, expert_thresholds):# Select experts using thresholds and expert capacityreturn select_expert(token_scores, expert_thresholds)
In very large-scale expert parallelism, the value of quantile balancing lies in being fast and stable. Fast means threshold updates can overlap with forward routing, expert computation, and all-to-all communication. Stable means that characterizing load through quantiles rather than absolute values can adapt to score drift across batches and modalities. Implementation points include: using approximate quantile estimation to reduce sorting overhead; using a sliding window or exponential moving average to handle cold start; designing expert capacity, drop policy, and fallback path consistently; monitoring the number of tokens per expert, communication queue length, and the proportion of hot experts; and using the same threshold update frequency and capacity constraints in training and inference to avoid inconsistency between serving-side load patterns and training-side behavior.
3. Block-Level Attention Residuals: Alleviating Deep Representation Bottlenecks and Reducing Memory and Communication Overhead
The residual stream of a deep Transformer is typically accumulated layer by layer. Backpropagation needs to retain a large number of intermediate activations, so memory usage grows with depth. In distributed training, residual-related activation and gradient synchronization also increase communication overhead. Deeper models may also suffer from residual-stream dominance and insufficient mixing of deep representations: information is passed along a single residual path, and the incremental contribution of deep modules to representations is diluted.
Block-level attention residuals organize the residual stream by blocks: regular residual connections are retained within a block, while several block-level summaries are maintained across blocks. Historical block summaries are weighted through lightweight attention or learnable aggregation, and the aggregated result is injected into the current block. This preserves the training stability of residual connections while introducing cross-depth information mixing at block boundaries, alleviating deep representation bottlenecks. At the same time, backpropagation only needs to retain block-boundary summaries and necessary checkpoints, reducing the storage and cross-device communication of full intermediate activations.
Pseudocode:
def block_attention_residual(h, block_summaries):q = project_q(h)k = project_k(block_summaries)alpha = softmax(q @ transpose(k) / sqrt(d))summary = alpha @ block_summariesh = h + project_out(summary)return h, summary
The engineering benefits appear in three areas. First, for memory, block-level summaries replace part of the full activation storage, reducing memory pressure in deep training. Second, for communication, block-boundary aggregation reduces fine-grained residual synchronization and makes it easier to combine with pipeline parallelism and expert parallelism. Third, for representation, inter-block attention allows deep modules to selectively reuse shallow and middle-layer summaries, improving deep information flow. When implementing this technique, note the tradeoff between block size and number of layers: if blocks are too large, cross-block mixing becomes coarse; if blocks are too small, summary maintenance overhead increases. It is also necessary to ensure numerical stability of summary projection, normalization, and residual scaling, and to cache block summaries during inference to control latency.
4. Combined Deployment Recommendations: Operator First, Then Routing, Then Depth
The recommended order for combining the three techniques is “operator first, then routing, then depth.” In the first step, introduce lower-bounded decay parameterization into the linear attention path to unify the matrix multiplication path for causal tiles, prioritizing numerical safety and operator utilization. In the second step, introduce quantile balancing into MoE routing, using dynamic thresholds to replace auxiliary loss and reduce expert hotspots and all-to-all communication congestion. In the third step, introduce block-level attention residuals into the deep backbone to reduce memory and communication overhead and improve deep representation mixing. During deployment, a unified benchmark should be established: on the operator side, focus on tile throughput, numerical error, and long-context extrapolation stability; on the routing side, focus on expert load variance, hot expert proportion, and communication wait time; on the depth side, focus on peak memory, inter-block communication volume, and deep gradient health. Through staged rollout, precision alignment, and training-inference consistency checks, the three techniques can be advanced from point optimizations to a systematic solution, providing a reusable engineering path for long-context and large-scale sparse models.
