tinker_cookbook.rl.RolloutLoop
Generated from tinker-cookbook at commit 4fa3ab8. Source links point at that snapshot.
class tinker_cookbook.rl.RolloutLoop(ABC)
Runs one group of rollouts against a policy and returns a TrajectoryGroup.
This is the unit of rollout work that RLDataset hands to the training
and evaluation loops. There are two ways to implement it:
-
Subclass
EnvGroupBuilderwhen episodes are step-by-step PythonEnvinstances. It implementsrunfrommake_envs()andcompute_group_rewards(). -
Subclass
RolloutLoopdirectly when something else drives the whole multi-turn episode loop and the grading, such as a sandboxed coding agent or an external rollout server.
Picklability: Implementations must be pickleable (via standard pickle) to support
distributed rollout execution where rollout loops are serialized and sent to remote
workers. Avoid storing live network connections, file handles, or other unpickleable
objects as fields. Store configuration strings (URLs, model names, task paths) and
construct heavy clients lazily inside run().
run(policy)
Run all rollouts for this group against policy and return the graded group.
Called by ~tinker_cookbook.rl.rollouts.do_group_rollout, which then
logs the trajectories and calls cleanup. The returned
TrajectoryGroup must have equal-length trajectories_G,
final_rewards_G, and metrics_G lists. Per-trajectory rewards may
be placed on transition reward fields, in final_rewards_G, or both
(TrajectoryGroup.get_total_rewards sums them).
The implementation owns everything about how the group is produced:
episodes, retries, grading, and how trajectories that stopped on a limit
are rewarded. Failures it tolerates can be recorded on
TrajectoryGroup.rollout_errors; they are reported to
~tinker_cookbook.rl.rollouts.RolloutErrorCounter. An exception
raised here is a group-level error: it fails the run, or skips the group
when the caller sets catch_group_errors.
Parameters:
- policy (TokenCompleter) – The token-level policy for this rollout group (in training and eval loops, a
~tinker_cookbook.completers.TinkerTokenCompleter).
Returns: TrajectoryGroup – The completed trajectories, final group rewards, per-trajectory metrics, and any captured rollout errors.
Abstract method.
cleanup()
Clean up resources allocated during run.
Called after the group rollout finishes, regardless of success, failure, or task cancellation. Override this to release expensive resources like cloud sandboxes, remote browsers, etc.
Default is a no-op. Implementations should be idempotent (safe to
call multiple times) and handle exceptions internally, as do_group_rollout
does not catch exceptions from this method.
Returns: None
logging_tags()
Return tags used to aggregate metrics in training logs.
Tags let the training loop group metrics (rewards, episode lengths, etc.) by environment type. Return a short list of names at different levels of granularity.
Returns: list[str] – Tag strings for this rollout group. Default is an empty list.