Training Large Models: Three Optimizations for Numerical Stability, Load Balancing, and Residual Connections

    This article discusses three training optimizations for large-scale Transformer models: KDA (lower-bounded decay parameterization for linear attention), QB (quantile balancing for Mixture-of-Experts without auxiliary loss), and Block AttnRes (block-level attention residual connections). Each technique is explained with its motivation, implementation form, expected benefits, and validation methods. The article focuses on system–model co-design rather than simply scaling compute, and provides practical checklists for engineering adoption.

    Introduction: From Compute Scaling to System–Model Co-Design

    Long-context, ultra-large sparse models, and deep Transformers place higher demands on training systems. Simply adding compute cannot simultaneously resolve conflicts among low-level operator efficiency, distributed scheduling, and representation quality. This article introduces three training optimizations: KDA’s lower-bounded decay parameterization, auxiliary-loss-free quantile balancing (QB), and block-level attention residuals (Block AttnRes). Each is described with its problem origin, implementation form, expected benefits, and verification methods. The numbers and formulas are used to illustrate principles; actual results depend on the target hardware, framework version, and model.

    1. KDA: Stabilizing Linear Attention with Lower-Bounded Decay Parameterization

    1.1 Problem Origin

    Linear attention reduces computational complexity to near-linear in sequence length, making it a common route for processing extremely long sequences. During training, it is typically computed in chunks in parallel. Traditional approaches use an unbounded negative Softplus to parameterize the log of the cumulative decay. This parameterization ensures monotonicity of the decay, but the computation of the diagonal block within a chunk requires the inverse of the cumulative decay. The more aggressive the decay and the longer the chunk, the larger the magnitude of the inverse, which may cause overflow or precision loss in low-precision formats.

    To avoid numerical issues, some implementations switch the diagonal block to element-wise positional calculations, bypassing the unified Tensor Core matrix multiplication path. This is more numerically stable but reduces hardware utilization.

    1.2 Parameterization Form and Numerical Range

    The original form is given as:

    g_new = g_min · Sigmoid(Δ)

    where g_min is a preset constant (example value: -5), and Δ is a learnable parameter. This restricts the log-decay to the interval [g_min, 0].

    For a 16-token tile, the minimum cumulative decay within the tile is 16 × (-5) = -80, and the magnitude of its inverse is e^80 ≈ 5.5 × 10^34. BF16 and FP32 have the same exponent bit width, with a maximum finite value of about 3.4 × 10^38, so this magnitude is still representable. However, BF16 has only 7 explicit mantissa bits, so the relative precision of the inverse is low. Thus, g_min and tile size must be chosen together and confirmed by error comparison. The above derivation assumes a 16-token tile and the example g_min; changing either requires recalculation.

    1.3 Engineering Benefits and Applicability

    If the inverse is bounded within a safe range, the diagonal block can share the same matrix multiplication kernel as other causal tiles, reducing special branches. This benefit depends on chunk size, tile size, kernel implementation, and hardware platform. Measurement should fix a baseline, comparing the original parameterization on the same kernel version. Metrics to compare include training and inference throughput, numerical error, and training loss curves.

    The original article states that this parameterization can extrapolate from short windows to million-scale contexts. This claim needs verification on long-context evaluation sets. Extrapolation capability may also be affected by position encoding schemes and training data distribution, so it cannot be inferred solely from the parameterization.

    1.4 Verification Checklist

    • Count Inf and NaN occurrences at the target tile size.
    • Compare output errors between the branched and unified GEMM versions.
    • Record tokens/s and memory usage, specifying sequence length and batch size.
    • Test extrapolation performance on long-context tasks.

    2. QB: Load Balancing in MoE without Auxiliary Loss

    2.1 Cost of Auxiliary Loss

    In MoE models, expert-parallel load balancing directly affects the compute time of each device. A common practice adds an auxiliary loss to the training objective to penalize imbalanced routing. This has two problems. First, the auxiliary loss conflicts with the language-modeling cross-entropy objective, and the coefficient requires manual tuning; improper selection can harm convergence. Second, auxiliary-loss statistics and gradient computation require additional synchronization and communication.

    2.2 Basic QB Flow

    The QB described in the original article does not add a penalty term to the loss; instead, it adjusts the quantile of the logits distribution during routing. The following flow is based on the original description; exact rules follow the original implementation:

    1. The gating network outputs logits for each expert per token in the batch.
    2. For each expert, compute the quantile threshold of the logits across the batch.
    3. Tokens that exceed the threshold and also exceed the expert’s capacity are reassigned to the next-best expert that still has capacity.
    4. Execute expert computation according to the reassigned result.

    Step 3 changes the original top-k selection. Details to confirm include: how the gate weights are renormalized after reassignment, whether reassigned tokens participate in gradient backpropagation, and the relationship between capacity factor and quantile threshold. These affect model quality and communication volume.

    2.3 Applicability

    • Benefits are more likely when the number of experts is large and load skew is significant.
    • The scenario requires a uniform capacity constraint or full expert parallelism.
    • If the task relies on the long-tail distribution of routing to maintain expert specialization, forced balancing may hurt model quality; direct adoption is not recommended.

    2.4 Evaluation Metrics

    • Coefficient of variation of expert load, and ratio of max load to average load.
    • Proportion of reassigned or dropped tokens.
    • All-to-all communication bytes per step.
    • Validation perplexity or downstream task metrics, to confirm balancing does not compromise model quality.

    3. Block AttnRes: Adding Local Residuals within Chunks

    3.1 Standard Residual Review

    The standard residual form of a Transformer sublayer is:

    y = x + Attn(x)

    The residual path allows information and gradients to pass directly through the sublayer, helping mitigate degradation in deep networks.

    3.2 Block-Level Residual Illustration

    The original article refines the granularity of residual connections to inside the attention block. The form below is an illustrative notation based on the original description; the exact definition should be referred to the original paper or code:

    y_b = Attn(x_b) + x_b (or similar block-level residual within a chunk)

    This approach introduces a local residual inside each attention chunk, potentially improving gradient flow and representation stability for very deep models. The exact formulation and benefits need to be validated on the target architecture.