Linear Attention Decay Parameter Lower Bound: Value Selection, Numerical Checks, and Migration

    This article explains why linear attention implementations need a lower bound on the log-decay parameter, presents a sigmoid-based parameterization, verifies BF16 and FP16 exponent ranges for common chunk lengths, and outlines validation, migration, acceptance, and rollback criteria for moving the diagonal block back into a unified GEMM path.

    1. Why Set a Lower Bound for the Decay Parameter

    Linear attention compresses historical information into a fixed-size state matrix. At each step, the old state is decayed over time and then accumulated. In long-context inference, this makes inference cost grow approximately linearly with sequence length, so the approach remains worth investing in.

    In engineering practice, the most error-prone part is the numerical range of the decay factor. In chunked parallel implementations, the diagonal part within a chunk must be multiplied by the reciprocal of the cumulative decay Γ. If log-decay, denoted g, is produced by an unbounded negative activation, then g has no lower bound. When decay is very strong, the reciprocal of Γ may exceed the range representable by BF16, producing inf or 0.

    To avoid this problem, some implementations split out the diagonal block and replace matrix multiplication with position-wise explicit computation. As a result, part of the same operator cannot use Tensor Core dense GEMM. The kernel becomes more complex and throughput decreases. Setting a lower bound on g keeps the numerical range finite and creates an opportunity to merge the diagonal block back into a unified GEMM path.

    This article discusses only this change.

    2. How to Write the Lower-Bound Parameterization

    The core approach is to restrict g to a finite interval. The code below is illustrative and cannot be run directly. The variable eAh_z is the output of a learnable linear projection with shape [batch, heads, seq_len], obtained from input hidden states through a linear layer.

    1. # Illustrative code, not a complete implementation
    2. # Requires: PyTorch >= 2.0; shown only to illustrate the numerical range
    3. g_min = -5.0
    4. g = g_min * torch.sigmoid(eAh_z) # g lies in (-5, 0)
    5. decay = torch.exp(g) # per-step decay factor lies in (e^-5, 1)

    The output of sigmoid is strictly within (0, 1), so neither endpoint of g is reached. In practice, g lies in the open interval (g_min, 0). Validation assertions should use g_min < g < 0 and allow for floating-point error.

    The value of g_min also determines the fastest forgetting speed the model can achieve. The lower bound of the per-step decay factor is exp(g_min). A larger absolute value of g_min allows the state to discard old information more quickly; if the absolute value is too small, the state accumulates too much history. Therefore, g_min should not be chosen only for numerical stability; it must also be tested on downstream tasks.

    3. Numerical Range Verification

    Take a chunk length of 16 as an example. The maximum absolute value of g per step is 5, so the maximum accumulated log scale within one tile is 16 × 5 = 80. The corresponding reciprocal scaling factor is exp(80), approximately 5.5 × 10^34.

    BF16 and FP32 use the same 8-bit exponent. The maximum natural logarithm of BF16 normal numbers is approximately 88.7, and the minimum is approximately -87.3. Therefore, exp(±80) remains within the BF16 normal-number range, with a margin of approximately 8.7. This gives the constraint: when tile length × |g_min| < 87, reciprocal scaling will not fail due to exponent overflow. Common values are shown below:

    Chunk length Maximum accumulation when g_min = -5 Satisfies < 87? Allowed upper limit of g_min
    16 80 Yes About 5.4
    32 160 No About 2.7
    64 320 No About 1.36

    The exponent range differs greatly across precisions, and the conclusion changes accordingly:

    Format Exponent bits Max natural log of normal numbers Min natural log of normal numbers Can it hold exp(±80)?
    FP32 8 About 88.7 About -87.3 Yes
    BF16 8 About 88.7 About -87.3 Yes
    FP16 5 About 11.1 About -9.7 No

    If the kernel runs under FP16, the upper limit must be recalculated. In addition, this conclusion applies only to the decay factor itself. The actual kernel must also check intermediate products, FP32 accumulation, and output normalization steps.

    4. Validation Methods

    Validation is performed in three steps.

    1. Distribution check. During training and inference, record the minimum value and the P1, P50, and P99 percentiles of g for each layer, and confirm that the actual distribution does not exceed (g_min, 0). If P1 stays close to g_min for a long time, the lower bound may be limiting model expressiveness, and this should be judged together with task performance.
    2. Numerical check. For random inputs and real corpora, compute the maximum value of Γ^-1 and compare it with the BF16 upper limit. Because the bound on g is guaranteed by g_min, the measured ln(Γ^-1) should not exceed the theoretical upper limit of tile length × |g_min|. If the measured value exceeds the theoretical upper limit, the implementation is incorrect.
    3. Output comparison. Using an FP32 reference implementation as the baseline, compare the relative error between the branch version and the unified GEMM version under BF16. The threshold should be based on comparable error measured on the baseline model; a starting point can be a multiple of the BF16 single-rounding error (approximately 4 × 10^-3).

    Every validation run should record the hardware model, driver and framework versions, precision settings, and random seed for reproducibility.

    5. Migration Steps and Acceptance Criteria

    1. Inspect the existing definition of the decay parameter and identify any unbounded activation, such as negative-softplus.
    2. Set g_min, verify tile length × |g_min| < 87 using the tile length, and confirm it under BF16.
    3. Merge the diagonal block into the unified GEMM path, keep the original branch as a control, and use the same random seed for both paths.
    4. Compare the output difference, throughput, and memory usage of the two paths.
    5. Test the impact of g_min on downstream tasks. The task set should include both long-range dependency tasks, such as long-document retrieval, and short-range dependency tasks, such as local language modeling. The control group is the model with the original decay parameterization, and metric differences must remain within the tolerance set by the team.
    6. Acceptance criteria: throughput is not lower than the baseline (threshold set by the team), memory does not increase, and downstream metric differences remain within tolerance.
    7. Rollback conditions: if any downstream metric drops beyond tolerance, or if g stays close to g_min for a long time and task metrics drop, switch back to the original branch and retain the ablation results for g_min.

    This change involves only the definition and initialization of the decay parameter; the backbone network does not need to change.

    6. Summary

    The scope of the change is small, and the main risk comes from the value of g_min. Numerical verification should be done first, followed by branch comparison, and finally downstream tasks should determine the value of g_min.