Compare commits

...
Author SHA1 Message Date
halleriteandGitHub 0b583306eb feat(orchestrator): hierarchical GRPO for proposer-solver envs (#3138) 2026-07-30 15:31:13 +02:00
halleriteandGitHub d612e23c1d chore(configs)!: remove every config shim (#3156) 2026-07-30 01:50:01 +02:00
halleriteandGitHub d135ed4c90 feat(orchestrator)!: rename env collections to sources, compose the verifiers config blocks (#3150) 2026-07-30 01:41:54 +02:00
1fd2d732c2 fix: read overview quality metrics from effective subset (#3159)
* fix: read overview quality metrics from effective subset

The all subset counts errored rollouts as zeros for num_branches,
num_turns, num_total_tokens, and is_truncated, which skews the
distributions and makes the panels uninterpretable. Point the wandb
overview panels and the eval success line at the effective subset;
has_error stays on all since effective drops errors by construction.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* fix: reword zero-skew rationale, drop subset guidance from skill

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-29 16:36:13 -07:00
6a9969e61a chore: bump renderers to 0.1.9.dev9 (#3158)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-29 16:06:49 -07:00
1385e0722c fix: compute trainable rate over effective rollouts (#3152)
* fix(orchestrator): compute trainable rate over effective rollouts

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* chore: drop comment

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
2026-07-28 23:52:21 -07:00
74 changed files with 539 additions and 373 deletions
+1 -1
View File
@@ -32,7 +32,7 @@ group_size = 8
[orchestrator.train.sampling]
max_completion_tokens = 768
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "alphabet-sort"
env.taskset = { id = "alphabet-sort-v1", min_turns = 3, max_turns = 5, task = { power_per_turn = false } }
env.agent.harness = { id = "null" }
+1 -1
View File
@@ -19,7 +19,7 @@ batch_size = 128
group_size = 8
seq_len = 8192
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "hendrycks-math"
env.taskset = { id = "math-env-v1", dataset_name = "mikasenghaas/Sanity-Test-R1D-1.5B", dataset_subset = "default" }
env.agent.harness = { id = "null" }
+1 -1
View File
@@ -22,7 +22,7 @@ group_size = 16
[orchestrator.train.sampling]
max_completion_tokens = 128
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "reverse-text"
env.taskset = { id = "reverse-text-v1" }
env.agent.harness = { id = "null" }
+1 -1
View File
@@ -40,7 +40,7 @@ group_size = 16
[orchestrator.train.sampling]
max_completion_tokens = 512
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "wiki-search"
env.taskset = { id = "wiki-search-v1" }
env.agent.harness = { id = "null" }
+1 -1
View File
@@ -21,7 +21,7 @@ name = "PrimeIntellect/Qwen3-1.7B-Wordle-SFT"
batch_size = 128
group_size = 8
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "wordle"
env.taskset = { id = "wordle-v1" }
env.player.harness = { id = "null" }
+1 -1
View File
@@ -22,7 +22,7 @@ group_size = 8
[orchestrator.train.sampling]
max_completion_tokens = 384
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "alphabet-sort"
env.taskset = { id = "alphabet-sort-v1", min_turns = 2, max_turns = 2, min_names_per_turn = 1, max_names_per_turn = 3, task = { similarity_power = 4, power_per_turn = false } }
env.agent.harness = { id = "null" }
@@ -26,7 +26,7 @@ name = "r8-1e-4"
[orchestrator.train.sampling]
max_completion_tokens = 128
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "reverse-text"
env.taskset = { id = "reverse-text-v1" }
env.agent.harness = { id = "null" }
@@ -25,7 +25,7 @@ name = "r8-1e-4"
[orchestrator.train.sampling]
max_completion_tokens = 128
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "reverse-text"
env.taskset = { id = "reverse-text-v1" }
env.agent.harness = { id = "null" }
@@ -25,7 +25,7 @@ group_size = 16
[orchestrator.train.sampling]
max_completion_tokens = 128
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "reverse-text"
env.taskset = { id = "reverse-text-v1" }
env.agent.harness = { id = "null" }
@@ -14,7 +14,7 @@ lr = 3e-5
[train.sampling]
max_completion_tokens = 128
[[train.env]]
[[train.source]]
name = "reverse-text"
env.taskset = { id = "reverse-text-v1" }
env.agent.harness = { id = "null" }
@@ -37,7 +37,7 @@ name = "prime-qwen3"
[orchestrator.train.sampling]
max_completion_tokens = 128
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "reverse-text"
env.taskset = { id = "reverse-text-v1" }
env.agent.harness = { id = "null" }
@@ -50,7 +50,7 @@ num_examples = 16
[orchestrator.eval.sampling]
max_completion_tokens = 128
[[orchestrator.eval.env]]
[[orchestrator.eval.source]]
name = "reverse-text"
env.taskset = { id = "reverse-text-v1" }
env.agent.harness = { id = "null" }
@@ -43,7 +43,7 @@ name = "prime-qwen3"
[orchestrator.train.sampling]
max_completion_tokens = 128
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "reverse-text"
env.taskset = { id = "reverse-text-v1" }
env.agent.harness = { id = "null" }
@@ -56,7 +56,7 @@ num_examples = 16
[orchestrator.eval.sampling]
max_completion_tokens = 128
[[orchestrator.eval.env]]
[[orchestrator.eval.source]]
name = "reverse-text"
env.taskset = { id = "reverse-text-v1" }
env.agent.harness = { id = "null" }
@@ -23,7 +23,7 @@ group_size = 16
[orchestrator.train.sampling]
max_completion_tokens = 128
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "reverse-text"
env.taskset = { id = "reverse-text-v1" }
env.agent.harness = { id = "null" }
@@ -22,7 +22,7 @@ group_size = 16
[orchestrator.train.sampling]
max_completion_tokens = 128
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "reverse-text"
env.taskset = { id = "reverse-text-v1" }
env.agent.harness = { id = "null" }
+1 -1
View File
@@ -18,7 +18,7 @@ name = "Qwen/Qwen3-4B-Instruct-2507"
batch_size = 512
group_size = 16
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "alphabet-sort"
env.taskset = { id = "alphabet-sort-v1", min_turns = 3, max_turns = 5, task = { power_per_turn = false } }
env.agent.harness = { id = "null" }
+2 -2
View File
@@ -18,7 +18,7 @@ batch_size = 512
group_size = 8
seq_len = 8192
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "hendrycks-math"
env.taskset = { id = "math-env-v1", dataset_name = "mikasenghaas/Sanity-Test-R1D-1.5B", dataset_subset = "default" }
env.agent.harness = { id = "null" }
@@ -27,7 +27,7 @@ env.agent.runtime = { type = "subprocess" }
[orchestrator.eval]
interval = 50
[[orchestrator.eval.env]]
[[orchestrator.eval.source]]
name = "aime2024"
env.taskset = { id = "aime24-v1" }
env.agent.harness = { id = "null" }
+1 -1
View File
@@ -18,7 +18,7 @@ name = "PrimeIntellect/Qwen3-0.6B-Reverse-Text-SFT"
batch_size = 128
group_size = 16
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "reverse-text"
env.taskset = { id = "reverse-text-v1" }
env.agent.harness = { id = "null" }
+1 -1
View File
@@ -23,7 +23,7 @@ oversampling_factor = 2.0
type = "zero_advantage"
enforce = true
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "wiki-search"
env.taskset = { id = "wiki-search-v1" }
env.agent.harness = { id = "null" }
+1 -1
View File
@@ -18,7 +18,7 @@ name = "PrimeIntellect/Qwen3-1.7B-Wordle-SFT"
batch_size = 512
group_size = 16
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "wordle"
env.taskset = { id = "wordle-v1" }
env.player.harness = { id = "null" }
@@ -20,7 +20,7 @@ group_size = 16
[orchestrator.train.sampling]
max_completion_tokens = 64
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "color-codeword"
env.taskset = { id = "color-codeword-v1", images_per_turn = 1 }
env.agent.harness = { id = "null" }
+1 -1
View File
@@ -24,7 +24,7 @@ type = "echo"
[orchestrator.algo.roles.user]
alpha = 0.1
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "alphabet-sort"
env.taskset = { id = "alphabet-sort-v1", min_turns = 3, max_turns = 5, task = { power_per_turn = false } }
env.agent.harness = { id = "null" }
+2 -2
View File
@@ -21,7 +21,7 @@ name = "prime-qwen3"
[orchestrator.train.sampling]
max_completion_tokens = 128
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "reverse-text"
env.taskset = { id = "reverse-text-v1" }
env.agent.harness = { id = "null" }
@@ -34,7 +34,7 @@ num_examples = 128
[orchestrator.eval.sampling]
max_completion_tokens = 128
[[orchestrator.eval.env]]
[[orchestrator.eval.source]]
name = "reverse-text"
env.taskset = { id = "reverse-text-v1" }
env.agent.harness = { id = "null" }
+2 -2
View File
@@ -21,7 +21,7 @@ name = "prime-qwen3"
[orchestrator.train.sampling]
max_completion_tokens = 128
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "reverse-text"
env.taskset = { id = "reverse-text-v1" }
env.agent.harness = { id = "null" }
@@ -34,7 +34,7 @@ num_examples = 128
[orchestrator.eval.sampling]
max_completion_tokens = 128
[[orchestrator.eval.env]]
[[orchestrator.eval.source]]
name = "reverse-text"
env.taskset = { id = "reverse-text-v1" }
env.agent.harness = { id = "null" }
+5 -5
View File
@@ -31,22 +31,22 @@ name = "prime-qwen3"
[orchestrator.train.sampling]
max_completion_tokens = 128
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "reverse-text-grpo"
env.taskset = { id = "reverse-text-v1" }
env.agent.harness = { id = "null" }
env.agent.runtime = { type = "subprocess" }
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "reverse-text-opd"
env.taskset = { id = "reverse-text-v1" }
env.agent.harness = { id = "null" }
env.agent.runtime = { type = "subprocess" }
[orchestrator.train.env.algo]
[orchestrator.train.source.algo]
type = "opd"
[orchestrator.train.env.algo.teacher]
[orchestrator.train.source.algo.teacher]
name = "PrimeIntellect/Qwen3-0.6B-Reverse-Text-RL"
base_url = ["http://localhost:8001/v1"]
@@ -57,7 +57,7 @@ num_examples = 128
[orchestrator.eval.sampling]
max_completion_tokens = 128
[[orchestrator.eval.env]]
[[orchestrator.eval.source]]
name = "reverse-text"
env.taskset = { id = "reverse-text-v1" }
env.agent.harness = { id = "null" }
+2 -2
View File
@@ -33,7 +33,7 @@ name = "prime-qwen3"
[orchestrator.train.sampling]
max_completion_tokens = 128
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "reverse-text"
env.taskset = { id = "reverse-text-v1" }
env.agent.harness = { id = "null" }
@@ -46,7 +46,7 @@ num_examples = 128
[orchestrator.eval.sampling]
max_completion_tokens = 128
[[orchestrator.eval.env]]
[[orchestrator.eval.source]]
name = "reverse-text"
env.taskset = { id = "reverse-text-v1" }
env.agent.harness = { id = "null" }
+2 -2
View File
@@ -33,7 +33,7 @@ name = "prime-qwen3"
[orchestrator.train.sampling]
max_completion_tokens = 128
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "reverse-text"
env.taskset = { id = "reverse-text-v1" }
env.agent.harness = { id = "null" }
@@ -46,7 +46,7 @@ num_examples = 128
[orchestrator.eval.sampling]
max_completion_tokens = 128
[[orchestrator.eval.env]]
[[orchestrator.eval.source]]
name = "reverse-text"
env.taskset = { id = "reverse-text-v1" }
env.agent.harness = { id = "null" }
+2 -2
View File
@@ -21,7 +21,7 @@ name = "prime-qwen3"
[orchestrator.train.sampling]
max_completion_tokens = 512
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "kuhn-poker"
env.taskset = { id = "kuhn-poker-v1" }
env.player0.harness = { id = "null" }
@@ -36,7 +36,7 @@ num_examples = 16
[orchestrator.eval.sampling]
max_completion_tokens = 512
[[orchestrator.eval.env]]
[[orchestrator.eval.source]]
name = "kuhn-poker"
env.taskset = { id = "kuhn-poker-v1" }
env.player0.harness = { id = "null" }
+2 -2
View File
@@ -29,7 +29,7 @@ name = "prime-qwen3"
[orchestrator.train.sampling]
max_completion_tokens = 128
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "reverse-text"
env.taskset = { id = "reverse-text-v1" }
env.agent.harness = { id = "null" }
@@ -42,7 +42,7 @@ num_examples = 128
[orchestrator.eval.sampling]
max_completion_tokens = 128
[[orchestrator.eval.env]]
[[orchestrator.eval.source]]
name = "reverse-text"
env.taskset = { id = "reverse-text-v1" }
env.agent.harness = { id = "null" }
+2 -2
View File
@@ -38,7 +38,7 @@ name = "prime-qwen3"
[orchestrator.train.sampling]
max_completion_tokens = 128
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "reverse-text"
env.taskset = { id = "reverse-text-v1" }
env.agent.harness = { id = "null" }
@@ -51,7 +51,7 @@ num_examples = 128
[orchestrator.eval.sampling]
max_completion_tokens = 128
[[orchestrator.eval.env]]
[[orchestrator.eval.source]]
name = "reverse-text"
env.taskset = { id = "reverse-text-v1" }
env.agent.harness = { id = "null" }
+2 -2
View File
@@ -38,7 +38,7 @@ name = "prime-qwen3"
[orchestrator.train.sampling]
max_completion_tokens = 128
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "reverse-text"
env.taskset = { id = "reverse-text-v1" }
env.agent.harness = { id = "null" }
@@ -51,7 +51,7 @@ num_examples = 128
[orchestrator.eval.sampling]
max_completion_tokens = 128
[[orchestrator.eval.env]]
[[orchestrator.eval.source]]
name = "reverse-text"
env.taskset = { id = "reverse-text-v1" }
env.agent.harness = { id = "null" }
+1 -1
+1 -1
+65 -10
View File
@@ -17,6 +17,7 @@ This page covers the math and the configurable algorithmic components: the algor
- [Custom Loss](#custom-loss)
- [Advantage](#advantage)
- [Default Advantage](#default-advantage)
- [Hierarchical GRPO](#hierarchical-grpo)
- [Self-Play Advantage (RAE)](#self-play-advantage-rae)
- [Authoring an Algorithm](#authoring-an-algorithm)
- [Reference Scoring](#reference-scoring)
@@ -69,6 +70,7 @@ type = "grpo" # the default
| `grpo` | policy | `rl` on actions | Standard group-relative RL. |
| `max_rl` | policy | `rl` on actions | MaxRL ([arXiv:2602.02710](https://arxiv.org/abs/2602.02710)): GRPO's centered reward normalized by the group **mean** instead of the standard deviation — the gradient is unbiased for the order-`group_size` truncation of the maximum-likelihood objective, upweighting hard examples like `1/p`. |
| `rae` | policy | `rl` on actions | RAE (SPIRAL, [arXiv:2506.24119](https://arxiv.org/abs/2506.24119)): reward minus a per-agent EMA baseline of that agent's own rewards — the estimator for multi-agent self-play envs, where the group mean would mix the agents' opposite reward scales. See [Self-Play Advantage](#self-play-advantage-rae). |
| `hierarchical_grpo` | policy | `rl` on actions | GRPO for proposer-solver envs. Solvers are compared only with attempts on the same proposed problem; proposers are compared with the other proposals in the group. See [Hierarchical GRPO](#hierarchical-grpo). |
| `opd` | policy | `ref_kl` on actions | On-policy distillation ([Thinking Machines](https://thinkingmachines.ai/blog/on-policy-distillation/)): the policy samples, per-token reverse KL against a reference model as the gradient signal. Needs a `teacher`. |
| `sft` | *(the teacher)* | `ce` on actions | Hard distillation: a frozen model generates rollouts, the policy trains with CE on its tokens. Needs a frozen `sampling.source` (the teacher it samples from). |
| `opsd` | policy | `ref_kl` on actions | SDFT ([arXiv:2601.19897](https://arxiv.org/abs/2601.19897)): the model is its own reference, conditioned on an expert demonstration. The teacher *is* the live policy (the paper's setting, no extra deployment) — no model to configure. |
@@ -118,18 +120,18 @@ Both components resolve per environment. Each env inherits `[orchestrator.algo]`
[orchestrator.algo]
type = "grpo"
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "math"
taskset = { id = "math-v1" }
harness = { id = "null" }
runtime = { type = "subprocess" }
env.taskset = { id = "math-v1" }
env.agent.harness = { id = "null" }
env.agent.runtime = { type = "subprocess" }
# inherits the top-level grpo
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "terminal"
taskset = { id = "terminal-v1" }
harness = { id = "bash" }
runtime = { type = "subprocess" }
env.taskset = { id = "terminal-v1" }
env.agent.harness = { id = "bash" }
env.agent.runtime = { type = "subprocess" }
algo = { type = "echo" } # this env runs its own algorithm
```
@@ -143,6 +145,7 @@ At runtime, each env's resolved config builds two objects: a `Sampler` (`prime_r
| `echo` | `EchoAlgorithm` | `score_rollout`: weighted ce on observation tokens; `score_group`: group-norm credit (inherited) |
| `max_rl` | `MaxRLAlgorithm` | `score_group`: mean-normalized group credit |
| `rae` | `RAEAlgorithm` | `score_group`: per-agent EMA-baseline credit |
| `hierarchical_grpo` | `HierarchicalGRPOAlgorithm` | `score_group`: GRPO baseline per episode for solvers, per group for the proposer |
| `opd` | `OPDAlgorithm` | `score_rollout`: own-context prefill under the teacher |
| `opsd` | `OPSDAlgorithm` | `score_rollout`: demo-conditioned prefill under the live policy |
| `sft` | `SFTDistillAlgorithm` | `score_group`: group-norm credit (feeds filters) |
@@ -179,7 +182,7 @@ $$
\mathcal{L} = \frac{\sum \mathcal{L}_{rl}}{N_{rl}} + \frac{\sum \mathcal{L}_{ce}}{N_{ce}} + \frac{\sum \mathcal{L}_{ref\_kl}}{N_{ref\_kl}}
$$
- `rl` — the configured RL loss (`[trainer.loss]`): DPPO + KL by default, or a [custom loss](#custom-loss). Fed by the advantage-assigning algorithms (`grpo`, `max_rl`, `rae`, and `echo`'s action tokens).
- `rl` — the configured RL loss (`[trainer.loss]`): DPPO + KL by default, or a [custom loss](#custom-loss). Fed by the advantage-assigning algorithms (`grpo`, `max_rl`, `rae`, `hierarchical_grpo`, and `echo`'s action tokens).
- `ce` — masked NLL. Used for frozen-model tokens (`sft`) and env-observation tokens (`echo`).
- `ref_kl` — the per-token reverse KL to a reference model ($\log \pi_{\text{ref}} - \log \pi$) as the policy-gradient signal, importance-ratio corrected with a one-sided trust region (`opd`, `opsd`). Requires `ref_logprobs` from a [reference scoring](#reference-scoring); the scoring model must be a vLLM server (it's the only one that exposes `prompt_logprobs`).
@@ -282,6 +285,7 @@ The per-token training signal is set by `algo.type` and the [algorithm](#the-alg
| `grpo` | `rl` | Group-norm: reward minus per-group baseline, optional length penalty. |
| `max_rl` | `rl` | Mean-normalized group credit (maximum-likelihood RL). |
| `rae` | `rl` | Reward minus a per-agent EMA baseline (SPIRAL's role-conditioned advantage estimation) — for multi-agent self-play envs. |
| `hierarchical_grpo` | `rl` | GRPO for proposer-solver envs: solvers are compared within one proposed problem, while proposers are compared across proposals. |
| `echo` | `rl` + `ce` | Group-norm on action tokens, plus weighted CE on env-provided tokens selected by message role (each role's `alpha` is its ECHO λ), optionally narrowed by a user filter. |
| `opd` | `ref_kl` | On-policy distillation: per-token reverse KL to a reference model (`teacher`, an inline frozen hosted model), evaluated in the trainer from shipped reference logprobs. No credit — rollouts keep `advantages = None` (advantage-based filters never fire) and ship no advantage stream; `group_size` only fans out sampling. |
| `opsd` | `ref_kl` | SDFT: per-token reverse KL to a demo-conditioned reference. No credit — rollouts keep `advantages = None` (advantage-based filters never fire) and ship no advantage stream. |
@@ -303,6 +307,57 @@ type = "grpo"
type = "linear"
```
### Hierarchical GRPO
GRPO gives each rollout its reward minus the average reward of comparable rollouts. In an ordinary single-agent group, every rollout answers the same task, so one group average is enough.
A proposer-solver env is different. Starting from one source task, it produces several proposed problems, then runs several solver attempts on each problem:
```text
one source task
├── proposed problem A
│ ├── proposer trace
│ ├── solver attempt 1
│ └── solver attempt 2
└── proposed problem B
├── proposer trace
├── solver attempt 1
└── solver attempt 2
```
The solver attempts for A should not be compared with the solver attempts for B: the two problems may have very different difficulty. Proposer and solver rewards should not be compared either: they measure different jobs.
`hierarchical_grpo` therefore chooses the average separately for each role:
| Trace | Compared with | Why |
|---|---|---|
| Solver | Other solver attempts on the same proposed problem | They attempted the same problem. |
| Proposer | Other proposer traces in the group | They started from the same source task and proposed alternatives. |
For example, if three solvers receive rewards `[1, 1, 0]` on one proposed problem, their average is `2/3` and their advantages are `[1/3, 1/3, -2/3]`. Solver rewards from other proposed problems do not affect those values. The proposers are scored separately according to how useful their problems were for the solvers, then compared with the other proposers in the group.
Configure which roles are compared within a single proposed problem with `episode_agents`. For `proposer-solver-v1`, that role is `solver`:
```toml
[orchestrator.algo]
type = "hierarchical_grpo"
episode_agents = ["solver"]
[[orchestrator.train.source]]
name = "proposer-solver"
group_size = 4 # proposed problems per source task
env.taskset = { id = "proposer-solver-v1" }
env.n = 4 # solver attempts per proposed problem
env.proposer.harness = { id = "null" }
env.proposer.runtime = { type = "subprocess" }
env.solver.harness = { id = "null" }
env.solver.runtime = { type = "subprocess" }
```
`group_size` controls how many problems are proposed from each source task. `env.n` controls how many solvers attempt each proposed problem. If a comparison contains only one trace—for example, a solver when `env.n = 1`—its advantage is zero and the zero-advantage filter removes it.
This algorithm is accepted only for proposer-solver envs. Use the env's `train_proposer` and `train_solver` settings if you want to train only one role.
### Self-Play Advantage (RAE)
Group-relative baselines assume the group is exchangeable attempts by one agent. A multi-agent self-play env breaks that: one episode yields one trace per agent, all trainable, and in a zero-sum game the rewards sum to ~0 whatever the policy does — the group mean carries no information, and centering against it converts any structural asymmetry (a first-mover edge) into permanent credit for one agent.
@@ -314,7 +369,7 @@ Group-relative baselines assume the group is exchangeable attempts by one agent.
type = "rae"
decay = 0.95
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "kuhn-poker"
env.taskset = { id = "kuhn-poker-v1" }
env.player0.harness = { id = "null" }
+10 -10
View File
@@ -17,7 +17,7 @@ Every `prime-rl` entrypoint uses [`pydantic-config`](https://github.com/PrimeInt
- [Optional Sub-Configs](#optional-sub-configs)
- [None](#none)
- [Discriminated Unions](#discriminated-unions)
- [Environments](#environments-orchestratortrainenv)
- [Environments](#environments)
- [Environment Variables](#environment-variables)
- [Examples](#examples)
@@ -55,7 +55,7 @@ CLI flags mirror the TOML tree using dots:
> Field names are snake_case in TOML (`max_model_len`) and kebab-case on the CLI (`--max-model-len`).
> Renamed fields keep their old name as a validation alias — e.g. `rollouts_per_example` is still accepted in TOML and CLI after being renamed to `group_size`. Mixing the two names across sources is safe.
> A renamed field keeps no alias for its old name: the old spelling fails as an unknown key rather than being silently translated.
## Inspecting and Validating
@@ -93,19 +93,19 @@ uv run rl @ rl.toml --trainer.model.lora.target-modules '["q_proj", "k_proj", "v
target_modules = ["q_proj", "k_proj", "v_proj"]
```
Overlay TOMLs **replace** lists wholesale — an overlay that wants to add one item must still spell out the full list. For arrays of tables (e.g. environments), see [Environments](#environments-orchestratortrainenv).
Overlay TOMLs **replace** lists wholesale — an overlay that wants to add one item must still spell out the full list. For arrays of tables, see [Environments](#environments).
### Dicts
CLI takes a JSON literal. TOML uses a table or inline-table. CLI dicts deep-merge with TOML dicts — CLI keys win on conflict but don't wipe the file's keys:
```bash
uv run rl @ rl.toml --orchestrator.train.env.0.args \
uv run rl @ rl.toml --orchestrator.train.source.0.args \
'{"dataset_name": "openai/gsm8k", "dataset_subset": "main"}'
```
```toml
[[orchestrator.train.env]]
[[orchestrator.train.source]]
args = { dataset_name = "openai/gsm8k", dataset_subset = "main" }
```
@@ -142,26 +142,26 @@ mu = 0.95
Omit `type` to keep the default variant.
### Environments (`[[orchestrator.train.env]]`)
### Environments
Training environments are an array of tables — set one per env, optionally with sampling weights:
Training and evaluation sources are arrays of tables. Set one source per environment; training sources can optionally carry sampling weights:
```toml
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "gsm8k"
env.taskset = { id = "gsm8k-v1", split = "train" }
env.agent.harness = { id = "null" }
env.agent.runtime = { type = "subprocess" }
ratio = 3 # 75% of batches
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "reverse-text"
env.taskset = { id = "reverse-text-v1" }
env.agent.harness = { id = "null" }
env.agent.runtime = { type = "subprocess" }
ratio = 1 # default — 25% of batches
[[orchestrator.eval.env]]
[[orchestrator.eval.source]]
name = "gsm8k-eval"
env.taskset = { id = "gsm8k-v1", split = "test" }
env.agent.harness = { id = "null" }
+1 -1
View File
@@ -283,6 +283,6 @@ enable_router_replay = true # this will also auto-set the inference.enable_retur
enable_return_routed_experts = true
```
This however is not free, it adds a significant overhead to the HTTP requests as this payload can grow quite large. We reccomend increasing `orchestrator.*.env.num_workers` to allow for more parallelization on the verifiers side.
This however is not free, it adds a significant overhead to the HTTP requests as this payload can grow quite large. We reccomend sizing up the env-server pool (`orchestrator.*.source.serve.pool`) to allow for more parallelization on the verifiers side.
Currently this feature is also not supported with CPU KV cache offload, which can have negative impact on the inference throughput.
+4 -3
View File
@@ -59,9 +59,9 @@ A condensed view of the knobs you'll most often tune. For trainer-side paralleli
| `orchestrator.batch_size` | Tasks per trainer step. |
| `orchestrator.group_size` | Rollouts generated per task. |
| `orchestrator.max_off_policy_steps` | How many distinct policies may have contributed to one rollout before it's discarded (default 8). The main off-policy dial on long agentic rollouts — bump for throughput, lower for tighter on-policyness. Watch `errored_rollouts` and `mismatch_kl/all/mean` when tuning. |
| `[orchestrator.algo]` | Training algorithm — its `type` names it (`grpo` default, `max_rl`, `rae`, `opd`, `opsd`, `sft`, `echo`). See [Algorithms](#algorithms). |
| `[[orchestrator.train.env]]` | Training environments. List multiple tables for multi-env training; weight them via `ratio`. See [Configuration § Environments](configuration.md#environments-orchestratortrainenv). |
| `[[orchestrator.eval.env]]` + `orchestrator.eval.interval` | Eval environments and cadence (default every 100 steps). |
| `[orchestrator.algo]` | Training algorithm — its `type` names it (`grpo` default, `max_rl`, `rae`, `hierarchical_grpo`, `opd`, `opsd`, `sft`, `echo`). See [Algorithms](#algorithms). |
| `[[orchestrator.train.source]]` | Training sources. List multiple tables for multi-env training; weight them via `ratio`. See [Configuration § Training sources](configuration.md#training-sources-orchestratortrainsource). |
| `[[orchestrator.eval.source]]` + `orchestrator.eval.interval` | Eval environments and cadence (default every 100 steps). |
**Monitoring:**
@@ -90,6 +90,7 @@ The RL entrypoint supports several training algorithms, switched via `[orchestra
| `grpo` (default) | None | Standard group-relative RL |
| `max_rl` | None | [MaxRL](https://arxiv.org/abs/2602.02710): GRPO with mean-normalized advantages (maximum-likelihood RL) |
| `rae` | None | [SPIRAL](https://arxiv.org/abs/2506.24119)'s role-conditioned advantage estimation: reward minus a per-agent EMA baseline, for multi-agent self-play envs (e.g. `kuhn-poker-v1`) |
| `hierarchical_grpo` | None | GRPO for proposer-solver envs: compare solvers only with attempts on the same proposed problem, and compare proposers with the other proposals in the group |
| `opd` | Required, must be vLLM (needs `prompt_logprobs`) | [On-policy distillation](https://thinkingmachines.ai/blog/on-policy-distillation/): the policy generates rollouts, the trainer minimizes per-token reverse KL to a reference model |
| `sft` | Required, any OpenAI-compatible endpoint | Hard-distill: a frozen model generates rollouts, the policy trains on its tokens |
| `opsd` | None — the live policy is its own reference (no deployment) | [SDFT](https://arxiv.org/abs/2601.19897): the model is its own reference conditioned on expert demonstrations |
+12 -12
View File
@@ -71,7 +71,7 @@ type = "muon"
batch_size = 256
group_size = 16
max_off_policy_steps = 32
max_inflight_rollouts = 512
max_inflight_episodes = 512
[orchestrator.renderer]
name = "glm-4.5"
@@ -93,15 +93,15 @@ num_turns_weight = 0.0
# openseeker/redsearcher pre-plug a `reference` judge; declaring `judges` here replaces that
# entry wholesale (keep `name`/`question_field`/`choices` in sync with the taskset defaults —
# the plugged BC-style prompt is replaced by the reference judge's stock prompt).
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "openseeker"
env.agent.harness = { id = "rlm", skills = ["search"], forward_env = ["SERPER_API_KEY"], summarize_at_tokens = [65536, 131072] }
env.agent.runtime = { type = "prime", vm = true, idle_timeout = "None", labels = ["glm45air-search"] }
[orchestrator.train.env.env.taskset]
[orchestrator.train.source.env.taskset]
id = "openseeker-v1"
[[orchestrator.train.env.env.taskset.task.judges]]
[[orchestrator.train.source.env.taskset.task.judges]]
id = "reference"
name = "correct"
model = "Qwen/Qwen3-235B-A22B-Instruct-2507"
@@ -109,22 +109,22 @@ question_field = "question"
choices = ["A", "B"]
# # Metric-only monitor (weight 0): rlm harness-mechanics rubric, judged by GLM-5.2.
# [[orchestrator.train.env.env.taskset.task.judges]]
# [[orchestrator.train.source.env.taskset.task.judges]]
# id = "rubric"
# name = "rlm"
# path = "deps/research-environments/rubrics/rlm.toml"
# model = "zai-org/GLM-5.2"
# weight = 0.0
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "redsearcher"
env.agent.harness = { id = "rlm", skills = ["search"], forward_env = ["SERPER_API_KEY"], summarize_at_tokens = [65536, 131072] }
env.agent.runtime = { type = "prime", vm = true, idle_timeout = "None", labels = ["glm45air-search"] }
[orchestrator.train.env.env.taskset]
[orchestrator.train.source.env.taskset]
id = "redsearcher-v1" # optional `difficulty` filter (easy/medium/hard)
[[orchestrator.train.env.env.taskset.task.judges]]
[[orchestrator.train.source.env.taskset.task.judges]]
id = "reference"
name = "correct"
model = "Qwen/Qwen3-235B-A22B-Instruct-2507"
@@ -132,7 +132,7 @@ question_field = "question"
choices = ["A", "B"]
# # Metric-only monitor (weight 0): rlm harness-mechanics rubric, judged by GLM-5.2.
# [[orchestrator.train.env.env.taskset.task.judges]]
# [[orchestrator.train.source.env.taskset.task.judges]]
# id = "rubric"
# name = "rlm"
# path = "deps/research-environments/rubrics/rlm.toml"
@@ -144,19 +144,19 @@ choices = ["A", "B"]
[orchestrator.eval]
interval = 20
[[orchestrator.eval.env]]
[[orchestrator.eval.source]]
name = "browsecomp"
num_examples = 500 # full set is 1266; cap eval at 500
env.agent.harness = { id = "rlm", skills = ["search"], forward_env = ["SERPER_API_KEY"], summarize_at_tokens = 98304 }
env.agent.runtime = { type = "prime", vm = true, idle_timeout = "None", labels = ["glm45air-search"] }
env.agent.timeout = { rollout = 3600 }
[orchestrator.eval.env.env.taskset]
[orchestrator.eval.source.env.taskset]
id = "browsecomp-v1"
task = { judge = { model = "Qwen/Qwen3-235B-A22B-Instruct-2507" } }
# # Metric-only monitor (weight 0): rlm harness-mechanics rubric, judged by GLM-5.2.
# [[orchestrator.eval.env.env.taskset.task.judges]]
# [[orchestrator.eval.source.env.taskset.task.judges]]
# id = "rubric"
# name = "rlm"
# path = "deps/research-environments/rubrics/rlm.toml"
+3 -3
View File
@@ -82,7 +82,7 @@ type = "muon"
batch_size = 256
group_size = 16
max_off_policy_steps = 32
max_inflight_rollouts = 512
max_inflight_episodes = 512
[orchestrator.algo]
type = "grpo"
@@ -97,7 +97,7 @@ num_turns_weight = 0.1
name = "glm-4.5"
thinking_retention = "all"
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "scaleswe"
env.taskset = { id = "scaleswe-v1" }
env.agent.harness = { id = "rlm", summarize_at_tokens = [65536, 131072] }
@@ -110,7 +110,7 @@ env.agent.runtime = { type = "prime", vm = true, idle_timeout = "None", labels =
[orchestrator.eval]
interval = 20
[[orchestrator.eval.env]]
[[orchestrator.eval.source]]
name = "swebench-verified"
env.taskset = { id = "swebench-verified-v1" }
env.agent.harness = { id = "rlm", summarize_at_tokens = 98304 }
+13 -13
View File
@@ -72,7 +72,7 @@ type = "muon"
batch_size = 256
group_size = 16
max_off_policy_steps = 32
max_inflight_rollouts = 512
max_inflight_episodes = 512
[orchestrator.renderer]
name = "glm-4.5"
@@ -91,23 +91,23 @@ num_turns_weight = 0.1
# --- Train: tmax (per-task Docker image in a prime sandbox, rlm ipython) ---
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "tmax"
env.agent.harness = { id = "rlm", summarize_at_tokens = [65536, 131072] }
env.agent.runtime = { type = "prime", vm = true, idle_timeout = "None", labels = ["glm45air-terminal"] }
[orchestrator.train.env.env.taskset]
[orchestrator.train.source.env.taskset]
id = "tmax-v1"
# # Metric-only monitors (weight 0): rlm harness-mechanics + swe code-usage rubrics, judged by GLM-5.2.
# [[orchestrator.train.env.env.taskset.judges]]
# [[orchestrator.train.source.env.taskset.judges]]
# id = "rubric"
# name = "rlm"
# path = "deps/research-environments/rubrics/rlm.toml"
# model = "zai-org/GLM-5.2"
# weight = 0.0
# [[orchestrator.train.env.env.taskset.judges]]
# [[orchestrator.train.source.env.taskset.judges]]
# id = "rubric"
# name = "swe"
# path = "deps/research-environments/rubrics/swe.toml"
@@ -119,47 +119,47 @@ id = "tmax-v1"
[orchestrator.eval]
interval = 20
[[orchestrator.eval.env]]
[[orchestrator.eval.source]]
name = "swebench-verified"
env.agent.harness = { id = "rlm", summarize_at_tokens = 98304 }
env.agent.runtime = { type = "prime", vm = true, idle_timeout = "None", labels = ["glm45air-terminal"] }
env.agent.timeout = { rollout = 3600 }
[orchestrator.eval.env.env.taskset]
[orchestrator.eval.source.env.taskset]
id = "swebench-verified-v1"
# [[orchestrator.eval.env.env.taskset.judges]]
# [[orchestrator.eval.source.env.taskset.judges]]
# id = "rubric"
# name = "rlm"
# path = "deps/research-environments/rubrics/rlm.toml"
# model = "zai-org/GLM-5.2"
# weight = 0.0
# [[orchestrator.eval.env.env.taskset.judges]]
# [[orchestrator.eval.source.env.taskset.judges]]
# id = "rubric"
# name = "swe"
# path = "deps/research-environments/rubrics/swe.toml"
# model = "zai-org/GLM-5.2"
# weight = 0.0
[[orchestrator.eval.env]]
[[orchestrator.eval.source]]
name = "terminal-bench-2"
group_size = 4 # avg@4
env.agent.harness = { id = "rlm", summarize_at_tokens = 98304 }
env.agent.runtime = { type = "prime", vm = true, idle_timeout = "None", labels = ["glm45air-terminal"] }
env.agent.timeout = { rollout = 3600 }
[orchestrator.eval.env.env.taskset]
[orchestrator.eval.source.env.taskset]
id = "terminal-bench-2-v1"
# [[orchestrator.eval.env.env.taskset.judges]]
# [[orchestrator.eval.source.env.taskset.judges]]
# id = "rubric"
# name = "rlm"
# path = "deps/research-environments/rubrics/rlm.toml"
# model = "zai-org/GLM-5.2"
# weight = 0.0
# [[orchestrator.eval.env.env.taskset.judges]]
# [[orchestrator.eval.source.env.taskset.judges]]
# id = "rubric"
# name = "swe"
# path = "deps/research-environments/rubrics/swe.toml"
+2 -2
View File
@@ -81,7 +81,7 @@ weight_decay = 0.0
[orchestrator]
batch_size = 256
group_size = 16
max_inflight_rollouts = 2048
max_inflight_episodes = 2048
max_off_policy_steps = 8 # 16/32 can be better, 8 is more CPU stable
[orchestrator.model]
@@ -96,7 +96,7 @@ temperature = 1.0
extra_body = {chat_template_kwargs = {clear_thinking = false}}
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "r2e"
env.taskset = { id = "r2e-gym-v1" }
env.agent.harness = { id = "rlm" }
+1 -1
View File
@@ -71,7 +71,7 @@ name = "zai-org/GLM-5-FP8"
[orchestrator.eval]
interval = 20
[[orchestrator.eval.env]]
[[orchestrator.eval.source]]
name = "swe-bench-verified"
env.taskset = { id = "swebench-verified-v1" }
env.agent.harness = { id = "bash" }
+7 -7
View File
@@ -47,35 +47,35 @@ weight_decay = 0.01
batch_size = 2048
oversampling_factor = 2
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "swe"
ratio = 0.3
env.taskset = { id = "r2e-gym-v1" }
env.agent.harness = { id = "bash" }
env.agent.runtime = { type = "prime", labels = ["intellect-3.1", "swe"] }
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "deepdive"
ratio = 0.2
env.taskset = { id = "deepdive-v1" }
env.agent.harness = { id = "rlm", skills = ["search"], forward_env = ["SERPER_API_KEY"] }
env.agent.runtime = { type = "prime", labels = ["intellect-3.1", "deepdive"] }
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "math"
ratio = 0.3
env.taskset = { id = "i3_math_v1" }
env.agent.harness = { id = "null" }
env.agent.runtime = { type = "subprocess" }
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "logic"
ratio = 0.2
env.taskset = { id = "i3_logic_v1", filter = { max = 0.874 } }
env.agent.harness = { id = "null" }
env.agent.runtime = { type = "subprocess" }
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "code"
ratio = 0.2
env.taskset = { id = "i3_code_v1" }
@@ -89,13 +89,13 @@ enforce = true
[orchestrator.eval]
interval = 25
[[orchestrator.eval.env]]
[[orchestrator.eval.source]]
name = "swe-bench-verified"
env.taskset = { id = "swebench-verified-v1" }
env.agent.harness = { id = "bash" }
env.agent.runtime = { type = "prime", labels = ["intellect-3.1", "swe-bench-verified"] }
[[orchestrator.eval.env]]
[[orchestrator.eval.source]]
name = "aime2025"
env.taskset = { id = "aime25-v1" }
env.agent.harness = { id = "null" }
+2 -2
View File
@@ -49,7 +49,7 @@ oversampling_factor = 2
max_off_policy_steps = 16
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "swe"
env.taskset = { id = "r2e-gym-v1" }
env.agent.harness = { id = "bash" }
@@ -58,7 +58,7 @@ env.agent.runtime = { type = "prime", labels = ["minimax-swe", "swe"] }
[orchestrator.eval]
interval = 25
[[orchestrator.eval.env]]
[[orchestrator.eval.source]]
name = "swe-bench-verified"
env.taskset = { id = "swebench-verified-v1" }
env.agent.harness = { id = "bash" }
+3 -3
View File
@@ -66,7 +66,7 @@ type = "adamw"
batch_size = 256
group_size = 16
max_off_policy_steps = 32
max_inflight_rollouts = 1536
max_inflight_episodes = 1536
[orchestrator.algo]
type = "grpo"
@@ -81,7 +81,7 @@ num_turns_weight = 0.1
name = "nemotron-3"
truncate_history_thinking = false
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "scaleswe"
env.taskset = { id = "scaleswe-v1" }
env.agent.harness = { id = "rlm", summarize_at_tokens = [65536, 131072] }
@@ -92,7 +92,7 @@ env.agent.runtime = { type = "prime", vm = true, idle_timeout = "None", labels =
[orchestrator.eval]
interval = 20
[[orchestrator.eval.env]]
[[orchestrator.eval.source]]
name = "swebench-verified"
env.taskset = { id = "swebench-verified-v1" }
env.agent.harness = { id = "rlm", summarize_at_tokens = 98304 }
+2 -2
View File
@@ -48,7 +48,7 @@ max_off_policy_steps = 8
[orchestrator.train.sampling]
max_completion_tokens = 32768
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "math"
env.taskset = { id = "i3_math_v1" }
env.agent.harness = { id = "null" }
@@ -57,7 +57,7 @@ env.agent.runtime = { type = "subprocess" }
[orchestrator.eval]
interval = 25
[[orchestrator.eval.env]]
[[orchestrator.eval.source]]
name = "aime2025"
env.taskset = { id = "aime25-v1" }
env.agent.harness = { id = "null" }
+2 -2
View File
@@ -46,7 +46,7 @@ batch_size = 512
oversampling_factor = 2
max_off_policy_steps = 16
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "swe"
env.taskset = { id = "r2e-gym-v1" }
env.agent.harness = { id = "bash" }
@@ -55,7 +55,7 @@ env.agent.runtime = { type = "prime", labels = ["qwen30b-swe", "swe"] }
[orchestrator.eval]
interval = 25
[[orchestrator.eval.env]]
[[orchestrator.eval.source]]
name = "swe-bench-verified"
env.taskset = { id = "swebench-verified-v1" }
env.agent.harness = { id = "bash" }
+1 -1
View File
@@ -35,7 +35,7 @@ batch_size = 512
group_size = 16
max_off_policy_steps = 32
[[orchestrator.train.env]]
[[orchestrator.train.source]]
env.taskset = { id = "general-agent-v1", task = { tools = { colocated = true } }, min_tier = 1 }
env.agent.harness = { id = "null" }
env.agent.runtime = { type = "modal" }
+1 -1
View File
@@ -31,7 +31,7 @@ group_size = 16
[orchestrator.train.sampling]
max_completion_tokens = 768
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "alphabet-sort"
env.taskset = { id = "alphabet-sort-v1", min_turns = 3, max_turns = 5, task = { power_per_turn = false } }
env.agent.harness = { id = "null" }
+2 -2
View File
@@ -16,7 +16,7 @@ batch_size = 512
group_size = 8
seq_len = 8192
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "hendrycks-math"
env.taskset = { id = "math-env-v1", dataset_name = "mikasenghaas/Sanity-Test-R1D-1.5B", dataset_subset = "default" }
env.agent.harness = { id = "null" }
@@ -25,7 +25,7 @@ env.agent.runtime = { type = "subprocess" }
[orchestrator.eval]
interval = 50
[[orchestrator.eval.env]]
[[orchestrator.eval.source]]
name = "aime2024"
env.taskset = { id = "aime24-v1" }
env.agent.harness = { id = "null" }
+1 -1
View File
@@ -15,7 +15,7 @@ group_size = 16
[orchestrator.train.sampling]
max_completion_tokens = 128
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "reverse-text"
env.taskset = { id = "reverse-text-v1" }
env.agent.harness = { id = "null" }
+1 -1
View File
@@ -133,7 +133,7 @@ uv run eval wiki-search-v1 --harness.id null \
The V1 taskset fixes the question bank and searchable corpus. You can replace its reference judge in `rl.toml`:
```toml
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "wiki-search"
taskset = { id = "wiki-search-v1", task = { judges = [{ id = "reference", model = "openai/gpt-5.4-nano" }] } }
harness = { id = "null" }
+1 -1
View File
@@ -44,7 +44,7 @@ max_completion_tokens = 512
type = "zero_advantage"
enforce = true
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "wiki-search"
env.taskset = { id = "wiki-search-v1" }
env.agent.harness = { id = "null" }
+1 -1
View File
@@ -18,7 +18,7 @@ name = "PrimeIntellect/Qwen3-1.7B-Wordle-SFT"
batch_size = 512
group_size = 16
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "wordle"
env.taskset = { id = "wordle-v1" }
env.player.harness = { id = "null" }
+4 -3
View File
@@ -13,10 +13,11 @@ name = "reverse-text"
[train.sampling]
max_completion_tokens = 128
[[train.env]]
[[train.source]]
name = "reverse-text"
taskset = { id = "reverse-text-v1" }
harness = { id = "null", runtime = { type = "subprocess" } }
env.taskset = { id = "reverse-text-v1" }
env.agent.harness = { id = "null" }
env.agent.runtime = { type = "subprocess" }
[renderer]
name = "prime-qwen3"
+1 -1
View File
@@ -10,7 +10,7 @@ dependencies = [
"renderers>=0.1.8",
"tomli>=2.2.1",
"tomli-w>=1.2.0",
"verifiers>=0.2.1",
"verifiers>=0.2.2.dev43",
]
[build-system]
@@ -35,6 +35,7 @@ executes them.
from typing import Annotated, Any, ClassVar, Literal, TypeAlias
import verifiers.v1 as vf
from pydantic import Field, model_validator
from renderers import AutoRendererConfig, RendererConfig
@@ -188,6 +189,13 @@ class BaseAlgoConfig(BaseConfig):
)
return self
def validate_env(self, env_config: vf.EnvConfig) -> None:
"""Raise if this algorithm cannot run on the env it is configured for,
given that env's resolved config. Most algorithms read only the rollouts
and their rewards, so they run on any env and the base does nothing;
override where the credit assignment encodes an env's episode structure.
Called once per train env after algorithm inheritance resolves."""
class GRPOAlgoConfig(BaseAlgoConfig):
type: Literal["grpo"] = "grpo"
@@ -253,6 +261,39 @@ class RAEAlgoConfig(BaseAlgoConfig):
memory — a restart re-warms them over ~1/(1 − decay) traces per agent."""
class HierarchicalGRPOAlgoConfig(BaseAlgoConfig):
type: Literal["hierarchical_grpo"] = "hierarchical_grpo"
"""GRPO for proposer-solver envs.
Agents in ``episode_agents`` are compared with same-role attempts on the
same proposed problem. Other agents are compared with the same role across
proposals generated from one source task. This keeps rewards from different
problems and different roles out of the same average."""
action_loss_type: ClassVar[ActionLossType] = "rl"
episode_agents: list[str] = Field(min_length=1)
"""Roles compared within one proposed problem. Use ``["solver"]`` for
``proposer-solver-v1``."""
def validate_env(self, env_config: vf.EnvConfig) -> None:
"""Require the proposer-solver structure used by the comparisons."""
try:
from proposer_solver_v1 import ProposerSolverEnvConfig
except ImportError as e:
raise ValueError(
"algorithm 'hierarchical_grpo' requires a proposer-solver env, but the "
"proposer-solver-v1 package is not installed (`uv sync --all-packages`)."
) from e
if not isinstance(env_config, ProposerSolverEnvConfig):
raise ValueError(
f"algorithm 'hierarchical_grpo' needs a proposer-solver env, but this env resolved to "
f"{type(env_config).__name__}. It compares solver attempts on the same proposed "
"problem and proposers across proposals. Use 'grpo' for a flat env or 'rae' for "
"multi-agent self-play."
)
class OPDAlgoConfig(BaseAlgoConfig):
type: Literal["opd"] = "opd"
"""On-policy distillation: the per-token signal is the reverse KL to
@@ -326,7 +367,14 @@ class SFTAlgoConfig(BaseAlgoConfig):
AlgoConfig: TypeAlias = Annotated[
GRPOAlgoConfig | EchoAlgoConfig | MaxRLAlgoConfig | RAEAlgoConfig | OPDAlgoConfig | OPSDAlgoConfig | SFTAlgoConfig,
GRPOAlgoConfig
| EchoAlgoConfig
| MaxRLAlgoConfig
| RAEAlgoConfig
| HierarchicalGRPOAlgoConfig
| OPDAlgoConfig
| OPSDAlgoConfig
| SFTAlgoConfig,
Field(discriminator="type"),
]
"""The training algorithm: sampling plus the per-token training signal (credit
@@ -336,6 +384,7 @@ its class defaults are the vetted setting.
- ``grpo`` — policy group sampling, group-relative advantage, RL loss (the default).
- ``max_rl`` — GRPO with mean-normalized advantages (maximum-likelihood RL).
- ``rae`` — reward minus a per-agent EMA baseline (SPIRAL), for multi-agent self-play envs.
- ``hierarchical_grpo`` — GRPO for proposer-solver envs: solvers are compared within one proposed problem and proposers across proposals. Needs ``episode_agents``.
- ``opd`` — on-policy distillation: policy samples, per-token reverse KL against a reference model. Needs ``teacher``.
- ``opsd`` — SDFT: policy samples, demo-conditioned reverse KL against the live policy (the teacher is the policy itself).
- ``sft`` — a frozen model samples, the policy trains with CE on its tokens. Needs a frozen ``sampling.source``.
@@ -1,9 +1,8 @@
import warnings
from pathlib import Path
from typing import Annotated, Any, Literal, TypeAlias
import verifiers.v1 as vf
from pydantic import AliasChoices, Field, model_validator
from pydantic import Field, SerializeAsAny, model_validator
from renderers import AutoRendererConfig, RendererConfig
from prime_rl.configs.algorithm import (
@@ -54,9 +53,7 @@ class TrainSamplingConfig(BaseConfig):
temperature: float = Field(1.0, ge=0, le=2.0)
"""Sampling temperature."""
max_completion_tokens: int | None = Field(
None, validation_alias=AliasChoices("max_completion_tokens", "max_tokens")
)
max_completion_tokens: int | None = None
"""Maximum output tokens per turn. If None, generates until max context length or EOS."""
# Strictly speaking, extra_body is not a sampling parameter, but it is the
@@ -79,18 +76,6 @@ class TrainSamplingConfig(BaseConfig):
return args
@model_validator(mode="before")
@classmethod
def _deprecate_max_tokens(cls, data: Any) -> Any:
if isinstance(data, dict) and "max_tokens" in data and "max_completion_tokens" not in data:
warnings.warn(
"'max_tokens' is deprecated, use 'max_completion_tokens' instead. "
"Auto-translating for now, but this will be removed in a future release.",
FutureWarning,
stacklevel=2,
)
return data
class EvalSamplingConfig(BaseConfig):
temperature: float | None = Field(None, ge=0, le=2.0)
@@ -105,9 +90,7 @@ class EvalSamplingConfig(BaseConfig):
min_p: float | None = Field(None, ge=0)
"""Min-p sampling threshold. None defers to the inference server default."""
max_completion_tokens: int | None = Field(
None, validation_alias=AliasChoices("max_completion_tokens", "max_tokens")
)
max_completion_tokens: int | None = None
"""Maximum output tokens per turn. None defers to the inference server default."""
reasoning_effort: Literal["minimal", "low", "medium", "high"] | None = None
@@ -138,40 +121,53 @@ class EvalSamplingConfig(BaseConfig):
return args
@model_validator(mode="before")
@classmethod
def _deprecate_max_tokens(cls, data: Any) -> Any:
if isinstance(data, dict) and "max_tokens" in data and "max_completion_tokens" not in data:
warnings.warn(
"'max_tokens' is deprecated, use 'max_completion_tokens' instead. "
"Auto-translating for now, but this will be removed in a future release.",
FutureWarning,
stacklevel=2,
)
return data
class EnvConfig(vf.EnvServerConfig):
name: str | None = None
"""Display name for this environment in logs, metrics, and buffer keys. Defaults to the taskset id. Must be unique across all envs in the same group."""
class ServingConfig(vf.ServingConfig):
"""Verifiers' serving block with ``address`` back to optional. Verifiers defaults it
to the address its own ``serve`` CLI binds; here the question is whether to spawn a
server or connect to one already running, and that answer has to survive the
resolved config being written to a file and read back — so it must be a *value*
(``None``), not field-set metadata, which a round-trip drops."""
address: str | None = None
"""ZMQ address of an external env server (e.g. ``tcp://host:5000``). When set, the orchestrator connects to this server instead of spawning one; when None, a subprocess env server is spawned automatically. The ``pool`` sizes the spawned server."""
"""ZMQ address of an external env server (e.g. ``tcp://host:5000``). When set, the orchestrator connects to that server instead of spawning one; when None, it spawns a subprocess env server on a free port. ``pool`` sizes the spawned server."""
class EnvConfig(BaseConfig):
"""One environment a run pulls from: the verifiers blocks it composes (``env`` — what
runs, ``serve`` — how it's hosted, ``legacy`` — a classic v0 env instead) plus this
orchestrator's own per-env knobs."""
env: SerializeAsAny[vf.EnvConfig] = vf.SingleAgentEnvConfig()
"""The verifiers environment — which env, its seed taskset, each agent, its knobs. Narrowed to the selected env's config class by the env id, else the taskset id."""
serve: ServingConfig = ServingConfig()
"""How the env server is run: ``serve.pool`` sizes the spawned server, ``serve.address`` points at an external one instead, and ``serve.max_concurrent`` bounds one worker's episodes in flight (unset = unbounded; the dispatcher's ``max_inflight_episodes`` is the run's bound)."""
legacy: vf.LegacyEnvConfig = vf.LegacyEnvConfig()
"""A classic (v0) environment to run through the bridge instead of ``env``."""
name: str | None = None
"""Display name for this environment in logs, metrics, and buffer keys. Defaults to the taskset id. Must be unique across all envs in the same group."""
ratio: float = Field(1.0, gt=0)
"""Sampling weight for this environment in the buffer. Relative weights are normalized to probabilities across envs (e.g. [1, 1] and [0.5, 0.5] are equivalent). Defaults to 1, i.e. equal weight per env."""
@model_validator(mode="before")
@classmethod
def _migrate_num_workers(cls, data):
"""Back-compat: the removed ``num_workers`` maps onto ``pool`` — an int becomes a
fixed ``static`` pool, ``"auto"`` falls through to the default ``elastic`` pool. An
explicit ``pool`` always wins."""
if isinstance(data, dict) and "num_workers" in data:
num_workers = data.pop("num_workers")
if "pool" not in data and num_workers != "auto":
data["pool"] = {"type": "static", "num_workers": num_workers}
return data
def _resolve_env(cls, data):
"""Narrow ``env`` to the selected env's config class."""
return vf.resolve_env_field(data, vf.narrowed_env_annotation(cls))
@property
def is_legacy(self) -> bool:
"""A classic (v0) env run through the bridge: a legacy id and no v1 taskset."""
return self.legacy.id is not None and not self.env.taskset.id
@property
def env_id(self) -> str:
"""The env's identifier: the v1 env's, else the v0 env id."""
return self.env.env_id or self.legacy.id or ""
@property
def resolved_name(self) -> str:
@@ -179,9 +175,24 @@ class EnvConfig(vf.EnvServerConfig):
@model_validator(mode="after")
def validate_env(self):
# A v0 id next to any v1 env identity leaves one of the two going nowhere, and
# which one depends on `is_legacy`: a taskset makes it False, so the v0 env never
# loads; a bare `env.id` leaves it True, so the v0 env runs under the v1 name.
if self.legacy.id is not None and self.env.env_id:
if self.env.taskset.id:
raise ValueError(
f"legacy.id {self.legacy.id!r} is a classic (v0) env and can't combine with "
f"the v1 taskset {self.env.taskset.id!r}. Pairing a reusable env with a taskset "
f"is env.id = {self.legacy.id!r}; to run the v0 env instead, drop the taskset."
)
raise ValueError(
f"legacy.id {self.legacy.id!r} is a classic (v0) env and can't combine with the "
f"v1 env.id {self.env.id!r}: the v0 env is what would run, stamped with the v1 "
"env's name. Keep whichever one you meant to run."
)
if not self.env_id:
raise ValueError(
'no env configured — set env = { taskset = { id = "<id>" } } (v1) or id = "<id>" (v0/legacy)'
'no env configured — set env = { taskset = { id = "<id>" } } (v1) or legacy = { id = "<id>" } (v0)'
)
if self.resolved_name == "agg":
raise ValueError(
@@ -192,25 +203,25 @@ class EnvConfig(vf.EnvServerConfig):
@model_validator(mode="after")
def resolve_legacy_env_kwargs(self):
"""For a v0/legacy env, surface the v1 knobs the legacy bridge applies via
``extra_env_kwargs`` (``env.set_kwargs(...)``): the per-rollout wall-clock timeout and
the multi-turn completion-token budget, read off ``env.agent``. (``max_seq_len`` is
added per train run in ``OrchestratorConfig.resolve_env_config``, which knows
``seq_len``.)"""
``legacy.extra_env_kwargs`` (``env.set_kwargs(...)``): the per-rollout wall-clock
timeout and the multi-turn completion-token budget, read off ``env.agent``.
(``max_seq_len`` is added per train run in ``OrchestratorConfig.resolve_env_config``,
which knows ``seq_len``.)"""
if self.is_legacy:
agent = getattr(self.env, "agent", None)
if agent is not None:
if agent.timeout.rollout is not None:
self.extra_env_kwargs["timeout_seconds"] = agent.timeout.rollout
self.legacy.extra_env_kwargs["timeout_seconds"] = agent.timeout.rollout
if agent.max_output_tokens is not None:
self.extra_env_kwargs["max_total_completion_tokens"] = agent.max_output_tokens
self.legacy.extra_env_kwargs["max_total_completion_tokens"] = agent.max_output_tokens
return self
class TrainEnvConfig(EnvConfig):
class TrainSourceConfig(EnvConfig):
sampling: TrainSamplingConfig = TrainSamplingConfig()
"""Per-env sampling overrides. Unset fields inherit from the group-level train sampling config."""
group_size: int = Field(1, ge=1, validation_alias=AliasChoices("group_size", "rollouts_per_example"))
group_size: int = Field(1, ge=1)
"""Rollouts generated per example for GRPO group-relative advantages.
Inherits from ``orchestrator.group_size`` when unset."""
@@ -220,14 +231,14 @@ class TrainEnvConfig(EnvConfig):
this env its own algorithm."""
class EvalEnvConfig(EnvConfig):
class EvalSourceConfig(EnvConfig):
sampling: EvalSamplingConfig = EvalSamplingConfig()
"""Per-env sampling overrides. Unset fields inherit from the group-level eval sampling config."""
num_examples: int = -1
"""Eval examples to sample from the dataset. ``-1`` uses all available examples."""
group_size: int = Field(1, ge=1, validation_alias=AliasChoices("group_size", "rollouts_per_example"))
group_size: int = Field(1, ge=1)
"""Rollouts generated per example. Used for pass@k estimation (e.g. ``group_size=8`` enables pass@1 through pass@8)."""
interval: int = Field(100, ge=1)
@@ -235,8 +246,8 @@ class EvalEnvConfig(EnvConfig):
class TrainConfig(BaseConfig):
env: list[TrainEnvConfig] = Field(default_factory=list)
"""Training environments."""
source: list[TrainSourceConfig] = Field(default_factory=list)
"""Training sources."""
sampling: TrainSamplingConfig = TrainSamplingConfig()
"""Shared training sampling configuration."""
@@ -246,7 +257,7 @@ class TrainConfig(BaseConfig):
"""Resolve per-env overrides: inherit group-level sampling (the worker ``pool``
is configured per env, defaulting to elastic)."""
group_sampling = self.sampling.model_dump()
for env in self.env:
for env in self.source:
if "sampling" not in env.model_fields_set:
env.sampling = TrainSamplingConfig(**group_sampling)
else:
@@ -256,7 +267,7 @@ class TrainConfig(BaseConfig):
@model_validator(mode="after")
def validate_unique_env_names(self):
env_names = [env.resolved_name for env in self.env]
env_names = [env.resolved_name for env in self.source]
duplicates = [n for n in env_names if env_names.count(n) > 1]
if duplicates:
raise ValueError(
@@ -266,8 +277,8 @@ class TrainConfig(BaseConfig):
class EvalConfig(BaseConfig):
env: list[EvalEnvConfig] = Field(default_factory=list)
"""Evaluation environments."""
source: list[EvalSourceConfig] = Field(default_factory=list)
"""Evaluation sources."""
sampling: EvalSamplingConfig = Field(default_factory=EvalSamplingConfig)
"""Shared eval sampling configuration; can differ from training sampling."""
@@ -275,7 +286,7 @@ class EvalConfig(BaseConfig):
num_examples: int = -1
"""Default eval examples per environment. ``-1`` uses all. Can be overridden per env."""
group_size: int = Field(1, ge=1, validation_alias=AliasChoices("group_size", "rollouts_per_example"))
group_size: int = Field(1, ge=1)
"""Default rollouts per example. Can be overridden per env."""
interval: int = Field(100, ge=1)
@@ -290,33 +301,33 @@ class EvalConfig(BaseConfig):
"""Resolve per-env overrides: inherit group-level sampling, num_examples,
group_size, and interval (the worker ``pool`` is configured per env, default elastic)."""
group_sampling = self.sampling.model_dump()
for env in self.env:
if "sampling" not in env.model_fields_set:
env.sampling = EvalSamplingConfig(**group_sampling)
for source in self.source:
if "sampling" not in source.model_fields_set:
source.sampling = EvalSamplingConfig(**group_sampling)
else:
merged = group_sampling | env.sampling.model_dump(exclude_unset=True)
env.sampling = EvalSamplingConfig(**merged)
if "num_examples" not in env.model_fields_set:
env.num_examples = self.num_examples
if "group_size" not in env.model_fields_set:
env.group_size = self.group_size
if "interval" not in env.model_fields_set:
env.interval = self.interval
merged = group_sampling | source.sampling.model_dump(exclude_unset=True)
source.sampling = EvalSamplingConfig(**merged)
if "num_examples" not in source.model_fields_set:
source.num_examples = self.num_examples
if "group_size" not in source.model_fields_set:
source.group_size = self.group_size
if "interval" not in source.model_fields_set:
source.interval = self.interval
return self
@model_validator(mode="after")
def validate_non_empty_envs(self):
if not self.env:
def validate_non_empty_sources(self):
if not self.source:
raise ValueError(
"EvalConfig must define at least one env. Either drop the "
"EvalConfig must define at least one source. Either drop the "
"[orchestrator.eval] block entirely (to disable eval) or "
"add a [[orchestrator.eval.env]] block."
"add a [[orchestrator.eval.source]] block."
)
return self
@model_validator(mode="after")
def validate_unique_env_names(self):
env_names = [env.resolved_name for env in self.env]
env_names = [source.resolved_name for source in self.source]
duplicates = [n for n in env_names if env_names.count(n) > 1]
if duplicates:
raise ValueError(
@@ -437,7 +448,7 @@ class OrchestratorConfig(BaseConfig):
algo: AlgoConfig = GRPOAlgoConfig()
"""Training algorithm: sampling plus the per-token training signal (credit
assignment and loss routing, fused — its ``type`` names the algorithm).
Defaults to ``grpo``. Override per env via ``[[orchestrator.train.env]]``'s
Defaults to ``grpo``. Override per source via ``[[orchestrator.train.source]]``'s
``algo``."""
model: ModelConfig = ModelConfig()
@@ -525,12 +536,12 @@ class OrchestratorConfig(BaseConfig):
"""Tokens to train on per step (token-based batching). Set this OR ``batch_size``."""
oversampling_factor: float | None = Field(None, gt=0)
"""Rollout-mode batching only. Multiplier used to derive ``max_inflight_rollouts`` from ``batch_size`` when ``max_inflight_rollouts`` is unset. Values below 1.0 intentionally cap in-flight rollout capacity below ``batch_size``."""
"""Rollout-mode batching only. Multiplier used to derive ``max_inflight_episodes`` from ``batch_size`` when ``max_inflight_episodes`` is unset. Values below 1.0 intentionally cap in-flight episode capacity below ``batch_size``."""
max_inflight_rollouts: int | None = Field(None, ge=1)
"""Maximum number of rollouts kept in-flight. Required for token-based batching. With ``batch_size`` set, defaults to ``batch_size * oversampling_factor`` (or ``batch_size`` when ``oversampling_factor`` is unset)."""
max_inflight_episodes: int | None = Field(None, ge=1)
"""Maximum number of episodes kept in-flight — one episode is one agent run at a time, whatever the env's agents are. Required for token-based batching. With ``batch_size`` set, defaults to ``batch_size * oversampling_factor`` (or ``batch_size`` when ``oversampling_factor`` is unset)."""
group_size: int = Field(1, ge=1, validation_alias=AliasChoices("group_size", "rollouts_per_example"))
group_size: int = Field(1, ge=1)
"""Output sequences returned per example during training."""
seq_len: int = 2048
@@ -552,33 +563,6 @@ class OrchestratorConfig(BaseConfig):
heartbeat: HeartbeatConfig | None = None
"""BetterStack heartbeat configuration for monitoring training progress."""
@model_validator(mode="before")
@classmethod
def _env_to_train(cls, data: Any) -> Any:
"""Allow [[env]] and [sampling] as shorthand for [train] with [[train.env]] and [train.sampling]."""
if not isinstance(data, dict):
return data
if "env" in data or "sampling" in data:
train = data.setdefault("train", {})
if isinstance(train, dict):
if "env" in data:
warnings.warn(
"'[[orchestrator.env]]' is deprecated, use '[[orchestrator.train.env]]' instead. "
"Auto-translating for now, but this will be removed in a future release.",
FutureWarning,
stacklevel=2,
)
train.setdefault("env", data.pop("env"))
if "sampling" in data:
warnings.warn(
"'[orchestrator.sampling]' is deprecated, use '[orchestrator.train.sampling]' instead. "
"Auto-translating for now, but this will be removed in a future release.",
FutureWarning,
stacklevel=2,
)
train.setdefault("sampling", data.pop("sampling"))
return data
@model_validator(mode="after")
def auto_setup_tokenizer(self):
if self.tokenizer.name is None:
@@ -617,15 +601,23 @@ class OrchestratorConfig(BaseConfig):
def inherit_env_algorithms(self):
"""Envs without their own algorithm inherit the top-level one.
Declared before any validator that reads ``algo``."""
for env_cfg in self.train.env:
for env_cfg in self.train.source:
if env_cfg.algo is None:
env_cfg.algo = self.algo.model_copy(deep=True)
return self
@model_validator(mode="after")
def validate_env_algorithms(self):
"""Let each algorithm reject environments it cannot score correctly."""
for env_cfg in self.train.source:
assert env_cfg.algo is not None # resolved by inherit_env_algorithms
env_cfg.algo.validate_env(env_cfg.env)
return self
@property
def any_policy_sourced(self) -> bool:
"""True when at least one train env samples rollouts from the live policy."""
return any(env.algo is not None and env.algo.sampling.source == "policy" for env in self.train.env)
return any(env.algo is not None and env.algo.sampling.source == "policy" for env in self.train.source)
@model_validator(mode="after")
def validate_pool_size(self):
@@ -691,29 +683,29 @@ class OrchestratorConfig(BaseConfig):
if has_token_batch:
if self.oversampling_factor is not None:
raise ValueError("oversampling_factor can only be set when batch_size is set")
if self.max_inflight_rollouts is None:
raise ValueError("max_inflight_rollouts must be set when token_batch_size is set")
if self.max_inflight_episodes is None:
raise ValueError("max_inflight_episodes must be set when token_batch_size is set")
else:
assert self.batch_size is not None
if self.batch_size % self.group_size != 0:
raise ValueError("Batch size must be divisible by the number of samples per problem")
oversampling_factor = self.oversampling_factor if self.oversampling_factor is not None else 1.0
resolved_max_inflight_rollouts = max(
resolved_max_inflight_episodes = max(
self.group_size,
int(self.batch_size * oversampling_factor),
)
if self.max_inflight_rollouts is not None and self.oversampling_factor is not None:
expected_max_inflight_rollouts = resolved_max_inflight_rollouts
if self.max_inflight_rollouts != expected_max_inflight_rollouts:
raise ValueError("max_inflight_rollouts conflicts with oversampling_factor * batch_size")
if self.max_inflight_rollouts is None:
self.max_inflight_rollouts = resolved_max_inflight_rollouts
if self.max_inflight_episodes is not None and self.oversampling_factor is not None:
expected_max_inflight_episodes = resolved_max_inflight_episodes
if self.max_inflight_episodes != expected_max_inflight_episodes:
raise ValueError("max_inflight_episodes conflicts with oversampling_factor * batch_size")
if self.max_inflight_episodes is None:
self.max_inflight_episodes = resolved_max_inflight_episodes
if self.max_inflight_rollouts is not None and self.max_inflight_rollouts < self.group_size:
raise ValueError("max_inflight_rollouts must be at least the number of rollouts per example")
if self.max_inflight_episodes is not None and self.max_inflight_episodes < self.group_size:
raise ValueError("max_inflight_episodes must be at least the number of rollouts per example")
# Propagate the top-level ``group_size`` into each train env that didn't set its own.
for env_cfg in self.train.env:
for env_cfg in self.train.source:
if "group_size" not in env_cfg.model_fields_set:
env_cfg.group_size = self.group_size
@@ -736,7 +728,7 @@ class OrchestratorConfig(BaseConfig):
@model_validator(mode="after")
def resolve_env_config(self):
"""Set vLLM sampling defaults + legacy env kwargs on each train env from top-level fields."""
for env in self.train.env:
for env in self.train.source:
# Policy-sourced rollouts hit our vLLM server; frozen-sourced
# rollouts may hit external OAI endpoints that reject these knobs.
assert env.algo is not None
@@ -746,6 +738,6 @@ class OrchestratorConfig(BaseConfig):
env.sampling.extra_body.setdefault("return_token_ids", True)
if env.is_legacy:
# v0 env: cap per-turn response tokens to the training budget (the legacy
# bridge applies extra_env_kwargs via env.set_kwargs).
env.extra_env_kwargs["max_seq_len"] = self.seq_len
# bridge applies legacy.extra_env_kwargs via env.set_kwargs).
env.legacy.extra_env_kwargs["max_seq_len"] = self.seq_len
return self
+1 -1
View File
@@ -33,7 +33,7 @@ dependencies = [
"setproctitle>=1.3.0",
"uvloop>=0.21.0",
"torchtitan",
"verifiers[harbor]>=0.2.1",
"verifiers[harbor]>=0.2.2.dev43",
"renderers",
"dion",
"tilelang>=0.1.8",
+10 -4
View File
@@ -30,7 +30,7 @@ uv run rl @ rl.toml --dry-run --output-dir /tmp/x # write resolved TOML to /tmp/
## Validators
Incompatible combinations (e.g. CP requires flash attention) must raise in a `model_validator` at resolve time, not at runtime. When renaming a field, emit a deprecation warning with a migration hint — never silently drop.
Incompatible combinations (e.g. CP requires flash attention) must raise in a `model_validator` at resolve time, not at runtime. When renaming a field, remove the old spelling: no `validation_alias`, no auto-translating `mode="before"` validator. The old key then fails as an unknown key, which is the signal. An alias that stays forever is worse than a break — it never gets retired, and a key whose *meaning* changed silently misconfigures the run.
## Special syntax
@@ -41,20 +41,26 @@ Incompatible combinations (e.g. CP requires flash attention) must raise in a `mo
**Lists** — TOML uses array of tables; later config files replace lists wholesale, so overlays must include the full desired list:
```toml
[[orchestrator.train.env]]
[[orchestrator.train.source]]
name = "reverse-text"
env.taskset = { id = "reverse-text-v1" }
env.agent.harness = { id = "null" }
env.agent.runtime = { type = "subprocess" }
[[orchestrator.eval.source]]
name = "reverse-text-eval"
env.taskset = { id = "reverse-text-v1", split = "test" }
env.agent.harness = { id = "null" }
env.agent.runtime = { type = "subprocess" }
```
CLI: `--orchestrator.train.env.0.env.taskset.id reverse-text-v1`.
CLI: `--orchestrator.train.source.0.env.taskset.id reverse-text-v1` or `--orchestrator.eval.source.0.env.taskset.id reverse-text-v1`.
**Dicts** — TOML uses a section; CLI takes a JSON string: `--vllm-extra '{"key1": "value1"}'`. This works for plain `dict` fields only — nested pydantic-model fields (e.g. `algo`) reject JSON strings; use dotted keys (`--orchestrator.algo.type max_rl`) or a TOML overlay file.
**Discriminated unions** — set the `type` field to pick the variant (`[orchestrator.algo] type = "max_rl"`). Omit `type` to keep the default variant.
**Algorithms** — `[orchestrator.algo] type = "grpo" | "max_rl" | "rae" | "opd" | "opsd" | "sft" | "echo"` — the type names the algorithm (credit assignment + loss routing, fused), and each type's class defaults are its vetted setting; any other key you set is your own assembly (e.g. `[orchestrator.algo.roles.user] alpha = 0.1` for echo — setting any echo role replaces the whole role table). There is no preset layer, and no config hook that points at user code — a new algorithm is a named class in the repo (subclass `Algorithm`, register it). Per-env override: `[orchestrator.train.env.algo] type = "opd"` (the env assembles its own algorithm). prime-rl only hosts the trainable policy; frozen models are inline external endpoints on the algorithm, named where the model is used — `[orchestrator.algo.teacher]` for opd (the frozen model scored against), `[orchestrator.algo.sampling.source]` for sft (the model it samples from), each with `name` + `base_url`. There is no shared `teacher` slot. opsd declares no model — it self-distills against the live policy. See `docs/algorithms.md`.
**Algorithms** — `[orchestrator.algo] type = "grpo" | "max_rl" | "rae" | "hierarchical_grpo" | "opd" | "opsd" | "sft" | "echo"` — the type names the algorithm (credit assignment + loss routing, fused), and each type's class defaults are its vetted setting; any other key you set is your own assembly (e.g. `[orchestrator.algo.roles.user] alpha = 0.1` for echo — setting any echo role replaces the whole role table). `hierarchical_grpo` is only valid with a proposer-solver env: it compares solvers with attempts on the same proposed problem and proposers with other proposals in the group. There is no preset layer, and no config hook that points at user code — a new algorithm is a named class in the repo (subclass `Algorithm`, register it). Per-source override: `[orchestrator.train.source.algo] type = "opd"` (the source assembles its own algorithm). prime-rl only hosts the trainable policy; frozen models are inline external endpoints on the algorithm, named where the model is used — `[orchestrator.algo.teacher]` for opd (the frozen model scored against), `[orchestrator.algo.sampling.source]` for sft (the model it samples from), each with `name` + `base_url`. There is no shared `teacher` slot. opsd declares no model — it self-distills against the live policy. See `docs/algorithms.md`.
**`BaseModel | None` fields** — bare flag enables defaults; nested override enables and sets:
+6 -6
View File
@@ -93,13 +93,13 @@ All metrics print to the console log (and W&B when configured).
| Metric | Description |
|--------|-------------|
| `train/agg/all/reward/mean` | mean training reward (per env: `train/<env>/all/reward/mean`) |
| `train/agg/all/num_total_tokens/mean` | avg tokens per rollout (also `num_input_tokens`, `num_output_tokens`) |
| `train/agg/all/num_turns/mean` | avg turns per rollout (multi-turn only) |
| `train/agg/all/is_truncated/mean` | fraction truncated |
| `train/agg/effective/reward/mean` | mean training reward (per env: `train/<env>/effective/reward/mean`) |
| `train/agg/effective/num_total_tokens/mean` | avg tokens per rollout (also `num_input_tokens`, `num_output_tokens`) |
| `train/agg/effective/num_turns/mean` | avg turns per rollout (multi-turn only) |
| `train/agg/effective/is_truncated/mean` | fraction truncated |
| `train/agg/all/has_error/mean` | fraction errored (per-type under `train/agg/all/error/<type>`; also `dispatcher/errored/{train,eval}`) |
| `train/<env>/all/metrics/<name>/mean` | env-specific metrics (e.g. pass rate) |
| `eval/<env>/all/{avg@k,pass@k}` | eval scores when configured |
| `train/<env>/effective/metrics/<name>/mean` | env-specific metrics (e.g. pass rate) |
| `eval/<env>/effective/{avg@k,pass@k}` | eval scores when configured |
**Stability** — trainer log:
+10 -6
View File
@@ -205,9 +205,9 @@ def rl_local(config: RLConfig):
)
frozen_endpoints: list[str] = []
for env in config.orchestrator.train.env:
for env in config.orchestrator.train.source:
algo = env.algo
assert algo is not None, "TrainEnvConfig.algo must be resolved before launch (inherit_env_algorithms)"
assert algo is not None, "TrainSourceConfig.algo must be resolved before launch (inherit_env_algorithms)"
for ref in (algo.sampling.source, getattr(algo, "teacher", None)):
if isinstance(ref, FrozenModelConfig):
frozen_endpoints.append(f"{ref.name} ({', '.join(ref.base_url)})")
@@ -487,8 +487,10 @@ def rl_slurm(config: RLConfig):
write_config(config, config_dir, exclude={"slurm", "dry_run", "clean_output_dir"})
logger.info(f"Wrote config to {config_dir / RL_TOML}")
train_env_names = [env.resolved_name for env in config.orchestrator.train.env]
eval_env_names = [env.resolved_name for env in config.orchestrator.eval.env] if config.orchestrator.eval else []
train_env_names = [env.resolved_name for env in config.orchestrator.train.source]
eval_env_names = (
[source.resolved_name for source in config.orchestrator.eval.source] if config.orchestrator.eval else []
)
log_message = format_log_message(
log_dir=log_dir,
@@ -502,8 +504,10 @@ def rl_slurm(config: RLConfig):
write_subconfigs(config, config_dir)
logger.info(f"Wrote subconfigs to {config_dir}")
train_env_names = [env.resolved_name for env in config.orchestrator.train.env]
eval_env_names = [env.resolved_name for env in config.orchestrator.eval.env] if config.orchestrator.eval else []
train_env_names = [env.resolved_name for env in config.orchestrator.train.source]
eval_env_names = (
[source.resolved_name for source in config.orchestrator.eval.source] if config.orchestrator.eval else []
)
has_infer = config.deployment.infer_nodes_per_replica > 0
log_message = format_log_message(
+6 -2
View File
@@ -5,8 +5,9 @@ is — a bundle of sampling and the per-token training signal. This package
turns the signal half into runtime objects (the sampling half is the env's
:class:`~prime_rl.orchestrator.sampler.Sampler`):
- one module per algorithm (``grpo``, ``echo``, ``max_rl``, ``rae``, ``opd``,
``opsd``, ``sft``) — each named class owns its scoring hooks
- one module per algorithm (``grpo``, ``echo``, ``max_rl``, ``rae``,
``hierarchical_grpo``, ``opd``, ``opsd``, ``sft``) — each named class owns
its scoring hooks
(``score_rollout`` / ``score_group``) and declares what it needs (loss
component, a "teacher", ...). One instance per env, built by
:func:`build_algorithm`. A new credit-assignment scheme is a new named class:
@@ -31,6 +32,7 @@ from typing import TYPE_CHECKING
from prime_rl.orchestrator.algo.base import Algorithm, connect_frozen_pool
from prime_rl.orchestrator.algo.echo import EchoAlgorithm
from prime_rl.orchestrator.algo.grpo import GRPOAlgorithm
from prime_rl.orchestrator.algo.hierarchical_grpo import HierarchicalGRPOAlgorithm
from prime_rl.orchestrator.algo.max_rl import MaxRLAlgorithm
from prime_rl.orchestrator.algo.opd import OPDAlgorithm
from prime_rl.orchestrator.algo.opsd import OPSDAlgorithm
@@ -50,6 +52,7 @@ ALGORITHM_CLASSES: dict[str, type[Algorithm]] = {
"echo": EchoAlgorithm,
"max_rl": MaxRLAlgorithm,
"rae": RAEAlgorithm,
"hierarchical_grpo": HierarchicalGRPOAlgorithm,
"opd": OPDAlgorithm,
"opsd": OPSDAlgorithm,
"sft": SFTDistillAlgorithm,
@@ -71,6 +74,7 @@ __all__ = [
"Algorithm",
"EchoAlgorithm",
"GRPOAlgorithm",
"HierarchicalGRPOAlgorithm",
"MaxRLAlgorithm",
"OPDAlgorithm",
"OPSDAlgorithm",
@@ -0,0 +1,40 @@
from __future__ import annotations
from collections import defaultdict
from typing import TYPE_CHECKING
from prime_rl.configs.algorithm import HierarchicalGRPOAlgoConfig
from prime_rl.orchestrator.algo.base import Algorithm
if TYPE_CHECKING:
from prime_rl.orchestrator.types import Rollout
from prime_rl.utils.client import InferencePool
class HierarchicalGRPOAlgorithm(Algorithm):
"""GRPO for proposer-solver envs.
Solver rewards are compared only with other attempts on the same proposed
problem. Proposer rewards are compared with the other proposals generated
from the same source task. Keeping those comparisons separate avoids
treating different problem difficulties or different agent roles as
interchangeable.
``episode_agents`` lists the roles, normally ``solver``, that are compared
within one episode. Other roles are compared across the full rollout group.
A comparison group with one trace produces zero advantage."""
def __init__(self, config: HierarchicalGRPOAlgoConfig, policy_pool: InferencePool):
super().__init__(config, policy_pool)
self.episode_agents = set(config.episode_agents)
async def score_group(self, group: list[Rollout]) -> None:
peers: dict[tuple[str | None, str | None], list[Rollout]] = defaultdict(list)
for rollout in group:
episode_scoped = rollout.agent_name in self.episode_agents
key = (rollout.agent_name, rollout.episode_id if episode_scoped else None)
peers[key].append(rollout)
for members in peers.values():
baseline = sum(rollout.reward for rollout in members) / len(members)
for rollout in members:
rollout.assign_advantages(rollout.reward - baseline)
+6 -4
View File
@@ -1,7 +1,9 @@
"""RolloutDispatcher: schedules rollouts under a shared permit counter.
- Capacity (``max_inflight_rollouts``) is shared across train + eval.
A group-scoring task that runs N rollouts in one call reserves N permits.
- Capacity (``max_inflight_episodes``) is shared across train + eval. One permit is
one episode: for a v1 env one ``run`` request, and a group-scoring task that runs
N rollouts in one call reserves N permits (each bridged v0 rollout is its own
single-agent episode).
- Optional rate limiting via ``AsyncLimiter(tasks_per_minute, 60)``.
- Emit-everything invariant: every dispatched env-rollout eventually reaches
``out_q`` exactly once, as one episode (a ``list[Rollout]``). Failures
@@ -129,7 +131,7 @@ class RolloutDispatcher:
eval_source: EvalSource | None,
policy_pool: InferencePool,
policy: Policy,
max_inflight_rollouts: int,
max_inflight_episodes: int,
tasks_per_minute: float | None,
max_off_policy_steps: int,
) -> None:
@@ -143,7 +145,7 @@ class RolloutDispatcher:
self.eval_source = eval_source
self.max_off_policy_steps = max_off_policy_steps
self.max_inflight = max_inflight_rollouts
self.max_inflight = max_inflight_episodes
self.inflight_permits = 0
self.rate_limiter: AsyncLimiter | None = (
AsyncLimiter(tasks_per_minute, time_period=60) if tasks_per_minute else None
@@ -13,18 +13,18 @@ from prime_rl.utils.utils import clean_exit
@clean_exit
def run_server(config: EnvServerConfig):
env = config.env
address = env.address or "tcp://127.0.0.1:5000"
# The env's ``pool`` (static or elastic) sizes the server; a v0/legacy env runs through
address = env.serve.address or "tcp://127.0.0.1:5000"
# The env's ``serve.pool`` (static or elastic) sizes the server; a v0/legacy env runs through
# the bridge, a v1 env is a native env block — both speak the same serve protocol,
# so the orchestrator is agnostic. serve_env applies the logging setup in this process
# and in every spawned worker.
server_kwargs = (
{"env_id": env.env_id, "env_args": env.args, "extra_env_kwargs": env.extra_env_kwargs}
{"env_id": env.env_id, "env_args": env.legacy.args, "extra_env_kwargs": env.legacy.extra_env_kwargs}
if env.is_legacy
else {"config_data": env_config_data(env.env)}
else {"config_data": env_config_data(env.env), "max_concurrent": env.serve.max_concurrent}
)
serve_env(
**pool_serve_kwargs(env.pool),
**pool_serve_kwargs(env.serve.pool),
legacy=env.is_legacy,
address=address,
log_setup=partial(setup_env_server_logging, config.log.level, config.log.json_logging),
+21 -15
View File
@@ -1,7 +1,7 @@
"""Env wrappers over a v1 env server.
Each ``Env`` owns a v1 ``EnvServer`` (spawned as a child process, or an
external one given by ``config.address``) and an ``EnvClient`` to drive it. The
external one pinned by ``config.serve.address``) and an ``EnvClient`` to drive it. The
orchestrator never *runs* an environment — the agents and their runtimes live only
in the server — but it does own the *taskset*: a v1 env's tasks are loaded here,
once, and each dispatched env-rollout ships its task's data on the request
@@ -34,7 +34,7 @@ from typing import Generic, TypeVar
import verifiers.v1 as vf
from verifiers.v1.serve import EnvClient, env_config_data
from prime_rl.configs.orchestrator import EnvConfig, EvalEnvConfig, TrainEnvConfig
from prime_rl.configs.orchestrator import EnvConfig, EvalSourceConfig, TrainSourceConfig
from prime_rl.orchestrator.algo import Algorithm, build_algorithm
from prime_rl.orchestrator.sampler import Sampler
from prime_rl.orchestrator.types import Rollout
@@ -112,8 +112,8 @@ class Env:
async def start(self, log_dir: Path, log_level: str | None = None, json_logging: bool = False) -> None:
"""Spawn the env server (if needed), connect, and load the taskset client-side
(legacy instead asks the server for ``info`` — its dataset is server-side)."""
external = self.config.address is not None
address = self.config.address or await self._spawn(log_dir, log_level or "INFO", json_logging)
external = self.config.serve.address is not None
address = self.config.serve.address or await self._spawn(log_dir, log_level or "INFO", json_logging)
get_logger().debug(f"Connecting {self.name} to env server {address}")
self._env_client = EnvClient(address=address)
# A spawned server already reported its address *after* binding, so it's up. An
@@ -152,12 +152,18 @@ class Env:
dict(
legacy=True,
env_id=self.config.env_id,
env_args=self.config.args,
extra_env_kwargs=self.config.extra_env_kwargs,
env_args=self.config.legacy.args,
extra_env_kwargs=self.config.legacy.extra_env_kwargs,
)
if self.config.is_legacy
# Picklable dict — the narrowed config class doesn't survive the spawn.
else dict(legacy=False, config_data=env_config_data(self.config.env))
# ``max_concurrent`` bounds this worker's episodes in flight — usually unset,
# since the dispatcher's ``max_inflight_episodes`` is the run's bound.
else dict(
legacy=False,
config_data=env_config_data(self.config.env),
max_concurrent=self.config.serve.max_concurrent,
)
)
process = ctx.Process(
target=_run_env_server,
@@ -165,7 +171,7 @@ class Env:
log_file=str(log_file),
log_level=log_level,
json_logging=json_logging,
**vf.pool_serve_kwargs(self.config.pool),
**vf.pool_serve_kwargs(self.config.serve.pool),
address="tcp://127.0.0.1:0",
address_queue=address_queue,
**server_kwargs,
@@ -246,9 +252,9 @@ class Env:
class TrainEnv(Env):
config: TrainEnvConfig
config: TrainSourceConfig
def __init__(self, config: TrainEnvConfig, sampler: Sampler, algorithm: Algorithm):
def __init__(self, config: TrainSourceConfig, sampler: Sampler, algorithm: Algorithm):
super().__init__(config)
self.sampler = sampler
self.algorithm = algorithm
@@ -256,9 +262,9 @@ class TrainEnv(Env):
class EvalEnv(Env):
config: EvalEnvConfig
config: EvalSourceConfig
def __init__(self, config: EvalEnvConfig):
def __init__(self, config: EvalSourceConfig):
super().__init__(config)
self.sampling_args = config.sampling.to_sampling_args()
self.examples: list[dict] = []
@@ -333,10 +339,10 @@ class TrainEnvs(Envs[TrainEnv]):
:class:`Sampler` and runtime :class:`Algorithm`, built from the env's
resolved algorithm config."""
def __init__(self, configs: Sequence[TrainEnvConfig], *, policy_pool, renderer_config=None):
def __init__(self, configs: Sequence[TrainSourceConfig], *, policy_pool, renderer_config=None):
self._envs: dict[str, TrainEnv] = {}
for config in configs:
assert config.algo is not None, "TrainEnvConfig.algo must be resolved before env construction"
assert config.algo is not None, "TrainSourceConfig.algo must be resolved before env construction"
env = TrainEnv(
config,
Sampler(config.algo.sampling, policy_pool, renderer_config),
@@ -348,7 +354,7 @@ class TrainEnvs(Envs[TrainEnv]):
class EvalEnvs(Envs[EvalEnv]):
"""Collection of evaluation environments."""
def __init__(self, configs: Sequence[EvalEnvConfig]):
def __init__(self, configs: Sequence[EvalSourceConfig]):
self._envs: dict[str, EvalEnv] = {}
for config in configs:
env = EvalEnv(config)
+20 -20
View File
@@ -156,7 +156,7 @@ class Orchestrator:
# Route the in-process v1 library logging through our handler. The
# env server runs in a child process, so its logging is separate.
intercept_vf_logging(logger="verifiers.v1", level="WARN")
algorithms = sorted({env.algo.type for env in config.train.env if env.algo is not None})
algorithms = sorted({env.algo.type for env in config.train.source if env.algo is not None})
get_logger().info(f"Starting orchestrator (algorithm: {', '.join(algorithms)})")
if config.bench:
@@ -238,8 +238,8 @@ class Orchestrator:
tokenizer=self.tokenizer,
run_config=config,
keep_full_history=config.bench,
train_env_names=[env.resolved_name for env in config.train.env],
eval_env_names=[env.resolved_name for env in config.eval.env] if config.eval is not None else [],
train_env_names=[env.resolved_name for env in config.train.source],
eval_env_names=[source.resolved_name for source in config.eval.source] if config.eval is not None else [],
)
if config.heartbeat is not None:
@@ -256,7 +256,7 @@ class Orchestrator:
get_logger().info("Loading training environments")
self.train_envs = TrainEnvs(
config.train.env, policy_pool=self.policy_inference, renderer_config=config.renderer
config.train.source, policy_pool=self.policy_inference, renderer_config=config.renderer
)
get_logger().debug(
f"Loaded {len(self.train_envs)} training environment(s) ({', '.join(self.train_envs.names)})"
@@ -270,7 +270,7 @@ class Orchestrator:
if config.eval is not None:
get_logger().info("Loading eval environment(s)")
self.eval_envs = EvalEnvs(config.eval.env)
self.eval_envs = EvalEnvs(config.eval.source)
get_logger().debug(f"Loaded {len(self.eval_envs)} eval environment(s) ({', '.join(self.eval_envs.names)})")
await self.eval_envs.start(
log_dir=get_log_dir(config.output_dir.parent) / "envs" / "eval",
@@ -391,7 +391,7 @@ class Orchestrator:
else None
)
assert config.max_inflight_rollouts is not None, "max_inflight_rollouts must be resolved before dispatcher init"
assert config.max_inflight_episodes is not None, "max_inflight_episodes must be resolved before dispatcher init"
log_interval = config.log.interval
wandb_enabled = config.wandb is not None
self.dispatcher = RolloutDispatcher(
@@ -401,7 +401,7 @@ class Orchestrator:
eval_source=self.eval_source,
policy_pool=self.policy_inference,
policy=self.policy,
max_inflight_rollouts=config.max_inflight_rollouts,
max_inflight_episodes=config.max_inflight_episodes,
tasks_per_minute=config.tasks_per_minute,
max_off_policy_steps=config.max_off_policy_steps,
)
@@ -597,11 +597,12 @@ class Orchestrator:
)
return
self.consecutive_empty_batches = 0
n_trainable = sum(1 for r in batch.rollouts if r.is_trainable)
if n_trainable / len(batch.rollouts) <= 0.1:
effective = batch.rollouts.effective
n_trainable = sum(1 for r in effective if r.is_trainable)
if effective and n_trainable / len(effective) <= 0.1:
get_logger().warning(
f"Only {n_trainable}/{len(batch.rollouts)} generated rollouts are trainable "
f"({n_trainable / len(batch.rollouts):.1%}) — consider reviewing task difficulty / filter config"
f"Only {n_trainable}/{len(effective)} effective rollouts are trainable "
f"({n_trainable / len(effective):.1%}) — consider reviewing task difficulty / filter config"
)
# Ship batch ``step`` only once the trainer has published v{step-1-TARGET_LAG}.
@@ -637,7 +638,6 @@ class Orchestrator:
# at ship time; the full arrival window already streamed into ``all`` on arrival.
# to_record drops the per-node training tensors — they're for training, not the rollout
# record, and can't round-trip json (raw numpy bytes).
effective = batch.rollouts.effective
records = [r.to_record() for r in effective]
await asyncio.to_thread(save_rollouts, records, get_trace_path(config.output_dir, step, "train", "effective"))
@@ -805,19 +805,19 @@ class Orchestrator:
def log_train_batch(self, batch: TrainBatch, *, step: int, step_time: float) -> None:
"""Per-step ``Step …`` success line. Multi-env runs append an indented ``╰─`` line per env.
``Error`` is the sink-level rate (errored arrivals / total arrivals, over the full window);
the quality metrics are over the effective (clean, trained-on) subset; ``Trainable`` is
relative to all generated rollouts."""
the quality metrics are over the effective (clean, trained-on) subset, as is ``Trainable``."""
rollouts = batch.rollouts
effective = rollouts.effective
eff = effective.metrics
n_generated = len(rollouts)
n_trainable = sum(1 for r in rollouts if r.is_trainable)
trainable_rate = (n_trainable / n_generated) if n_generated else 0.0
n_effective = len(effective)
n_trainable = sum(1 for r in effective if r.is_trainable)
trainable_rate = (n_trainable / n_effective) if n_effective else 0.0
max_off_policy = max((r.off_policy_steps for r in effective), default=0)
head = (
f"Step {step} | {format_time(step_time):>7} | Reward {eff.reward.mean():.4f} | "
f"Trainable {n_trainable}/{n_generated} ({trainable_rate:.1%}) | "
f"Trainable {n_trainable}/{n_effective} ({trainable_rate:.1%}) | "
f"Turns {eff.num_turns.mean():.1f} | Branches {eff.num_branches.mean():.1f} | "
f"Max Off-Policy {max_off_policy} | "
f"Error {rollouts.metrics.has_error.mean():.1%} | Truncation {eff.is_truncated.mean():.1%}"
@@ -875,15 +875,15 @@ class Orchestrator:
metrics["step"] = float(batch.step)
self.monitor.log(metrics, step=batch.step)
# Success line — reward / turns / truncation over the effective set, error rate + branches
# over the full returned cohort. ``Stat.mean()`` is 0.0 for an empty set.
# Success line — quality metrics over the effective set, error rate over the full returned
# cohort. ``Stat.mean()`` is 0.0 for an empty set.
eff, full = effective.metrics, rollouts.metrics
triggered_at = self.eval_triggered_at.pop((batch.env_name, batch.step), None)
elapsed = (time.perf_counter() - triggered_at) if triggered_at is not None else 0.0
get_logger().success(
f"Evaluated {batch.env_name} (Step {batch.step}) | "
f"Policy v{policy_version} | {format_time(elapsed):>7} | Reward {eff.reward.mean():.4f} | "
f"Turns {eff.num_turns.mean():.1f} | Branches {full.num_branches.mean():.1f} | "
f"Turns {eff.num_turns.mean():.1f} | Branches {eff.num_branches.mean():.1f} | "
f"Error {full.has_error.mean():.1%} | Truncation {eff.is_truncated.mean():.1%}"
)
+1 -1
View File
@@ -146,7 +146,7 @@ class TrainBatch:
finalized in that span (errored + filtered included; rollouts of still-incomplete groups wait
for a later window). Its ``.effective`` / ``.metrics`` views drive logging. ``samples`` is the
trainer-bound payload (the shipped cohort's post-filter survivors) — an empty list means nothing
ships, which would stall the trainer. Trainable counts derive from ``rollouts``
ships, which would stall the trainer. Trainable counts derive from ``rollouts.effective``
(``r.is_trainable``) and token totals from ``samples``, so neither is carried as a field."""
rollouts: TrainRollouts
+1 -1
View File
@@ -168,7 +168,7 @@ class PrimeMonitor(Monitor):
payload["batch_size"] = run_config.batch_size
payload["rollouts_per_example"] = run_config.group_size
payload["seq_len"] = run_config.seq_len
payload["environments"] = [{"id": env.id} for env in run_config.train.env]
payload["environments"] = [{"id": env.env_id} for env in run_config.train.source]
payload["run_config"] = run_config.model_dump(exclude_none=True, mode="json")
if run_config.wandb:
payload["wandb_project"] = run_config.wandb.project
+12 -10
View File
@@ -298,15 +298,17 @@ class WandbMonitor(Monitor):
OVERVIEW_NAME = "overview"
# Per-rollout metrics (under "<scope>/all/") shown for BOTH train and eval. Only the reward metrics
# differ — train uses "reward/mean", eval uses "avg@k", each shown for the all and effective
# subsets — and each section builder prepends its own.
# Per-rollout metrics (as "<subset>/<metric>" under "<scope>/") shown for BOTH train and eval.
# Quality metrics read the effective subset — the all subset includes errored rollouts, whose
# zero values skew the distributions. has_error only exists on all (effective drops errors by
# construction). Only the reward metrics differ — train uses "reward/mean", eval uses "avg@k",
# each shown for the all and effective subsets — and each section builder prepends its own.
COMMON_METRICS = [
"has_error/mean",
"is_truncated/mean",
"num_total_tokens/mean",
"num_turns/mean",
"num_branches/mean",
"all/has_error/mean",
"effective/is_truncated/mean",
"effective/num_total_tokens/mean",
"effective/num_turns/mean",
"effective/num_branches/mean",
]
STABILITY_METRICS = ["optim/grad_norm", "entropy/all/mean", "mismatch_kl/all/mean", "kl_ent_ratio/mean"]
@@ -351,7 +353,7 @@ def train_section(name: str, scope: str) -> ws.Section:
return section(
name,
metrics=[f"{scope}/all/reward/mean", f"{scope}/effective/reward/mean"]
+ [f"{scope}/all/{m}" for m in COMMON_METRICS],
+ [f"{scope}/{m}" for m in COMMON_METRICS],
)
@@ -361,7 +363,7 @@ def eval_section(name: str, env_pattern: str) -> ws.Section:
return section(
name,
regexes=[f"eval/{env_pattern}/all/avg@.*", f"eval/{env_pattern}/effective/avg@.*"]
+ [f"eval/{env_pattern}/all/{m}" for m in COMMON_METRICS],
+ [f"eval/{env_pattern}/{m}" for m in COMMON_METRICS],
)
+24 -5
View File
@@ -25,11 +25,14 @@ CONFIG_CLASSES = [
def get_config_files() -> list[Path]:
"""Any TOML file inside `configs/` or `examples/`."""
"""Any TOML file inside `configs/`, `examples/` or `k8s/`."""
config_files = list(Path("configs").rglob("*.toml"))
example_files = list(Path("examples").rglob("*.toml"))
# The k8s example configs are mounted into the chart's containers verbatim, so a
# stale key there breaks a deploy with nothing else to catch it.
k8s_files = list(Path("k8s").rglob("*.toml"))
return config_files + example_files
return config_files + example_files + k8s_files
@pytest.mark.parametrize("config_file", get_config_files(), ids=lambda x: x.as_posix())
@@ -177,10 +180,10 @@ def test_env_algo_overrides_top_level():
{
"renderer": {"name": "qwen3"}, # echo needs the renderer's role attribution
"algo": {"type": "echo"},
"train": {"env": [{"id": "a", "algo": {"type": "grpo"}}, {"id": "b"}]},
"train": {"source": [{"legacy": {"id": "a"}, "algo": {"type": "grpo"}}, {"legacy": {"id": "b"}}]},
}
)
env_a, env_b = config.train.env
env_a, env_b = config.train.source
# Env a sets its own algorithm; only env b inherits the top-level echo algorithm.
assert env_a.algo is not None and env_a.algo.type == "grpo"
assert env_b.algo is not None and env_b.algo.type == "echo"
@@ -188,7 +191,23 @@ def test_env_algo_overrides_top_level():
# Resolved configs round-trip.
dumped = config.model_dump(exclude_none=True)
reloaded = OrchestratorConfig.model_validate(dumped)
assert reloaded.train.env[0].algo is not None and reloaded.train.env[0].algo.type == "grpo"
assert reloaded.train.source[0].algo is not None and reloaded.train.source[0].algo.type == "grpo"
with pytest.raises(ValidationError, match="env"):
OrchestratorConfig.model_validate(
{
"renderer": {"name": "qwen3"},
"train": {"env": [{"legacy": {"id": "removed"}}]},
}
)
with pytest.raises(ValidationError, match="env"):
OrchestratorConfig.model_validate(
{
"renderer": {"name": "qwen3"},
"eval": {"env": [{"legacy": {"id": "removed"}}]},
}
)
def test_trainer_enable_token_export_cli_flag():
+1 -2
View File
@@ -32,8 +32,7 @@ def create_run_with_config(output_dir: Path, run_name: str) -> Path:
"model": {"name": "test-model"},
"batch_size": 2,
"group_size": 1,
"env": [{"id": "test-env"}],
"sampling": {"temperature": 1.0},
"train": {"source": [{"legacy": {"id": "test-env"}}], "sampling": {"temperature": 1.0}},
# test-model isn't in MODEL_RENDERER_MAP; use the explicit default renderer.
"renderer": {"name": "default"},
}
+4 -4
View File
@@ -41,7 +41,7 @@ def create_run_with_config(
"model": {"name": "test-model"},
"batch_size": 32,
"group_size": 4,
"env": [{"id": "test-env"}],
"train": {"source": [{"legacy": {"id": "test-env"}}]},
# test-model isn't in MODEL_RENDERER_MAP; use the explicit default renderer.
"renderer": {"name": "default"},
}
@@ -202,7 +202,7 @@ def test_config_loading(tmp_path: Path) -> None:
"batch_size": 32,
"max_steps": 1000,
"group_size": 4,
"env": [{"id": "test-env"}],
"train": {"source": [{"legacy": {"id": "test-env"}}]},
"renderer": {"name": "default"},
}
create_run_with_config(tmp_path, "run_test123", config=test_config)
@@ -247,7 +247,7 @@ def test_config_cleanup_on_deletion(tmp_path: Path) -> None:
"model": {"name": "test-model"},
"batch_size": 16,
"group_size": 4,
"env": [{"id": "test-env"}],
"train": {"source": [{"legacy": {"id": "test-env"}}]},
"renderer": {"name": "default"},
}
run_dir = create_run_with_config(tmp_path, "run_delete_me", config=test_config)
@@ -278,7 +278,7 @@ def test_config_invalid(tmp_path: Path) -> None:
"model": {"name": "test-model"},
"batch_size": "not-a-number", # Invalid type
"group_size": 4,
"env": [{"id": "test-env"}],
"train": {"source": [{"legacy": {"id": "test-env"}}]},
}
run_dir = create_run_with_config(tmp_path, "run_invalid", config=invalid_config)
config_dir = run_dir / "control"
Generated
+14 -28
View File
@@ -936,21 +936,6 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/e6/ec/0c42039e80b9acc534f67b73b7a42471948042859b3a64867b50a4a77fa3/chromadb-1.5.9-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:cc09b3df76e5a5cb386aed2715a2eea152e3949f9e1ba93c7119505377749929", size = 23316203, upload-time = "2026-05-05T05:54:41.157Z" },
]
[[package]]
name = "claude-agent-sdk"
version = "0.2.107"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "anyio" },
{ name = "mcp" },
{ name = "sniffio" },
]
sdist = { url = "https://files.pythonhosted.org/packages/5a/f1/34820c3b12ec3d10d1cf4b72a877958134e4e2e7bd5af4dbc0cf4f55df33/claude_agent_sdk-0.2.107.tar.gz", hash = "sha256:e1310eef43b886c66ac157b9e80af0fb6ccedd83ad6acc9d4a6bb59cffdd2620", size = 255641, upload-time = "2026-06-22T20:51:00.429Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/fc/f1/ae6db2aa82f4d10ffa2c3c6953c2079d969f43e45bbf5f1ba3e5e6c66dad/claude_agent_sdk-0.2.107-py3-none-manylinux_2_17_aarch64.whl", hash = "sha256:abda89a41a4bcf2a9e1a3a94edf165ea5632174878874fcbfeeadbcc40e7f7d2", size = 73397534, upload-time = "2026-06-22T20:51:10.696Z" },
{ url = "https://files.pythonhosted.org/packages/9e/91/24808205b576842fb1ea8856d92da6ddca2903e1c3582e16d0ff0ed1b9d9/claude_agent_sdk-0.2.107-py3-none-manylinux_2_17_x86_64.whl", hash = "sha256:e3eabda428cbb1da71f1f0d3c742f81b1fe36c44d84e744fde39c4b9dbd3781b", size = 74371415, upload-time = "2026-06-22T20:51:14.154Z" },
]
[[package]]
name = "clbench-v1"
version = "0.2.0"
@@ -1893,11 +1878,11 @@ wheels = [
[[package]]
name = "filelock"
version = "3.29.0"
version = "3.32.0"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/b5/fe/997687a931ab51049acce6fa1f23e8f01216374ea81374ddee763c493db5/filelock-3.29.0.tar.gz", hash = "sha256:69974355e960702e789734cb4871f884ea6fe50bd8404051a3530bc07809cf90", size = 57571, upload-time = "2026-04-19T15:39:10.068Z" }
sdist = { url = "https://files.pythonhosted.org/packages/c0/80/8232b582c4b318b817cf1274ba74976b07b34d35ef439b3eb948f98645a1/filelock-3.32.0.tar.gz", hash = "sha256:7be2ad23a14607ccc71808e68fe30848aeace7058ace17852f68e2a68e310402", size = 213757, upload-time = "2026-07-21T13:17:42.898Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/81/47/dd9a212ef6e343a6857485ffe25bba537304f1913bdbed446a23f7f592e1/filelock-3.29.0-py3-none-any.whl", hash = "sha256:96f5f6344709aa1572bbf631c640e4ebeeb519e08da902c39a001882f30ac258", size = 39812, upload-time = "2026-04-19T15:39:08.752Z" },
{ url = "https://files.pythonhosted.org/packages/06/79/b4c714bef36bc4ec2beeae1e0c124f0223888cd8c6feb1cdc56038116920/filelock-3.32.0-py3-none-any.whl", hash = "sha256:d396bea984af47333ef05e50eae7eff88c84256de6112aea0ec48a233c064fe3", size = 97732, upload-time = "2026-07-21T13:17:41.55Z" },
]
[[package]]
@@ -2411,19 +2396,20 @@ wheels = [
[[package]]
name = "harbor"
version = "0.14.0"
version = "0.20.0"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "claude-agent-sdk" },
{ name = "datasets" },
{ name = "dirhash" },
{ name = "fastapi" },
{ name = "filelock" },
{ name = "httpx" },
{ name = "jinja2" },
{ name = "litellm" },
{ name = "packaging" },
{ name = "pathspec" },
{ name = "platformdirs" },
{ name = "pydantic" },
{ name = "pyjwt" },
{ name = "python-dotenv" },
{ name = "pyyaml" },
{ name = "requests" },
@@ -2435,9 +2421,9 @@ dependencies = [
{ name = "typer" },
{ name = "uvicorn" },
]
sdist = { url = "https://files.pythonhosted.org/packages/a9/f3/cba38a11b0cca01ecd471437869f1cd57d86a3b1e4091b8fd3d112cba8af/harbor-0.14.0.tar.gz", hash = "sha256:0ffffc25a618e4b7bf2b901a8c717c8bc28877f5aa8c37be47f1ec8c301cb0b6", size = 1241271, upload-time = "2026-06-17T16:43:23.495Z" }
sdist = { url = "https://files.pythonhosted.org/packages/1e/da/5a26998c6e7d9455321ab39bc8e9122993892ece13c3ad4f2b0de986aaf6/harbor-0.20.0.tar.gz", hash = "sha256:e2e5e88f772690fd121553ca34fd5d6dd6b4aaa51c8fae635abc84b112303112", size = 1590870, upload-time = "2026-07-18T21:25:22.578Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/f6/22/cb447121af474cfc7662b9f997be20316eadc692f19fa884608460589020/harbor-0.14.0-py3-none-any.whl", hash = "sha256:171971a008386ce633ef9f53fb4170e7d7807dba15349e930366581dd4c511e2", size = 1412739, upload-time = "2026-06-17T16:43:25.062Z" },
{ url = "https://files.pythonhosted.org/packages/76/03/b6617f32385295729f3af0ae0d512cf87ba4793b9ce462ea020d776a9025/harbor-0.20.0-py3-none-any.whl", hash = "sha256:4b7e48223aea2384cdb8c9eff35eaebd482fc9b1ec09f8193a121c47356ff19a", size = 1792416, upload-time = "2026-07-18T21:25:19.206Z" },
]
[[package]]
@@ -5020,11 +5006,11 @@ wheels = [
[[package]]
name = "platformdirs"
version = "4.9.6"
version = "4.11.0"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/9f/4a/0883b8e3802965322523f0b200ecf33d31f10991d0401162f4b23c698b42/platformdirs-4.9.6.tar.gz", hash = "sha256:3bfa75b0ad0db84096ae777218481852c0ebc6c727b3168c1b9e0118e458cf0a", size = 29400, upload-time = "2026-04-09T00:04:10.812Z" }
sdist = { url = "https://files.pythonhosted.org/packages/78/9b/560e4be8e26f6fd133a03630a8df0c663b9e8d61b4ade152b72005aec83b/platformdirs-4.11.0.tar.gz", hash = "sha256:0555d18370482847566ffabcaa53ad7c6c1c29f195989ae1ed634a05f76ea1e0", size = 31953, upload-time = "2026-07-21T13:09:36.565Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/75/a6/a0a304dc33b49145b21f4808d763822111e67d1c3a32b524a1baf947b6e1/platformdirs-4.9.6-py3-none-any.whl", hash = "sha256:e61adb1d5e5cb3441b4b7710bea7e4c12250ca49439228cc1021c00dcfac0917", size = 21348, upload-time = "2026-04-09T00:04:09.463Z" },
{ url = "https://files.pythonhosted.org/packages/7d/68/d8d58938dfb1370b266a1a729e6d77a985be23689a0496498ee17b2cbf90/platformdirs-4.11.0-py3-none-any.whl", hash = "sha256:360ccded2b7fce0af0ff80cc8f5942a1c5d99b0e856033acb030bfc634709e74", size = 23247, upload-time = "2026-07-21T13:09:35.422Z" },
]
[[package]]
@@ -5368,7 +5354,7 @@ requires-dist = [
{ name = "renderers", specifier = ">=0.1.8" },
{ name = "tomli", specifier = ">=2.2.1" },
{ name = "tomli-w", specifier = ">=1.2.0" },
{ name = "verifiers", specifier = ">=0.2.1" },
{ name = "verifiers", specifier = ">=0.2.2.dev43" },
]
[[package]]
@@ -7893,7 +7879,7 @@ requires-dist = [
{ name = "anthropic", specifier = ">=0.78.0" },
{ name = "datasets", specifier = ">=3.3.0,<6.0.0" },
{ name = "gepa", specifier = ">=0.0.6" },
{ name = "harbor", marker = "python_full_version >= '3.12' and extra == 'harbor'", specifier = "==0.14.0" },
{ name = "harbor", marker = "python_full_version >= '3.12' and extra == 'harbor'", specifier = "==0.20.0" },
{ name = "httpx", specifier = ">=0.27.0" },
{ name = "loguru", specifier = ">=0.7.0" },
{ name = "math-verify", specifier = ">=0.8.0" },