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.
For the shared serverless pool, use the experimental
async_rl_loop_serverless adapter.
It keeps this recipe’s rollout and scheduling contract but replaces dedicated
resource lifecycle and hotloading with session-scoped snapshots. The two paths
remain separate until they share one weight-publication contract. See
Serverless Training for lifecycle and
limits.
Responsibilities
Minimal setup
prompt_token_ids. Fork the
single-turn example
for a minimal adapter. For multi-turn harnesses, tools, sandboxes, and exact
token ancestry, read
Cookbook: Agentic Reinforcement Learning.
Agentic RL changes the rollout adapter, not this async scheduling and training
contract.
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 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_concurrency_rollout_sample counts active rollout_fn calls, not the
individual inference requests that a multi-turn agent makes. The shared
DeploymentSampler owns inference-request concurrency separately.
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 waits for evaluation on the current sampler version before replacing that version, hotloads the updated weights, and publishes the next policy version. Publication reopens staleness capacity.
async_rl_loop does not
expose a weight-sync interval. The final partial optimizer batch is trained
rather than discarded. Known transient rollout failures are dropped behind a
bounded circuit breaker. Invalid rollout data, unexpected cancellation, and
unknown errors remain fatal. A row may still train after recoverable failures
when at least min_group_size runs survive.
Loss behavior
The default path computes GRPO in the client and does not expose a generalpolicy_loss or loss_path selector. Dedicated async RL can opt into the
trainer’s built-in PPO kernel with server_side_grpo=True; this changes only
where the GRPO policy update executes, requires kl_beta=0, and is not a
different algorithm. 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.
Evaluation
Passevaluation_fn(step, rollout_fn) and evaluation_interval=N to main().
Evaluation runs at the initial or resumed step, at each interval, and once at
the actual final step without duplicating a periodic evaluation at that step.
It uses the same rollout object, sampler, max_completion_tokens, and resolved
max_seq_len as training, but it does not enter training groups or mutate the
optimizer. Evaluation is fail-open. It can overlap the next batch’s rollout and
trainer work, but it must finish before that sampler version is replaced, so a
slow evaluation can delay weight publication.
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
- Agentic RL skill reference — multi-turn token ancestry, session/cache architectures, mismatch policies, and trace failures
- 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
IGPO (Information Gain Policy Optimization)
Theigpo_loop recipe extends the async RL pipeline with turn-level information-gain rewards for multi-turn agent trajectories. Start from Cookbook RL for the core rollout and weight-sync lifecycle, then switch to igpo_loop when your reward depends on per-turn information gain rather than a single scalar at episode end.