tinker_cookbook.rl.AsyncConfig
Generated from tinker-cookbook at commit 8bf7dd6. Source links point at that snapshot.
class tinker_cookbook.rl.AsyncConfig()
Configuration for async RL training.
In async mode, sampling and training run concurrently, so training data
can come from older weights ("stale" or off-policy data). Sampling can run
up to sampling_steps_ahead steps ahead of training: at most
groups_per_step * (sampling_steps_ahead + 1) trajectory groups (each of
group_size trajectories) may be started but not yet trained, counting
both groups still being sampled and finished groups waiting to be trained.
A group takes one of these buffer slots when its rollout starts and frees
it once it has been trained (or right away if it is filtered out). Each
step trains the oldest groups_per_batch completed groups, taking the
groups sampled from the oldest weights first. With streaming minibatches,
a step trains StreamMinibatchConfig.groups_per_batch groups instead, in
the order they finish. Here and below, groups_per_step means whichever
of the two applies.
Nothing is discarded for staleness: while training continues, a slow
rollout is trained when it finishes, however many steps stale it is by
then. (Filtered groups are not trained, and rollouts still running when
training ends are cancelled.) sampling_steps_ahead bounds how far
sampling can run ahead, not staleness itself. While the buffer stays full,
typical staleness is about sampling_steps_ahead steps, but slow
rollouts make an unbounded tail; async/staleness_* logs the actual
values. sampling_steps_ahead=0 is on-policy (staleness 0).
Training steps don't map one-to-one to dataset batches: each step trains
groups_per_batch groups that survive filtering (such as
remove_constant_reward_groups) and rollout errors, wherever they came
from. Training ends after max_steps steps or when the dataset runs out,
whichever comes first; in the second case the remaining groups are trained
as a final, smaller step and a warning reports how many steps ran.
Async runs train with loss_fn, not Config.loss_fn. Its default,
stable_reinforce, stays stable on off-policy data. With another loss,
prefer a clipped one such as ppo: importance_sampling can become
unstable on stale data.
A rollout that never finishes keeps its buffer slot: training stalls once
more than groups_per_step * sampling_steps_ahead groups hang (with
sampling_steps_ahead=0, as in sync training, a single one), and the
run can't finish while a rollout whose group is still needed hangs. For environments that can hang, set
rollout_error_tolerance=RetryOnFailure(per_rollout_timeout=...).
Rollouts still running when training ends are cancelled (their env
cleanup still finishes), except those in a rollout executor's threads or
processes, which run to completion. Up to
groups_per_step * (sampling_steps_ahead + 1) * group_size trajectories
run at once, so size a rollout executor (and any sandbox pool) for that
many.
Every eval_every step and the final step are evaluated on that step's
weights. Evals run alongside training and each other, and never skip a
step, so with evals slower than eval_every steps, several run at once.
Evaluators must therefore be safe to call concurrently:
RLTestSetEvaluator gives each call its own copies of its env group
builders, and Inspect evals take turns.
With inflight_weight_updates (see
https://tinker-docs.thinkingmachines.ai/tinker/howto/inflight_sampling/), a
rollout's tokens can come from several weight versions; each group is
attributed to the oldest, so async/staleness_*, sampling_client/step_*
and optim/kl_sample_train_* are bounds or mixtures. It costs one extra
sampler save on each periodic-checkpoint step and one on each evaluated step
(evals run on a snapshot of that step's weights).
Fields:
- groups_per_batch (int)
- sampling_steps_ahead (int | None, default:
None) - max_steps_off_policy (int | None, default:
None) - loss_fn (LossFnType, default:
'stable_reinforce') - inflight_weight_updates (bool, default:
True)
steps_ahead()
sampling_steps_ahead, or the deprecated max_steps_off_policy
when that is the one set.
Returns: int