18.5 On-policy, off-policy, offline, and online learning
A rollout is evidence from a particular policy. Before using it in an update, identify the policy that sampled its actions, the policy being optimized, and the distribution of prompts or states. These distinctions determine whether the estimator is valid and whether old experience can be reused.
Concepts from other sections (10)
This section uses these ideas. Each has a short definition and a link to the section that explains it in full. Tap a dotted term in the text to preview it.
- On-policy / off-policy: learning about the policy being followed versus learning about a different policy. Read more: 4.4 World models, multiple agents, and RLHF
- Variance: the expected squared distance from the mean; its square root is the standard deviation. Read more: 13.1 Random variables, expectation, variance, and normal draws by Box-Muller in Mathematics
- PPO: a policy gradient method that clips the new-to-old probability ratio to keep updates small. Read more: 4.4 World models, multiple agents, and RLHF
- GRPO: a PPO-style RL method that replaces the critic with the group-normalized reward of several samples of the same prompt. Read more: 19.7 The training step and validation
- reference policy: the frozen model (usually the SFT checkpoint) against which the policy’s log-ratios are measured. Read more: 18.2 Direct preference optimization and IPO
- DPO: minimizing over preference pairs, equivalent to fitting the KL-regularized reward objective. Read more: 18.2 Direct preference optimization and IPO
- Top-p (nucleus): the smallest set of most likely tokens whose mass reaches , including the crossing token. Read more: 21.1 Sampling and logit processors
- Reinforcement fine-tuning (RFT): tuning a model against an evaluator that returns a reward from 0 to 1 for each output, with gold completions optional; it fits tasks that are verifiable but lack reference answers. Read more: 24.5 Routing implementations and selection
- Regularization: penalizing model complexity to trade bias for lower variance. Read more: Chapter 1: Statistical Learning
- LLM judge: a language model used as a scorer, treated as a noisy instrument whose malformed replies are missing readings. Read more: 29.3 LLM judge with position control
Learning objectives
Name the distributions
Section titled “Name the distributions”| Name | Role | Changes when |
|---|---|---|
| Behavior policy | Actually generates recorded actions | A rollout worker receives new weights or its sampling transform changes |
| Target policy | Policy whose performance the learner seeks to improve | An optimizer update changes its parameters |
| Old policy | Snapshot used to collect a PPO/GRPO rollout batch | A new rollout round begins |
| Reference policy | Anchor for a regularizer | The recipe explicitly refreshes it; commonly frozen after SFT |
On-policy methods collect fresh experience from the policy they are updating. PPO uses a fixed old-policy batch for a limited number of updates, so the target moves away from the behavior during those updates. It is conventionally an on-policy algorithm with bounded batch reuse, rather than a general replay-buffer algorithm.
Off-policy learning updates a target using experience from another behavior policy. Q-learning can learn a greedy target while an exploratory policy collects transitions. A distributed actor can be off-policy relative to the learner simply because its weights are stale.
Offline means learning from an existing fixed dataset without fresh environment interaction. Online means new data is collected during learning. An offline replay dataset is often off-policy; an online asynchronous learner can also be off-policy. DPO is typically an offline preference objective on fixed pairs, not a PPO importance-sampling update. Distillation’s use of “on-policy” concerns whose generated prefixes supply its training states; the KL direction is an independent choice.
The model is the policy
Section titled “The model is the policy”For a language model the state is every token so far, the action is the next token, and the policy is the distribution the system assigns to that token, . Everything that determines the distribution is part of the policy:
- the weights, including any LoRA adapter;
- the sampling transforms, such as temperature and top-p;
- the numerical execution: precision, kernels, and batching.
“Same model” and “same policy” are therefore different claims. A sampler and a trainer can load identical weights and still assign different probabilities to the same token. Training that assumes one policy is then slightly off-policy without anyone having chosen that. Batch invariance and numerical reproducibility works an example.
A noisy reward is a separate problem. A grader that returns different scores for the same rollout adds variance to the advantage, but the behavior policy is unchanged and the data is still on-policy. Diagnose the two separately: rerun the grader on fixed rollouts to measure reward noise, and rescore fixed tokens in both engines to measure policy mismatch.
Where the common methods sit
Section titled “Where the common methods sit”| Method | Data comes from | Class | Compared against |
|---|---|---|---|
| SFT | A fixed dataset of demonstrations | Not RL; the model never samples | The label |
| REINFORCE | The current model, used once | On-policy | A running-average baseline |
| PPO | A recent snapshot, reused for a few passes | On-policy with bounded reuse | A learned critic |
| GRPO | A recent snapshot, in groups for each prompt | On-policy with bounded reuse | The group’s mean reward |
| RFT | The current model, scored by a grader | A name for the whole sample, grade, and update loop; the algorithm underneath is usually PPO-like or GRPO-like | Depends on the implementation |
| DPO | Fixed pairs of preferred and rejected outputs | Offline | The rejected output |
| DQN, SAC | A replay buffer of old experience | Off-policy | Learned Q-values |
SFT and DPO have no sampler in the training loop, so they cannot suffer a sampler and trainer mismatch. PPO and GRPO are where that mismatch does the most damage, because their ratio divides a trainer probability by a sampler probability.
Work an importance correction
Section titled “Work an importance correction”For one state with actions , let , , and action rewards . Under , an unweighted reward average tends to . The target expectation is . Importance weights recover it:
If but , no recorded sample can tell us the reward of . This is support mismatch; no finite weight can repair absent evidence. Small nonzero behavior probabilities also cause high-variance weights. Weight clipping reduces variance but introduces bias, so report clipping and the distribution of weights.
For weights , the diagnostic effective sample size is
Weights give ESS 4; give . This diagnoses weight concentration, not task quality or a proof of estimator accuracy.
Why trajectories are harder
Section titled “Why trajectories are harder”A trajectory ratio includes a product of action ratios. Products over long outputs can have extreme variance. Token-level PPO ratios are part of a local surrogate using fixed sampled states; they do not by themselves correct arbitrary changes in the full distribution of histories. Off-policy actor-critic algorithms use additional estimators and assumptions. IMPALA’s V-trace is one example designed for actor/learner lag, not a switch that turns any stale PPO buffer into valid data.
For language-model rollouts, record the actual generation contract. Temperature, top-k, top-p, grammar constraints, repetition penalties, speculative verification, and even numerical differences can change the behavior distribution. If generation truncates an action to probability zero, an untruncated learner distribution has a support mismatch. A practical recipe may deliberately use an approximation; name it and measure its effect. Do not silently label raw unfiltered model log probabilities as the actual filtered behavior log probabilities.
A rollout record that supports diagnosis
Section titled “A rollout record that supports diagnosis”prompt IDs and completion IDs; attention and completion maskspolicy revision; tokenizer and chat-template revisionsampling transforms and seed; actual behavior token log probabilitiestermination reason: EOS, length cap, tool failure, cancellationreward components and checker revision; tool observationscollection time; learner revision at consumptionHold old log probabilities fixed during PPO epochs. Recomputing the denominator from the changing learner makes every ratio one and removes the intended correction. A reference policy cannot substitute for the old behavior policy: regularization and importance correction have different jobs.
Key terms
Section titled “Key terms”- Support: the actions or histories with nonzero probability under a distribution.
- Policy lag: the gap between the learner and the policy that produced a rollout.
- Replay: reusing stored experience, subject to the chosen algorithm’s assumptions.
Summary
Section titled “Summary”Data freshness and policy agreement are separate properties. Record behavior probabilities, control lag, and use an estimator designed for the data you actually have.
Review questions
Section titled “Review questions”-
A worker generates continuously but is 20 learner updates behind. Is that necessarily on-policy?
Answer
No. Collection is online, but actions come from a stale behavior policy. Bound lag or use a justified off-policy estimator. -
Why does a fixed seed not establish equality between rollout and training probabilities?
Answer
The seed controls random draws. Model revisions, tokenization, transforms, precision, and batch-dependent numerical computation can still differ. -
The sampler and the trainer load the same weight file. Are they the same policy?
Answer
Only if they assign the same probabilities. Sampling transforms, precision, kernels, batching, and a merged versus unmerged adapter can each change the distribution while the file stays the same. -
An LLM judge gives the same rollout a different score on a rerun. Does that make training off-policy?
Answer
No. It adds noise to the advantage, which raises gradient variance. Off-policy describes a mismatch between the behavior and target policies, and the judge changes neither. -
Why can SFT and DPO not have a sampler and trainer mismatch?
Answer
They train on fixed data. No sampler generates rollouts during training, so no recorded behavior probability is compared with a trainer probability.
Sources and checks
Section titled “Sources and checks”Sutton and Barto, Reinforcement Learning, chapters 5–6 supplies the behavior/target distinction; PPO, section 3 specifies the limited reuse scheme. Recompute the finite-action expectation and ESS with learning checks.