Optimize Rollout Sampling
Treat rollout work as distribution design, selection, and estimation—not as a single temperature knob.
Start with the right unit
State the sampling unit before proposing an algorithm:
- Token: one vocabulary item inside a model call.
- Reasoning/action step: a thought chunk, tool call, or environment action.
- Trajectory: the complete sequence from prompt to terminal outcome.
- Population: a set of trajectories used for voting, ranking, resampling, or a policy update.
Do not call step-local temperature scaling “trajectory-level power sampling.” Read references/taxonomy.md whenever power sampling, importance sampling, SMC, or off-policy correction is involved.
Run the design workflow
1. Formalize the target
Write down:
- Base/behavior distribution
p(τ|x) or μ(τ|x).
- Desired target distribution or decision rule.
- Available signal: none, answer agreement, outcome verifier, process score, environment reward, or human preference.
- Access: text-only API, token log-probabilities, full logits, model weights, environment snapshots, or a world model.
- Budget: model calls, generated tokens, wall time, verifier calls, and environment interactions.
- Goal: maximize single returned answer, coverage/pass@k, expected reward, training signal quality, diversity, or unbiased evaluation.
Keep these goals separate. A sampler that improves oracle coverage can worsen pass@1; a selector that improves measured reward can overfit the verifier; a biased low-variance estimator can be useful for optimization but invalid for evaluation.
2. Select the smallest adequate method
| Conditions |
Start with |
Escalate to |
| No verifier, text-only API |
IID repeated sampling + answer canonicalization + self-consistency |
Universal self-consistency or sample-based MBR for free-form outputs |
| Outcome verifier only |
Best-of-N with honest held-out evaluation |
Rejection sampling, reward-proportional resampling, or QAlign/MCMC when BoN over-optimizes the verifier |
| Reliable process score |
Stepwise beam search or DVTS |
ToT/MCTS/SMC when early allocation and backtracking matter |
| Full sequence log-probability, no verifier |
Sequence-level power sampling experiment |
Autoregressive MCMC; use SMC only with a principled twist/lookahead |
| Off-policy training rollouts |
Log behavior probabilities and policy versions |
Token/turn/prefix/sequence IS chosen to match the objective; clip only with bias recorded |
| Interactive agent with replayable state |
Whole-trajectory BoN baseline |
Branch at restorable states; use shallow lookahead before full tree search |
| Interactive agent without state restore |
Independent full trajectories |
Do not branch a mutable environment; add snapshots, deterministic replay, or a world model first |
Prefer a baseline ladder: greedy/pass@1 → IID repeated sampling/pass@k → self-consistency or BoN → stepwise search → MCMC/SMC or adaptive tree search. Add a more complex method only when the previous rung exposes a specific limitation.
3. Build a matched-budget experiment
Always compare methods at matched cost. Record at least:
- prompt/task ID, seed, policy/model version, sampler configuration;
- full trajectory or a stable hash, terminal status, reward/correctness;
- generated tokens, wall time, model calls, verifier calls, tool/environment calls;
- behavior log-probability and target log-probability when using IS;
- selected candidate and the rule that selected it.
Use references/protocols.md for experiment grids, agent-state branching, and reporting. Use scripts/analyze_rollouts.py on JSONL logs. Run scripts/power_vs_temperature.py when explaining or checking sequence power.
4. Diagnose before concluding
Report all of the following when available:
- pass@1 and the unbiased pass@k estimator;
- oracle@N separately from selected-answer accuracy;
- majority/self-consistency and Best-of-N accuracy;
- unique-answer and unique-trajectory rates;
- reward-score calibration and reward hacking indicators;
- mean/median tokens, model calls, verifier calls, wall time, and environment calls;
- IS effective sample size (ESS), maximum weight, clipping rate, and estimator type;
- mean across task IDs with task-level bootstrap intervals, not a confidence interval over correlated rollouts.
5. Produce an actionable answer
Return these sections unless the user asks for another format:
- Formal objective and access assumptions
- Recommended sampler and why
- Minimal baseline and ablation grid
- Implementation sketch tied to an actual framework
- Metrics, failure criteria, and expected cost
- What the result would and would not prove
For literature reviews, read references/papers.md. For implementation work, also read references/code-notes.md.
Enforce the non-negotiable checks
- Distinguish
q_seq(τ) ∝ p(τ)^α from token-local ancestral sampling at temperature 1/α; prefix normalizers generally make them different.
- Distinguish sampling from reweighting. Importance sampling estimates an expectation under a target distribution; it does not itself produce independent target samples.
- Require target support to be contained in proposal support before using IS. Treat missing behavior log-probabilities as a blocker for exact IS.
- Compute products and weights in log space. Report ESS and weight concentration; never hide them behind a clipped estimate.
- Do not reuse a verifier for search and call its score an unbiased final evaluation. Evaluate with rules, tests, humans, or a separately trained held-out judge.
- Do not average pass@k over tasks with fewer than
k samples without explicitly reporting the reduced task set.
- Keep trajectory length normalization explicit. Sum log-probabilities corresponds to sequence probability; mean log-probability changes the target and introduces a different length preference.
- In agent trees, restore both textual context and environment state at every branch. Replaying only the transcript is insufficient for a stochastic or stateful environment.
- Treat correlated branches, shared prefixes, resampled particles, and repeated revisions as non-IID. Do not use the IID pass@k interpretation for them.
- Separate the rollout policy used to collect training data from the inference policy. Record policy lag and the granularity of any correction.
Use the bundled tools
Analyze rollout logs:
python scripts/analyze_rollouts.py rollouts.jsonl --k 1,2,4,8 --power-alpha 2
Expected core fields are prompt_id plus one or more of correct, reward, answer, score, base_logp, behavior_logp, and target_logp. See references/protocols.md for the schema.
Demonstrate the power/temperature distinction:
python scripts/power_vs_temperature.py --alpha 2
Keep the review current
Treat references/papers.md as a curated map through 2026-08-25, not a claim of literal exhaustiveness. For a new review, search forward from the canonical works, prefer primary papers and official repositories, record the search cutoff, and label unreviewed or unofficial code clearly.
1---2name: optimize-rollout-sampling3description: Design, audit, implement, and evaluate sampling strategies for LLM reasoning and interactive-agent rollouts. Use for rollout sampling, trajectory sampling, inference-time scaling, temperature/top-k/top-p/min-p, repeated sampling, pass@k, self-consistency, Best-of-N, verifier-guided search, beam/ToT/MCTS/DVTS, power sampling, MCMC/SMC, rejection sampling, importance sampling, off-policy correction, GRPO/PPO rollout design, rollout diversity, and train-time trajectory selection.4---56# Optimize Rollout Sampling78Treat rollout work as distribution design, selection, and estimation—not as a single `temperature` knob.910## Start with the right unit1112State the sampling unit before proposing an algorithm:1314- **Token**: one vocabulary item inside a model call.15- **Reasoning/action step**: a thought chunk, tool call, or environment action.16- **Trajectory**: the complete sequence from prompt to terminal outcome.17- **Population**: a set of trajectories used for voting, ranking, resampling, or a policy update.1819Do not call step-local temperature scaling “trajectory-level power sampling.” Read [references/taxonomy.md](references/taxonomy.md) whenever power sampling, importance sampling, SMC, or off-policy correction is involved.2021## Run the design workflow2223### 1. Formalize the target2425Write down:26271. Base/behavior distribution `p(τ|x)` or `μ(τ|x)`.282. Desired target distribution or decision rule.293. Available signal: none, answer agreement, outcome verifier, process score, environment reward, or human preference.304. Access: text-only API, token log-probabilities, full logits, model weights, environment snapshots, or a world model.315. Budget: model calls, generated tokens, wall time, verifier calls, and environment interactions.326. Goal: maximize single returned answer, coverage/pass@k, expected reward, training signal quality, diversity, or unbiased evaluation.3334Keep these goals separate. A sampler that improves oracle coverage can worsen pass@1; a selector that improves measured reward can overfit the verifier; a biased low-variance estimator can be useful for optimization but invalid for evaluation.3536### 2. Select the smallest adequate method3738| Conditions | Start with | Escalate to |39| --- | --- | --- |40| No verifier, text-only API | IID repeated sampling + answer canonicalization + self-consistency | Universal self-consistency or sample-based MBR for free-form outputs |41| Outcome verifier only | Best-of-N with honest held-out evaluation | Rejection sampling, reward-proportional resampling, or QAlign/MCMC when BoN over-optimizes the verifier |42| Reliable process score | Stepwise beam search or DVTS | ToT/MCTS/SMC when early allocation and backtracking matter |43| Full sequence log-probability, no verifier | Sequence-level power sampling experiment | Autoregressive MCMC; use SMC only with a principled twist/lookahead |44| Off-policy training rollouts | Log behavior probabilities and policy versions | Token/turn/prefix/sequence IS chosen to match the objective; clip only with bias recorded |45| Interactive agent with replayable state | Whole-trajectory BoN baseline | Branch at restorable states; use shallow lookahead before full tree search |46| Interactive agent without state restore | Independent full trajectories | Do not branch a mutable environment; add snapshots, deterministic replay, or a world model first |4748Prefer a baseline ladder: greedy/pass@1 → IID repeated sampling/pass@k → self-consistency or BoN → stepwise search → MCMC/SMC or adaptive tree search. Add a more complex method only when the previous rung exposes a specific limitation.4950### 3. Build a matched-budget experiment5152Always compare methods at matched cost. Record at least:5354- prompt/task ID, seed, policy/model version, sampler configuration;55- full trajectory or a stable hash, terminal status, reward/correctness;56- generated tokens, wall time, model calls, verifier calls, tool/environment calls;57- behavior log-probability and target log-probability when using IS;58- selected candidate and the rule that selected it.5960Use [references/protocols.md](references/protocols.md) for experiment grids, agent-state branching, and reporting. Use [scripts/analyze_rollouts.py](scripts/analyze_rollouts.py) on JSONL logs. Run [scripts/power_vs_temperature.py](scripts/power_vs_temperature.py) when explaining or checking sequence power.6162### 4. Diagnose before concluding6364Report all of the following when available:6566- pass@1 and the unbiased pass@k estimator;67- oracle@N separately from selected-answer accuracy;68- majority/self-consistency and Best-of-N accuracy;69- unique-answer and unique-trajectory rates;70- reward-score calibration and reward hacking indicators;71- mean/median tokens, model calls, verifier calls, wall time, and environment calls;72- IS effective sample size (ESS), maximum weight, clipping rate, and estimator type;73- mean across task IDs with task-level bootstrap intervals, not a confidence interval over correlated rollouts.7475### 5. Produce an actionable answer7677Return these sections unless the user asks for another format:78791. **Formal objective and access assumptions**802. **Recommended sampler and why**813. **Minimal baseline and ablation grid**824. **Implementation sketch tied to an actual framework**835. **Metrics, failure criteria, and expected cost**846. **What the result would and would not prove**8586For literature reviews, read [references/papers.md](references/papers.md). For implementation work, also read [references/code-notes.md](references/code-notes.md).8788## Enforce the non-negotiable checks8990- Distinguish `q_seq(τ) ∝ p(τ)^α` from token-local ancestral sampling at temperature `1/α`; prefix normalizers generally make them different.91- Distinguish sampling from reweighting. Importance sampling estimates an expectation under a target distribution; it does not itself produce independent target samples.92- Require target support to be contained in proposal support before using IS. Treat missing behavior log-probabilities as a blocker for exact IS.93- Compute products and weights in log space. Report ESS and weight concentration; never hide them behind a clipped estimate.94- Do not reuse a verifier for search and call its score an unbiased final evaluation. Evaluate with rules, tests, humans, or a separately trained held-out judge.95- Do not average pass@k over tasks with fewer than `k` samples without explicitly reporting the reduced task set.96- Keep trajectory length normalization explicit. Sum log-probabilities corresponds to sequence probability; mean log-probability changes the target and introduces a different length preference.97- In agent trees, restore both textual context and environment state at every branch. Replaying only the transcript is insufficient for a stochastic or stateful environment.98- Treat correlated branches, shared prefixes, resampled particles, and repeated revisions as non-IID. Do not use the IID pass@k interpretation for them.99- Separate the rollout policy used to collect training data from the inference policy. Record policy lag and the granularity of any correction.100101## Use the bundled tools102103Analyze rollout logs:104105```bash106python scripts/analyze_rollouts.py rollouts.jsonl --k 1,2,4,8 --power-alpha 2107```108109Expected core fields are `prompt_id` plus one or more of `correct`, `reward`, `answer`, `score`, `base_logp`, `behavior_logp`, and `target_logp`. See [references/protocols.md](references/protocols.md) for the schema.110111Demonstrate the power/temperature distinction:112113```bash114python scripts/power_vs_temperature.py --alpha 2115```116117## Keep the review current118119Treat [references/papers.md](references/papers.md) as a curated map through 2026-08-25, not a claim of literal exhaustiveness. For a new review, search forward from the canonical works, prefer primary papers and official repositories, record the search cutoff, and label unreviewed or unofficial code clearly.