On-Policy Counterfactual Influence

Rhys Gould, Yaowen Ye, Stuart Russell, Jacob SteinhardtNeurIPS 2026

TL;DR

In reinforcement learning, training data isn't static—every update changes the model, which changes the actions it takes next, creating a cascading "butterfly effect" across the rest of training. Traditional data attribution methods ignore this feedback loop and consequently fail to identify which moments in training actually mattered. This paper introduces a fast, mathematically grounded way to trace those ripples back to their source, letting us pinpoint helpful or harmful training events and actively steer RL models toward better performance.

Overview of on-policy counterfactual influence and weighted retraining

What Problem Does This Paper Address?

Suppose your newly trained language model exhibits a brilliant reasoning trick—or a subtle flaw. How do you figure out which specific training examples caused that behavior? In supervised learning, "data attribution" tools (like Influence Functions or TracIn) estimate what would happen if you deleted a single data point and retrained. Crucially, they assume the rest of your dataset stays fixed.

In on-policy reinforcement learning (like PPO or GRPO, the workhorses behind modern reasoning models), that assumption completely breaks down. Because the model generates its own training data on the fly, removing a single rollout at step $k$ alters the policy's weights, causing it to sample different actions at step $k+1$, leading to different rewards and updates all the way to the end of training. Existing attribution methods treat historical rollouts as frozen, missing this policy-data interaction gap entirely.

Figure 2: Counterfactual training dynamics under the removal of τ’s contribution at update step k. The off-policy counterfactual (dashed blue) approximates the true counterfactual by reusing data from the original training run after update step k, while the on-policy counterfactual (red) samples new data, recovering the true counterfactual.

Methods

Brute-force retraining the model for every single training event is computationally impossible. Instead, the authors define on-policy counterfactual influence—the change in a final target metric if a specific rollout's gradient were removed—and derive a tractable first-order Taylor approximation.

When you unroll the training dynamics, an event's influence propagates forward through two distinct matrices:

  1. The Loss Hessian ($\mathbf{H}$): How today's parameter shift alters the shape of tomorrow's loss landscape (standard in prior unrolling methods).
  2. The Policy-Data Interaction Matrix ($\mathbf{\Pi}$): The covariance between the policy gradient and the score function ($\nabla_\theta \log \pi_\theta$). This is the paper's core theoretical addition—it mathematically tracks how an update shifts the probability of sampling future trajectories.

To make this practical for modern deep learning, the authors make two major engineering leaps beyond prior work:

  • Adaptive Optimizers: Prior unrolling methods were stuck assuming vanilla SGD. Here, the authors characterize how perturbations propagate through internal optimizer states—momentum, adaptive scaling, and weight decay—giving us an exact formulation for AdamW.
  • Linear-Time Algorithm: Using reverse-mode accumulation (walking backward from the final step $K$ down to $1$), they compute the influence of every training event in a single backward pass. For $K$ steps and batch size $B$, this takes $O(KB)$ Hessian-vector products.

Datasets

No new static datasets are introduced, as data is generated dynamically on-policy:

  • Synthetic Linear MDP: A lightweight environment mimicking LLM RL finetuning. A policy receives Gaussian state vectors ("prompts") of pool size 320, generates action sequences ("chain-of-thought tokens"), and gets an outcome reward, evaluated on a disjoint pool of held-out states.
  • Verifiable Algorithmic Tasks: Adapted from recent RL-for-reasoning work (Zeng et al., 2025), consisting of six synthetic tasks (addition, subtraction, multiplication, sorting, find_max, find_min) used to finetune Qwen3-0.6B (via LoRA and GRPO).

Key Insights and Ideas

  • Temporal Credit Assignment for Discovery: If you isolate the $\mathbf{\Pi}$ matrix, an event's influence neatly equals its immediate impact plus the influences of all future trajectories it made more likely. Imagine an RL agent stumbles upon a clever strategy once (discovery) and uses it 100 times later (exploitation). Off-policy methods credit the 100 mundane exploitations; $\mathbf{\Pi}$ funnels credit for all 100 future events back to that single "aha!" moment of discovery.
  • Unifying Prior Attribution Methods: Classic methods fall out as crippled special cases of this framework. Zero out $\mathbf{\Pi}$, and you get off-policy unrolling (like SGD-Influence). Zero out both $\mathbf{\Pi}$ and $\mathbf{H}$, and you get simple gradient dot-products (Direct Effect and TracIn).

Key Results

  • Predicting True Ablations: In the linear MDP (averaged across 512 seeds to beat RL noise), the authors' method ($I_{\text{ONPOL}}$) predicts the true effect of removing training states far better than any baseline (achieving $r = +0.98$, $\rho = +0.97$ on the evaluation scatter, vs. $r \le 0.80$ for Influence Functions, TracIn, and off-policy unrolling) and uniquely nails the single most influential state.
  • Steering RL Training: Reweighting GRPO advantages during retraining using $I_{\text{ONPOL}}$ scores boosts final expected reward by +0.39, outperforming all baselines in both continuous reweighting and bottom-$K$ harmful data pruning.
  • LLM Task Transfer: When holding out a target task during Qwen3-0.6B finetuning, $I_{\text{ONPOL}}$ identifies the most helpful training task in 9/12 cases (vs. 5/12 for baselines), with a mean Spearman correlation of +0.37 (vs. $-0.14$ for off-policy). On arithmetic tasks with strong cross-task transfer (addition $\leftrightarrow$ subtraction), it scores 5/6 while baselines score 0/6.

Limitations and Future Work

  • First-Order Breakdown: Because the method relies on a local linear approximation, its accuracy degrades if removing a single event drastically alters the parameter trajectory—such as under very high learning rates. Incorporating higher-order terms is a key next step.
  • RL Seed Variance: RL runs are notoriously noisy across random seeds, meaning raw per-event scores don't always generalize to brand-new runs unless aggregated over meaningful groups (like prompts or task sources).
  • Beyond RL: The framework naturally applies to any setup where the model shapes its own data stream; the authors suggest extending it to on-policy distillation and imitation learning (DAgger).

Summary updated

Abstract

On-policy training plays an important role in modern machine learning, especially in reinforcement learning (RL) for language models. However, quantifying how training data influences the policy's behavior is difficult in on-policy settings: one must account for the cascading effect by which a training event affects its immediate policy update, which in turn affects future action samples, which further affects future policy updates, and so on. Attribution methods developed for off-policy and supervised learning (e.g. influence functions) do not account for such \emph{policy-data interaction}, and can therefore fail in on-policy settings. In this work, we formalize the problem of attributing behaviors to individual training events in the on-policy setting. We derive an influence measure that accounts for policy-data interaction while also being tractable to compute in practical training setups (e.g. LM finetuning) and for realistic optimizers (e.g. AdamW) at a cost that scales linearly in the total number of training events. Empirically, our influence measure accurately predicts the true effect of ablating specific events during RL, while traditional methods fail to do so. Further, we show that this influence accurately identifies helpful and harmful RL training events, allowing us to improve performance via influence-weighted retraining. Overall, we show that accounting for policy-data interaction is both necessary and tractable, allowing for principled training intervention in modern RL pipelines.
BibTeX
@inproceedings{gould2026policy,
  author = {Rhys Gould and Yaowen Ye and Stuart Russell and Jacob Steinhardt},
  title = {{On-Policy Counterfactual Influence}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=uca0HSKmnM},
}
Figure