Skip to content

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.

Learning objectives

  • Separate behavior, target, old, and reference policies.
  • Explain why online data is not necessarily on-policy.
  • Recognize support mismatch and importance-weight variance.
NameRoleChanges when
Behavior policy μ\muActually generates recorded actionsA rollout worker receives new weights or its sampling transform changes
Target policy πθ\pi_\thetaPolicy whose performance the learner seeks to improveAn optimizer update changes its parameters
Old policy πold\pi_{\mathrm{old}}Snapshot used to collect a PPO/GRPO rollout batchA new rollout round begins
Reference policy πref\pi_{\mathrm{ref}}Anchor for a regularizerThe 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.

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, πθ(token∣context)\pi_\theta(\text{token} \mid \text{context}). 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.

MethodData comes fromClassCompared against
SFTA fixed dataset of demonstrationsNot RL; the model never samplesThe label
REINFORCEThe current model, used onceOn-policyA running-average baseline
PPOA recent snapshot, reused for a few passesOn-policy with bounded reuseA learned critic
GRPOA recent snapshot, in groups for each promptOn-policy with bounded reuseThe group’s mean reward
RFTThe current model, scored by a graderA name for the whole sample, grade, and update loop; the algorithm underneath is usually PPO-like or GRPO-likeDepends on the implementation
DPOFixed pairs of preferred and rejected outputsOfflineThe rejected output
DQN, SACA replay buffer of old experienceOff-policyLearned 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.

For one state with actions a,ba,b, let μ=[0.8,0.2]\mu=[0.8,0.2], π=[0.4,0.6]\pi=[0.4,0.6], and action rewards [1,3][1,3]. Under μ\mu, an unweighted reward average tends to 1.41.4. The target expectation is 2.22.2. Importance weights π/μ=[0.5,3]\pi/\mu=[0.5,3] recover it:

Ea∼μ[π(a)μ(a)r(a)]=0.8(0.5)(1)+0.2(3)(3)=2.2.\mathbb E_{a\sim\mu}\left[\frac{\pi(a)}{\mu(a)}r(a)\right] =0.8(0.5)(1)+0.2(3)(3)=2.2.

If μ(b)=0\mu(b)=0 but π(b)>0\pi(b)>0, no recorded sample can tell us the reward of bb. 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 w1,…,wnw_1,\ldots,w_n, the diagnostic effective sample size is

ESS=(∑iwi)2∑iwi2.\mathrm{ESS}=\frac{(\sum_i w_i)^2}{\sum_i w_i^2}.

Weights [1,1,1,1][1,1,1,1] give ESS 4; [1,1,1,9][1,1,1,9] give 144/84≈1.714144/84\approx1.714. This diagnoses weight concentration, not task quality or a proof of estimator accuracy.

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.

prompt IDs and completion IDs; attention and completion masks
policy revision; tokenizer and chat-template revision
sampling transforms and seed; actual behavior token log probabilities
termination reason: EOS, length cap, tool failure, cancellation
reward components and checker revision; tool observations
collection time; learner revision at consumption

Hold 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.

  • 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.

Data freshness and policy agreement are separate properties. Record behavior probabilities, control lag, and use an estimator designed for the data you actually have.

  1. A worker generates continuously but is 20 learner updates behind. Is that necessarily on-policy?

    AnswerNo. Collection is online, but actions come from a stale behavior policy. Bound lag or use a justified off-policy estimator.
  2. Why does a fixed seed not establish equality between rollout and training probabilities?

    AnswerThe seed controls random draws. Model revisions, tokenization, transforms, precision, and batch-dependent numerical computation can still differ.
  3. The sampler and the trainer load the same weight file. Are they the same policy?

    AnswerOnly 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.
  4. An LLM judge gives the same rollout a different score on a rerun. Does that make training off-policy?

    AnswerNo. 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.
  5. Why can SFT and DPO not have a sampler and trainer mismatch?

    AnswerThey train on fixed data. No sampler generates rollouts during training, so no recorded behavior probability is compared with a trainer probability.

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.