async_rl_loop. You provide dataset rows and a rollout function; the recipe runs rollout production independently from serialized training. When a rollout finishes, the producer immediately tries to refill available capacity—even while forward/backward or optimizer work is running.
Responsibilities
Minimal setup
prompt_token_ids. Fork the single-turn example or multi-turn example for your environment.
Rollout contract
The factory receivesRolloutSetup once and returns an async function:
rollout_fn completions_per_prompt times for each dataset row. One call represents one trajectory and returns:
RolloutRun(segments=[...])on success. A run contains one or moreRolloutSamplesegments from the same trajectory.Noneto drop that trajectory draw.
tokens, logprobs, and loss_mask lists plus a scalar reward. Set the mask to 1 only for tokens that should contribute to training. All segments in one run must have the same reward.
Scheduling controls
These five fields define the rollout/training pipeline:
Admission is row-atomic: the scheduler submits a row only when both the staleness budget and concurrency budget can fit all of its completions.
max_head_offpolicy_versions=0 is fully on-policy: every optimizer batch trains groups from its current published policy version. Chunk training can still overlap remaining rollouts from the same optimizer batch.
Runtime behavior
- The recipe syncs initial policy weights to the sampler.
- The producer submits complete rows while both admission budgets allow it.
- Every completed rollout retries refill. As soon as the first training chunk is ready, serialized trainer work can begin while rollout production continues.
- Later chunks queue and run in order. One optimizer step follows the final chunk.
- The recipe hotloads the updated weights and publishes the next policy version. Publication reopens staleness capacity.
async_rl_loop does not expose a weight-sync interval. Known transient rollout failures are dropped behind a bounded circuit breaker. Invalid rollout data, unexpected cancellation, and unknown errors remain fatal.
Loss behavior
The stock recipe has one direct client-side GRPO path and nopolicy_loss or loss_path selector. anchor_logp="old_policy" (the default) snapshots trainer logprobs and applies TIS against rollout behavior logprobs; anchor_logp="rollout" reuses aligned rollout logprobs and makes the TIS ratio identity. Set kl_beta=0 to disable reference-policy KL and reference provisioning.
Detailed reference
Keep implementation and tuning detail out of the recipe page:- Async RL skill reference — admission math, metrics, tuning, failure policy, and resume semantics
- Custom RL loss reference — fork the recipe deliberately when you need a trainer built-in or another research objective
- Checkpointing — resumable checkpoints and final model promotion
- Weight sync — how updated policy weights reach the sampler
rl_loop— simpler synchronous GRPO when rollout/training overlap is unnecessary