Lower-Bounded Decay Parameterization for Linear Attention: Principles and Engineering Implementation

    Linear attention reduces the quadratic cost of standard softmax attention, but its recurrent hidden state and chunk-based parallelization introduce numerical challenges—particularly with reciprocal scaling of cumulative decay factors. This article explains why naive decay parameterization breaks down in low-precision arithmetic, introduces a lower-bounded decay parameterization that keeps scaling factors within representable float32 range, and shows how it enables a unified dense computation path for both diagonal and off-diagonal tiles. It also covers practical guidance on reference implementations, precision management, and the joint constraint between chunk size and decay bound, plus brief overviews of auxiliary-loss-free MoE load balancing and chunked residual aggregation.

    1. Background: Why Linear Attention Struggles to Fully Utilize Hardware

    The computational cost of standard softmax attention grows quadratically with sequence length, making long-context scenarios expensive. Linear attention reduces the cost to approximately linear in sequence length by using kernel function approximations or state recurrence. The trade-off is that the model must maintain a hidden state that is updated token by token, and this recurrent structure is inherently harder to parallelize than dense matrix multiplication.

    The common engineering approach is chunk-based parallelism. The sequence is split into fixed-length chunks: computation within each chunk is handled with matrix operations, while state is passed between chunks through recurrence. Intra-chunk computation falls into two categories:

    • Off-diagonal blocks: interactions between the query chunk and historical key-value chunks. These have regular shapes and can be computed directly with dense matrix multiplication.
    • Diagonal blocks: interactions among tokens within the same chunk. These must satisfy both the causal mask and the relative decay between every pair of tokens.

    The decay factor is a key quantity in linear attention. Decay accumulates along the sequence at each step, so the total decay of position i relative to position j within a chunk equals the product of per-step decays between them. To convert this product into matrix operations, many implementations scale by the reciprocal of the cumulative value.

    1.1 Numerical Risks of Reciprocal Scaling

    Reciprocal scaling is fragile under low precision. Consider 16-bit floating point: the smallest representable positive subnormal number is roughly 2^-24. If the per-step decay is 0.5, the cumulative product underflows to zero after about 24 multiplications, and taking its reciprocal yields infinity, causing all subsequent computation to fail.

    1. # Pseudocode: reciprocal scaling in the naive approach
    2. # Assume per-step decay of 0.5, chunk length of 64, 16-bit floating point
    3. cum = 1
    4. for t in range(64):
    5. cum = cum * 0.5 # underflows to zero around step 25
    6. scale_inv = 1 / cum # result is infinity; subsequent computation fails

    To avoid this problem, implementers often isolate the diagonal blocks and compute them position by position. As a result, diagonal blocks cannot leverage efficient dense matrix multiplication and become a bottleneck for overall throughput.

    2. The Core Idea of Lower-Bounded Decay Parameterization

    This approach constrains the range of the decay values. It modifies only the parameterization and adds no extra computation steps.

    2.1 From Unbounded to Bounded

    If the log-decay is produced by an unbounded function—for example, the negative form of Softplus—its value can approach negative infinity, meaning the per-step decay can get arbitrarily close to zero. Switching to a bounded form constrains the log-decay to the interval [g_min, 0]:

    g_t = g_min · σ(s_h · z_t), where s_h = exp(A_h) > 0

    Meaning of the symbols:

    • σ is the Sigmoid function, with output in (0, 1).
    • g_min is a pre-set lower bound; the example uses -5.
    • s_h is a learnable scaling coefficient per attention head, guaranteed positive via the exponential.
    • z_t is the projected output at position t.

    With the lower bound fixed, the per-step decay exp(g_t) falls within [exp(g_min), 1]. With g_min = -5, this interval is roughly [0.0067, 1]. The per-step decay can no longer approach zero indefinitely, cutting off the source of numerical underflow.

    2.2 The Numerical Range Can Be Computed in Advance

    Within a tile of length 16, the absolute value of the cumulative log-decay is at most 16 × 5 = 80. The corresponding reciprocal scaling factor is at most about exp(80) ≈ 5.5 × 10^34, which falls within the representable range of 32-bit floating point (roughly 3.4 × 10^38).

    The significance of this result: the upper bound of the scaling factor is a constant computed directly from hyperparameters, independent of input data. Engineers only need to perform a one-time check before deployment, rather than relying on runtime heuristics.

    2.3 Diagonal Blocks Also Take the Dense Path

    With bounded scaling factors, diagonal and off-diagonal blocks can share the same formula.

    1. # Pseudocode: unified dense computation path within a chunk
    2. # b is the cumulative log-decay at each intra-chunk position (per-position prefix sum)
    3. Q_s = Q * exp(b) # query-side scaling
    4. K_s = K * exp(-b) # key-side reciprocal scaling, with a bounded numerical range
    5. A = Q_s @ K_s^T # dense matrix multiplication
    6. A = A * causal_mask # element-wise causal mask
    7. O = A @ V

    With this formulation, all causal tiles map to regular matrix multiplications, making scheduling and pipeline design more uniform. The main benefits are threefold:

    • Removing the special branch for diagonal blocks leaves a single code path, reducing maintenance and testing costs.
    • Computation concentrates on matrix multiplication units, making it easier to improve hardware utilization.
    • Changes to existing linear attention implementations are minimal; the core work lies in the parameterization and numerical range verification.

    2.4 Decay and Positional Information

    Decay itself carries distance information. The farther away a token is, the more decay accumulates and the lower the weight of that historical information. As a result, the model can perceive relative distance even without explicit positional encoding—such designs are typically called NoPE (No Position Encoding) schemes.

    Note that long-context extrapolation capability depends on multiple factors, including the training distribution, state capacity, and evaluation methodology. No conclusion should be drawn from the decay mechanism alone; actual benchmark results should be the reference.

    3. Engineering Recommendations

    3.1 Use a Naive Recurrence as the Reference Implementation

    First implement a per-token recurrent version as the baseline, then compare it against the chunked implementation. Test inputs should cover random data and edge cases, such as long sequences with decay near 1 and sequences with decay near the lower bound.

    1. # Pseudocode: numerical consistency check
    2. ref = recurrent_reference(Q, K, V, g) # naive recurrence; reliable but slow
    3. out = chunked_kernel(Q, K, V, g) # chunked implementation under test
    4. assert max_abs_error(ref, out) < tol # tol set according to precision and task

    3.2 Use Higher Precision for Cumulative Quantities

    Intra-chunk log-decay prefix sums are prone to error accumulation, so it is recommended to store them in higher precision. Low precision should only be used for matrix multiplication inputs, preserving throughput without sacrificing cumulative accuracy.

    3.3 Chunk Size and Lower Bound Must Be Tuned Together

    The chunk length C and the lower bound |g_min| jointly determine the upper limit of the scaling factor. Their product must satisfy the following constraint:

    |g_min| × C ≤ ln(numerical upper limit)

    For 32-bit floating point, ln(3.4 × 10^38) ≈ 88.7. With g_min = -5 and C = 16, the product is 80, leaving a margin of only about 8.7. If the chunk length is increased to 18, the product reaches 90 and exceeds the representable range. Therefore, whenever you adjust the chunk size or the lower bound, recheck this constraint.

    The following two techniques are independent of the decay parameterization above. This section covers only the problem background and general ideas, without implementation details.

    4.1 Auxiliary-Loss-Free MoE Load Balancing

    In MoE models, the router may assign most tokens to a few experts, leaving other compute units idle for long periods. The common approach is to add an auxiliary load-balancing term to the training loss, but this term’s gradients can conflict with the language modeling objective and sometimes degrade model quality.

    The auxiliary-loss-free approach does not modify the loss function. Instead, it dynamically adjusts routing tendencies based on the statistical distribution of recent load across experts: heavily loaded experts have their selection probability relatively decreased, while lightly loaded experts have it relatively increased. This decouples load control from the main training objective. The specific statistics and update rules should follow the original source material.

    4.2 Chunked Residual Aggregation

    In deep Transformers, the residual stream accumulates layer by layer. Information from early layers can be diluted by later layers, while each layer’s intermediate representations must participate in backpropagation or cross-device communication, so memory and bandwidth pressure grows with depth.

    The chunked residual approach groups several adjacent layers into a block: computation proceeds normally within a block, and only aggregated representations are passed between blocks. This reduces the intermediate states that must be stored and transmitted, and gives deep-layer information a chance to be preserved in a more compact form. This direction is sensitive to structural assumptions and requires ablation studies tailored to the specific model.

    5. Adoption Recommendations

    Technique Suitable Scenarios Main Risks
    Lower-bounded decay parameterization Models already using linear attention that want to improve chunked computation efficiency Lower bound and chunk size must be verified jointly; numerical boundaries need reconfirmation
    Auxiliary-loss-free load balancing Large-scale MoE training where the auxiliary loss interferes with the main task Statistics and update rules must be tuned in coordination with training stability
    Chunked residual aggregation Deep models where memory or cross-device communication is a bottleneck Sensitive to network structure assumptions; requires ablation experiments

    When making a selection, first assess whether your model architecture is a good match, then evaluate the cost of adoption. The lower-bounded decay parameterization requires the fewest changes and is a suitable first candidate for validation.