[KongchangAI]
· 2 min read· 1,253 words

Sampler Replay: Why RLVR Training Should Optimize the Sampler, Not the Trainer

Sampler Replay: Why RLVR Training Should Optimize the Sampler, Not the Trainer

New paper argues RLVR should train the sampler directly rather than a trainer that tolerates the sampler, proposing Sampler Replay.

The article introduces a new paper re-examining Train-Inference Mismatch (TIM) in RLVR. The conventional view attributes TIM to the trainer absorbing data from an imperfect sampler, designing algorithms around gradient bias correction — essentially training a trainer that tolerates a bad sampler. The paper argues this framework is misaligned: at deployment users invoke the sampler, not the trainer, so optimization should target the sampler directly. The authors propose Sampler Replay, which replays the sampler's hidden states, logits, and routing decisions during the trainer's forward pass so gradients approach the sampler's true gradients. Experiments show it stabilizes training under severe TIM from quantization, weight perturbations, and staleness, outperforming strong baselines, and the paper mathematically proves Score Centering is just its logits-only special case, unifying existing TIM mitigation techniques.

Sampler Replay: Why RLVR Training Should Optimize the Sampler, Not the Trainer

Reinforcement Learning with Verifiable Rewards (RLVR) has shown strong performance in improving model reasoning capabilities, but a long-overlooked problem is capping its potential: Train-Inference Mismatch (TIM). The conventional view attributes this problem to "the trainer absorbing data produced by an imperfect sampler," and algorithm design has therefore revolved around correcting gradient bias. A new paper proposes a fundamentally different perspective — since what actually matters at test time is the sampler's behavior, why not train the sampler directly?

Sampler Replay paper source screenshot

Redefining the Problem: From "Training the Trainer" to "Training the Sampler"

Current mainstream RLVR algorithms treat the sampler as an efficiency tool that may produce off-policy trajectories due to quantization, weight perturbations, or staleness. The trainer's job is to compensate for the gradient discrepancies introduced by these trajectories — essentially "training a trainer that can tolerate a bad sampler."

The paper's authors point out a fundamental misalignment in this framework: at deployment time, users invoke the sampler, not the trainer. No matter how precise the trainer's gradients are, if the sampler's own behavior is not properly optimized, test performance will still suffer. They therefore argue for demoting the trainer to "a mechanism for approximating the sampler's true gradients," with the optimization target aimed directly at the sampler.

This shift in perspective yields a key corollary: solving TIM should not rely solely on correcting the trainer; the trainer must "see" the states the sampler actually experiences during the forward pass when performing backpropagation.

RLVR (Reinforcement Learning with Verifiable Rewards) is a reinforcement learning training paradigm whose core feature is that reward signals come from automatically verifiable correctness judgments — for example, whether a math answer matches, or whether code passes unit tests. Unlike RLHF, which relies on human preference annotations, RLVR does not require training a reward model; rewards are deterministic and programmatically verifiable. This characteristic makes it particularly effective for tasks such as mathematical reasoning and code generation, and it has become a key training method for reasoning models like DeepSeekAd-R1. However, because rewards reflect only final outcomes and cannot constrain the intermediate sampling process, RLVR is far more sensitive to sampler behavior than traditional RLHF — which is precisely the root cause of why the TIM problem is amplified in RLVR.

How Sampler Replay Works

Sampler Replay's core operation is to replay the sampler's hidden states, logits, and routing decisions during the trainer's forward pass. This makes the gradients computed by the trainer closer to the sampler's true gradients, rather than an approximation based on idealized assumptions.

The paper validates the method across multiple tasks and model scales. Experiments show that under severe TIM conditions induced by quantization (weights, activations, KV cache), weight perturbations, and staleness, Sampler Replay stabilizes training and outperforms strong baselines. This means that when the inference side adopts aggressive quantization for efficiency, the training side no longer has to sacrifice stability as the cost.

One detail worth noting: the algorithm does not add overhead out of thin air. Through its replay mechanism, it injects the sampler's key information along the inference path into the training path, realigning the two at the gradient level.

Routing decisions here refer to the expert assignment scheme that the gating network selects for each token in a Mixture-of-Experts (MoE) architecture. In an MoE model, the forward computation path is not fixed; the gating network dynamically determines which experts participate in computation. When the sampler's gating scores shift slightly due to quantization or weight perturbations, the set of activated experts may differ entirely, causing hidden states and logits to diverge significantly. Such discrete routing differences cannot be compensated by simple numerical approximation — the routes the sampler actually selects must be precisely replayed during training for gradients to reflect the true computation graph. This is also why Sampler Replay needs to replay routing decisions rather than just logits.

Unifying Existing Techniques: Score Centering Is Just a Special Case

Another contribution of the paper is its theoretical unification. Various techniques for handling TIM in prior literature have often been proposed and discussed independently, but the authors show that Sampler Replay is a generalization of these techniques.

The most intuitive example is Score Centering: the paper mathematically proves that Score Centering is equivalent to the special case of Sampler Replay where only logits are replayed. This conclusion not only explains why Score Centering works, but also provides a unified explanatory framework for other TIM mitigation techniques. For engineering practitioners, this means they no longer need to choose among multiple unrelated tricks; instead, they can understand each one's applicable scope and limitations within the Sampler Replay framework.

Score Centering is a technique for correcting gradient bias in off-policy RL training. It works by subtracting a baseline score (typically the mean of the current batch's scores or some reference value) when computing the policy gradient, so that the expected gradient estimate is closer to the on-policy gradient. In the TIM context, Score Centering works because it implicitly compensates for the shift in logits distribution between the sampler and the trainer. Sampler Replay's mathematical proof reveals the exact mechanism of this implicit compensation: Score Centering is equivalent to a restricted version that replays only the sampler's logits without replaying hidden states and routing decisions. It can therefore correct logits shifts caused by numerical precision differences, but cannot handle more structural divergences such as routing changes — which explains why its effectiveness is limited under severe TIM.

Implications for RLVR Engineering Practice

In real-world RLVR deployments, inference efficiency pressures often lead the sampler and trainer to use different numerical precisions or policy update cadences. Sampler Replay sends a clear signal: rather than continually patching the training side, make the training process faithfully reflect the sampler's actual computation path.

This line of thinking has direct reference value for quantization-aware training, asynchronous RLHF pipelines, and large-scale distributed inference scenarios. When the sampler is "imperfect" due to system constraints, what the trainer needs is an accurate model of that imperfection — not robustness to it.

The paper is currently released as a preprint, with code and further experimental details pending public release. But its core proposition — train the sampler, not a trainer that tolerates the sampler — is worth revisiting for RLVR researchers and engineers as they re-examine the design assumptions of existing algorithms.

One-line Summary

A new paper argues that RLVR should directly train the sampler rather than a trainer that tolerates the sampler, and proposes the Sampler Replay method.

Paragraph Summary

The article introduces a new paper that re-examines the Train-Inference Mismatch (TIM) problem in RLVR. The conventional view attributes TIM to the trainer absorbing data from an imperfect sampler, and therefore designs algorithms around correcting gradient bias — essentially training a trainer that can tolerate a bad sampler. The paper points out a misalignment in this framework: at deployment time, users invoke the sampler, not the trainer, so the optimization target should be aimed directly at the sampler. To this end, the authors propose Sampler Replay, which replays the sampler's hidden states, logits, and routing decisions during the trainer's forward pass so that gradients more closely match the sampler's true gradients. Experiments show that the method stabilizes training under severe TIM induced by quantization, weight perturbations, and staleness, and outperforms strong baselines. The paper also mathematically proves that Score Centering is merely a special case of Sampler Replay that replays only logits, unifying existing TIM mitigation techniques.

#RLVR#Sampler Replay#Train-Inference Mismatch#TIM#Score Centering#Mixture-of-Experts#reinforcement learning#quantization
Share:

Related articles