Stabilizing Large-Scale RL Post-Training: Unbiased KL, Sequence Masking, and Consistency Constraints

    This article examines three algorithmic refinements to the standard GRPO objective for large-scale reinforcement learning post-training. It explains why training becomes unstable at scale, how an unbiased KL estimator reduces gradient explosion, how off-policy sequence masking filters harmful learning signals, and how Keep Routing and Keep Sampling Mask reduce train-inference objective drift. It also summarizes the token-, sequence-, and system-level stability methodology behind these changes and distills practical lessons for engineers building large-scale training pipelines.

    Stabilizing Large-Scale RL Post-Training: Unbiased KL, Sequence Masking, and Consistency Constraints

    A team behind an open-source large model recently released a new-generation model and technical report, prompting extensive discussion across the industry. Much has already been said about model capabilities, so this article does not repeat that analysis. Instead, it focuses on a more engineering-oriented question: during large-scale reinforcement learning (RL) post-training, how can algorithmic improvements address the two persistent problems of “training instability” and “policy drift”?

    The team made three changes to the objective function of the standard GRPO (Group Relative Policy Optimization) algorithm: a mathematical correction (unbiased KL estimation), stability filtering (off-policy sequence masking), and consistency constraints (Keep Routing and Keep Sampling Mask). Although these three changes appear independent, they point to the same core insight: in large-scale training, numerical stability takes priority over theoretical exactness. The following sections examine each change in turn.

    1. Background: Why Large-Scale RL Post-Training Is Unstable

    In reinforcement learning from human feedback or from verifiable rewards, a KL divergence regularization term is typically added to the policy update to prevent the new policy from drifting too far from the reference policy—that is, to prevent the model from “training off the rails.” The standard approach is to add (\mathbb{D}{KL}(\pi{\theta} | \pi_{ref})) to the objective function as a penalty term.

    At small training scales, this mechanism works well. But once RL post-training compute is scaled to a substantial proportion of pretraining cost—for example, more than 10%—a series of numerical problems that were masked at small and medium scales tends to surface:

    • Gradient explosion: some tokens have extremely low probability under the current policy, causing the gradient of the KL term to approach infinity.
    • Ineffective learning: the sampling policy and the current policy distributions diverge too much, and noise in the gradient signal drowns out useful information.
    • Objective drift: the inference environment and training environment behave inconsistently (for example, MoE routing or sampling truncation), so the optimization objective becomes disconnected from actual behavior.

    These are precisely the problems targeted by the team’s three improvements.

    2. Improvement 1: Unbiased KL Estimation—Addressing Gradient Explosion

    Root Cause

    In PPO/GRPO-style algorithms, commonly used KL estimators (such as the K3 estimator) have a hidden risk when computing gradients: when the current policy (\pi{\theta}) assigns a much lower probability to a token than the reference policy does ((\pi{\theta} \ll \pi{ref})), the (\pi{\theta}) term in the denominator can amplify the gradient to a dangerous magnitude. This causes numerical instability and, in severe cases, can ruin an entire training run.

    Approach

    The team introduced a correction term based on importance sampling, rewriting the KL estimate as follows:

    1. D_KL ≈ (π_θ / π_old) · ( π_ref/π_θ − log(π_ref/π_θ) − 1 )

    Here it is important to distinguish two easily confused concepts:

    • (\pi_{old}) (old policy): responsible for producing data. It is the policy at the moment of data sampling and is used to generate the rollout batches used in training.
    • (\pi_{\theta}) (current policy): responsible for being optimized. It is the model policy whose parameters are being updated by gradient descent.

    By introducing the importance-sampling ratio (\pi{\theta}/\pi{old}), the gradient calculation remains unbiased in mathematical expectation while numerically avoiding gradient explosion caused by low-probability events. In one sentence: reorganize the KL term from a sampling perspective so that extreme samples no longer dominate the gradient.

    3. Improvement 2: Off-Policy Sequence Masking—Filtering Out Ineffective Learning Signals

    Root Cause

    In actual training, rollout data is generated by the old policy, while optimization happens on the current policy. As iterations proceed, the two distributions gradually diverge—that is, the degree of off-policyness increases. If the distribution shift for certain sequences is too large, gradients computed from those data not only fail to help learning but also introduce harmful noise.

    Approach

    The team’s approach is to apply stability filtering at the entire-sequence level: when the distribution difference between the old policy and the current policy for a sequence exceeds a threshold, that sequence is directly masked out of the loss calculation rather than “corrected.”

    This is a highly engineering-oriented trade-off—giving up theoretical correction of extreme samples in exchange for cleaner and more stable overall gradient signals. Its essence is acknowledging a practical reality: in large-scale training, discarding bad data is more cost-effective than rescuing it.

    4. Improvement 3: Consistency Constraints—Eliminating Train-Inference Objective Drift

    Keep Routing (for MoE Architectures)

    In mixture-of-experts (MoE) models, each token is routed to a specific expert subnetwork. If routing decisions differ between training and inference, the parameters updated by the optimizer become misaligned with the actual forward paths that take effect, causing “training something different from what is used.” Keep Routing fixes or aligns inference-time routing decisions during training, ensuring that gradient updates act on the expert parameters along the real inference path.

    Keep Sampling Mask (for Top-P/Top-K Truncation)

    Similarly, online inference usually applies Top-P or Top-K sampling truncation, meaning low-probability tokens never enter the candidate set. If training also computes loss and gradients for tokens that cannot possibly be sampled, objective drift occurs—the model optimizes behavior that will never happen. Keep Sampling Mask reproduces the inference-time sampling mask in the training loss, applying optimization pressure only to tokens that could actually be selected during inference.

    Together, these two constraints ensure that the policy described by the training objective is strictly consistent with the policy actually executed at inference time.

    5. Overall Perspective: A Methodology That Prioritizes Engineering Stability

    Connecting the three improvements reveals a clear technical路线:

    1. Unbiased KL prevents gradient explosion when probabilities are extremely low—addressing “single-token-level” numerical problems.
    2. Sequence masking prevents ineffective learning when distribution differences are too large—addressing “whole-sequence-level” data quality problems.
    3. Keep Routing / Keep Sampling prevents inconsistency between training and inference environments—addressing “system-level” objective alignment problems.

    With safeguards at the token, sequence, and system levels, RL post-training compute can be scaled to more than 10% of pretraining cost without collapse. This is the key infrastructure behind the new model’s substantial gains in reasoning capability—not a single point technique, but a complete stability-oriented training engineering system.

    6. Lessons for Developers

    For engineers working on large-model training or large-model application development, this methodology offers several broadly applicable lessons:

    • Stability takes priority over exactness: in large-scale systems, a theoretically perfect but numerically fragile solution is often inferior to a slightly biased but robust one.
    • Bad data is better discarded than mishandled: for samples with severe distribution shift, discarding them directly is usually safer than forcing a correction.
    • Train-inference consistency is a hidden red line: any behavior that exists at inference time but is missing during training—routing, truncation, caching—can become a hidden source of performance bottlenecks.
    • Infrastructure determines the capability ceiling: putting algorithmic innovation into production depends heavily on the maturity of training frameworks, compute scheduling, and monitoring systems. In practice, general-purpose container platforms, distributed training scheduling, logging services, and monitoring/alerting in cloud environments can help teams build large-scale training pipelines with observability and fault tolerance more efficiently, allowing them to focus on the algorithms themselves.

    Conclusion

    On the surface, this model update is a capability improvement. At a deeper level, it reflects the maturation of RL training engineering methodology. The three measures—unbiased KL, sequence masking, and consistency constraints—provide a validated answer to the industry-wide question of how to scale RL post-training. For any team working on large-model post-training, this pragmatic philosophy of “numerical stability over theoretical exactness” is worth revisiting.