# Async RL Asynchronous (async) RL overlaps sampling with training to save wall-clock time. In synchronous (sync) RL, each step samples a batch, waits for its slowest rollout, and then trains, so sampling and training take turns sitting idle. In async RL, the trainer trains on finished rollouts while new ones keep sampling. Because sampling runs ahead, the trainer often trains on stale rollouts, sampled by weights from several steps earlier. Letting sampling run further ahead raises throughput but also staleness, and you set this tradeoff with [`sampling_steps_ahead`](#choose-how-far-ahead-to-sample). Stale data can make RL training unstable, so by default the cookbook handles it in two ways: [in-flight weight updates](#in-flight-weight-updates) keep rollouts fresher, and [StableReinforce](#stablereinforce), the default loss, is built to stay stable on off-policy data. ## How async RL works ![Timelines of the same nine rollouts trained in three steps, on one time axis: sync, async, and async with in-flight weight updates. In sync, rollouts and the trainer take turns waiting, so it finishes last. Both async panels have identical timing and finish sooner, with training steps overlapping rollouts. With in-flight updates, running rollouts change weight version at each step.](../images/async/timeline-light.svg#only-light) **Figure 1. Sync and async training schedules.** Figure 1 runs the same rollouts through both schedules. Sync finishes last, because each batch waits for its slowest rollout and then for the step to train. In async RL, sampling keeps going while the trainer trains, and each training step takes the next batch of finished rollouts. After each step, the trainer publishes new weights for the rollouts that start afterwards. How much time this saves depends mostly on how uneven rollout lengths are and how long training takes compared with sampling. Sampling can't run arbitrarily far ahead: [`sampling_steps_ahead`](#choose-how-far-ahead-to-sample) caps how many groups (the rollouts for one prompt) can be sampling or waiting to be trained at once. Most groups end up about that many steps stale, but it isn't a hard limit, since a long rollout can finish many steps after it started. ## Training on stale data ### In-flight weight updates With in-flight weight updates, rollouts that are still generating switch to each step's new weights as they propagate, instead of finishing on the weights they started with. Long responses benefit most, since more steps pass while they generate. The cookbook does this with Tinker's [inflight sampling](https://tinker-docs.thinkingmachines.ai/tinker/howto/inflight_sampling/index.md), saving each step's weights with [`save_weights_and_get_sampling_client(kind="inflight")`](https://tinker-docs.thinkingmachines.ai/tinker/api-reference/trainingclient/#save_weights_and_get_sampling_client). They're on by default; to keep each rollout on its starting weights, set `inflight_weight_updates=False`. Evals are unaffected: each one samples from a [snapshot](https://tinker-docs.thinkingmachines.ai/tinker/howto/inflight_sampling/index.md) of its step's weights, so it measures one fixed policy. ### StableReinforce Even with in-flight updates, most groups were sampled by an older policy than the one being trained, and the two drift further apart as staleness grows. Common RL losses such as [importance sampling](https://tinker-docs.thinkingmachines.ai/tinker/losses/importance-sampling/index.md), [PPO](https://tinker-docs.thinkingmachines.ai/tinker/losses/ppo/index.md) and [CISPO](https://tinker-docs.thinkingmachines.ai/tinker/losses/cispo/index.md) correct for this gap with a per-token ratio between the two policies, computed from the logprobs returned at sampling time. This works well when the policies are close, but gets harder to keep stable as they drift apart. [StableReinforce](https://tinker-docs.thinkingmachines.ai/tinker/losses/stable-reinforce/index.md) (`stable_reinforce`), the default loss for async runs, is a REINFORCE variant built to stay stable when the two policies are far apart. Besides the sampled logprobs, it uses information Tinker records at sampling time. In our internal post-training, it has stayed stable even when async RL runs far off-policy. The loss also includes a KL term between the sampler and the learner, which you can tune through `loss_fn_config` (see the [StableReinforce page](https://tinker-docs.thinkingmachines.ai/tinker/losses/stable-reinforce/#samplerlearner-kl)). A stable loss doesn't make stale data as useful as fresh data. Groups sampled many steps ago say less about the current policy, so sampling far ahead can slow learning per step. Even so, the cookbook never drops groups for being stale: the stalest are usually the longest responses, so dropping them would bias training toward short ones. ## Set up async training ### Configure AsyncConfig Async training is off unless you pass an [`AsyncConfig`](https://tinker-docs.thinkingmachines.ai/cookbook/api-reference/rl/asyncconfig/index.md) to the RL [`Config`](https://tinker-docs.thinkingmachines.ai/cookbook/api-reference/rl/config/index.md): ```python from tinker_cookbook.rl.train import AsyncConfig, Config config = Config( ..., # Train 32 groups per step, with sampling running up to 2 steps ahead. async_config=AsyncConfig(groups_per_batch=32, sampling_steps_ahead=2), ) ``` [`groups_per_batch`](https://tinker-docs.thinkingmachines.ai/cookbook/api-reference/rl/asyncconfig/index.md) is the number of groups each step trains, usually your dataset's batch size. [`sampling_steps_ahead`](https://tinker-docs.thinkingmachines.ai/cookbook/api-reference/rl/asyncconfig/index.md) is how many steps sampling may run ahead of training, where 0 means on-policy. It replaces `max_steps_off_policy`, which still works but is deprecated. The loss comes from `AsyncConfig.loss_fn` (default `stable_reinforce`), not `Config.loss_fn`. The [API reference](https://tinker-docs.thinkingmachines.ai/cookbook/api-reference/rl/asyncconfig/index.md) lists every field and its default. The `math_rl`, `code_rl`, `rubric` and `harbor_rl` recipes take `sampling_steps_ahead` as a flag. This runs math RL with sampling up to two steps ahead: ```bash python -m tinker_cookbook.recipes.math_rl.train env=math \ model_name="Qwen/Qwen3.5-9B" renderer_name=qwen3_5_disable_thinking \ max_tokens=2048 group_size=16 groups_per_batch=64 learning_rate=2e-5 \ sampling_steps_ahead=2 ``` ### Choose how far ahead to sample `sampling_steps_ahead` works through a buffer of groups that sampling and training share. A group takes a slot when its rollouts start and frees it once it's trained, and the buffer holds `sampling_steps_ahead + 1` steps' worth of groups (Figure 2). Groups dropped after rollout errors (with a tolerant [`rollout_error_tolerance`](#hung-rollouts-and-resuming)) or filtered out by `remove_constant_reward_groups=True` don't count toward a step, which waits until it has `groups_per_batch` groups. ![A row of 12 buffer slots: 4 groups in the current training step, 3 finished groups waiting, and 5 groups still sampling. Trained groups free their slots on the left, and a new group waits for a free slot on the right.](../images/async/buffer-light.svg#only-light) **Figure 2. The group buffer.** Since new groups take freed slots right away, the buffer stays full, and most groups are about `sampling_steps_ahead` steps stale by the time they're trained (Figure 3, from the [example runs](#example)). Groups come out fresher early in a run, before sampling gets ahead, and whenever the trainer is waiting on rollouts. ![Share of trained groups by staleness with sampling 1, 2, 4 and 8 steps ahead.](../images/async/staleness-by-k-light.svg#only-light) **Figure 3. Staleness of trained groups.** How far ahead to sample trades speed for staleness. Speed improves as `sampling_steps_ahead` grows, until slow rollouts no longer hold up training; past that point, running further ahead only adds staleness. Workloads with long or uneven rollouts, such as multi-turn agents or long reasoning, gain the most. `sampling_steps_ahead=2` is a reasonable default. In the [example](#example), it ran about 5× as many steps per hour as sync, with held-out accuracy matching sync. To tune it for your workload, try a few values on short runs of about 20 steps and compare wall-clock time per step. Pick the smallest value that gets most of the speedup, then check on a longer run that [held-out evals](#monitor-a-run) keep up with a lower value. Two limits also apply. At the start of a run, `(sampling_steps_ahead + 1) × groups_per_batch` groups begin before the first update, so for short runs where that's a large share of the dataset, use a smaller value. And up to `(sampling_steps_ahead + 1) × groups_per_batch × group_size` rollouts run at once, so size sandbox pools and executors for that ([API reference](https://tinker-docs.thinkingmachines.ai/cookbook/api-reference/rl/asyncconfig/index.md)). ### Hung rollouts and resuming A hung rollout keeps its buffer slot, so enough of them will stall training. If your environment can hang, set `rollout_error_tolerance` to a [`RetryOnFailure`](https://tinker-docs.thinkingmachines.ai/cookbook/api-reference/rl/retryonfailure/index.md) with a `per_rollout_timeout`. Don't add your own timeouts around Tinker calls, since the SDK already handles slow requests. To resume a run, rerun it with the same `log_path`. Training picks up from the last checkpoint, but rollouts in flight are lost, so a few prompts near the resume point can be trained twice or skipped. ## Monitor a run The cookbook logs training metrics to `metrics.jsonl` in your `log_path`, and to [Weights & Biases](https://docs.wandb.ai/quickstart/) when you set `wandb_project` (and optionally `wandb_name`) in your `Config`. A name ending in `*` stands for a family of metrics, such as `async/staleness_min`, `async/staleness_mean` and `async/staleness_max`. - `async/staleness_*` is the age, in training steps, of the weights that sampled each trained group. With in-flight updates it counts the oldest weights, so it overstates staleness for later tokens ([details](https://tinker-docs.thinkingmachines.ai/cookbook/rl/rl-logging/#async-metrics)). - `optim/kl_sample_train_*` estimates the KL between the sampling and training policies on the trained tokens ([details](https://tinker-docs.thinkingmachines.ai/cookbook/rl/rl-logging/#metricsjsonl)). A high or growing value means the data is far off-policy. Track progress with held-out evals (`eval_every`) rather than training reward. Training reward comes from rollouts sampled by older weights, so it lags behind the current policy. ## Example: sync vs. async on code RL We compared sync training with async sampling one, two, four and eight steps ahead on the same code RL setup. We trained Qwen3.5-4B with LoRA (rank 32) on [DeepCoder](https://huggingface.co/datasets/agentica-org/DeepCoder-Preview-Dataset) code problems and graded responses by running the tests in a sandbox. Each step trains on 16 groups of 16 samples with `stable_reinforce` and a learning rate of 4e-5. Thinking is off and responses are capped at 16K tokens. We timed each setting on its own with evals off, and measured accuracy with separate 60-step runs on 256 held-out problems. Async ran 3–8× faster than sync, with most of the gain reached by four steps ahead. With one or two steps, held-out accuracy matched sync. With four or eight, it trailed by a couple of points (Figure 4). ![Wall-clock time per training step and held-out pass@1 per training step for sync training and async training with sampling 1, 2, 4 and 8 steps ahead.](../images/async/speed-accuracy-light.svg#only-light) **Figure 4. Speed and held-out accuracy, sync vs. async.** Left: wall-clock time for the first 20 training steps. Right: held-out pass@1 on DeepCoder, averaged over two seeds. ## Related docs - [`AsyncConfig` API reference](https://tinker-docs.thinkingmachines.ai/cookbook/api-reference/rl/asyncconfig/index.md) - [StableReinforce](https://tinker-docs.thinkingmachines.ai/tinker/losses/stable-reinforce/index.md) - [Inflight sampling](https://tinker-docs.thinkingmachines.ai/tinker/howto/inflight_sampling/index.md) - [RL Training Outputs](https://tinker-docs.thinkingmachines.ai/cookbook/rl/rl-logging/index.md)