Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
07d8589
split configs into entrypoints and components
mikasenghaas Dec 2, 2026
053529a
move config blocks to the component that uses them
mikasenghaas Dec 2, 2026
b4331ea
point eval ci path filters at the moved configs
mikasenghaas Dec 2, 2026
48de560
keep algorithm with the shared config blocks
mikasenghaas Dec 3, 2026
ab4c7ee
point the eval ci filter at configs/algorithm.py
mikasenghaas Dec 3, 2026
674e506
add an engine component config and script
mikasenghaas Dec 2, 2026
bdc56e3
write engine-only per-rank configs, make EngineConfig strict
mikasenghaas Dec 2, 2026
39ff450
nest only public sections in rl and sft
mikasenghaas Dec 2, 2026
2b6674d
nest a trainer section in rl
mikasenghaas Dec 2, 2026
427c4b7
derive sft inference deployment from the run
mikasenghaas Dec 2, 2026
e7f5969
map entrypoints and components in the configs readme
mikasenghaas Dec 2, 2026
b78d01d
build each component config via components()
mikasenghaas Dec 2, 2026
819fc8f
drop the unused keep_engine_fields filter
mikasenghaas Dec 2, 2026
e8eba09
drop the removed resume cleanup config from the readme
mikasenghaas Dec 3, 2026
bf1358c
make the modelexpress server a component
mikasenghaas Dec 3, 2026
1a00029
let the builders fill the weight broadcast group
mikasenghaas Dec 3, 2026
9932959
group the p/d transfer fields of the engine config
mikasenghaas Dec 3, 2026
a2c9615
write every component config whole before launch
mikasenghaas Dec 3, 2026
1f4679c
build each p/d engine config with its role's offload
mikasenghaas Dec 3, 2026
167d996
split configs into entrypoints, components, blocks
mikasenghaas Dec 3, 2026
06d968b
import BaseConfig from configs.base in the slim check
mikasenghaas Dec 3, 2026
d1707a3
drop the removed resume cleanup config from the layout
mikasenghaas Dec 3, 2026
95b8fdd
document every config class and field
mikasenghaas Dec 3, 2026
f8fcb74
set the run-level fields of rl once
mikasenghaas Dec 3, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,15 @@ jobs:
/tmp/slim/bin/python - <<'PY'
import sys

from prime_rl.configs.rl import RLConfig
from prime_rl.configs.sft import SFTConfig
from prime_rl.configs.inference import InferenceConfig
from prime_rl.configs.orchestrator import OrchestratorConfig
from prime_rl.configs.trainer import TrainerConfig
from prime_rl.configs.env_worker_pool import EnvWorkerPoolConfig
from prime_rl.utils.config import BaseConfig, find_package_resource, rgetattr, rsetattr
from prime_rl.configs.components.env_worker_pool import EnvWorkerPoolConfig
from prime_rl.configs.components.orchestrator import OrchestratorConfig
from prime_rl.configs.components.router import RouterConfig
from prime_rl.configs.components.trainer import TrainerConfig
from prime_rl.configs.entrypoints.inference import InferenceConfig
from prime_rl.configs.entrypoints.rl import RLConfig
from prime_rl.configs.entrypoints.sft import SFTConfig
from prime_rl.configs.base import BaseConfig
from prime_rl.utils.config import find_package_resource, rgetattr, rsetattr
from prime_rl.utils.validation import propagate_shared_fields

# `verifiers` (+ its `datasets` dep) is a declared slim dep: the v1 config types
Expand All @@ -103,7 +105,7 @@ jobs:
run: |
/tmp/slim/bin/python - <<'PY'
from pydantic_config import cli
from prime_rl.configs.sft import SFTConfig
from prime_rl.configs.entrypoints.sft import SFTConfig
# The slim wheel intentionally excludes taskset packages, so validate a real
# SFT config here. RL recipes are covered by the full config suite.
for cfg_cls, args in [
Expand Down Expand Up @@ -136,15 +138,20 @@ jobs:
- '{pyproject.toml,uv.lock,.python-version,.gitmodules}'
- 'deps/**'
- 'packages/**/pyproject.toml'
- 'packages/prime-rl-configs/src/prime_rl/configs/{trainer,shared,__init__}.py'
- 'packages/prime-rl-configs/src/prime_rl/configs/{base,__init__}.py'
- 'packages/prime-rl-configs/src/prime_rl/configs/{blocks,components/trainer}/**'
- 'packages/prime-rl-configs/src/prime_rl/configs/{components,entrypoints}/__init__.py'
- 'packages/prime-rl-configs/src/prime_rl/utils/**'
- 'src/prime_rl/*.py'
- 'src/prime_rl/{trainer,multimodal,transports,utils}/**'
- 'tests/{__init__.py,conftest.py,utils.py}'
- 'tests/integration/{__init__.py,conftest.py}'
- 'packages/prime-rl-configs/src/prime_rl/configs/{eval,orchestrator,inference,env_worker_pool,algorithm,monitors}.py'
- 'packages/prime-rl-configs/src/prime_rl/configs/entrypoints/{eval,inference}.py'
- 'packages/prime-rl-configs/src/prime_rl/configs/components/{orchestrator,engine}/**'
- 'packages/prime-rl-configs/src/prime_rl/configs/components/{online_eval,env_worker_pool}.py'
- 'src/prime_rl/{control,eval,orchestrator,monitors}/**'
- 'src/prime_rl/entrypoints/{eval,env_worker_pool}.py'
- 'src/prime_rl/entrypoints/eval.py'
- 'src/prime_rl/components/env_worker_pool.py'
- 'tests/integration/test_gsm8k_eval.py'
- 'tests/integration/configs/gsm8k-eval.toml'

Expand Down
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ Write tests as plain functions with pytest fixtures. Don't use class-based tests

`prime-rl` owns run config resolution and process launch; external orchestrators (such as `prime-factory-operator`) only materialize infrastructure.

- Put role-specific vLLM flags, parallelism, kernel workarounds, role env vars, and router/transport settings in `prime-rl-configs` (`for_pd_role`, `dump_rl_components`, `dump_pd_components`), never only in SLURM templates.
- Ship `[project.scripts]` entrypoints (like `router`) for non-trivial role/service startup, reading mounted JSON configs plus minimal pod inputs (`POD_IP`, `JOB_COMPLETION_INDEX`, peer URLs).
- Put role-specific vLLM flags, parallelism, kernel workarounds, role env vars, and router/transport settings in `prime-rl-configs` (`InferenceSection.engine_config(role=...)`, `components()`, `dump_components`), never only in SLURM templates.
- Ship `[project.scripts]` entrypoints (like `router` and `engine`) for non-trivial role/service startup, reading mounted JSON configs plus minimal pod inputs (`POD_IP`, `JOB_COMPLETION_INDEX`, peer URLs).
- Keep orchestrator helpers (like `resolve_client_roles`) compatible with both SLURM per-rank external LB and Kubernetes per-pod internal DP.

## Git
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/llep/bench_llep.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
rel_err,
)

from prime_rl.configs.trainer import LLEPConfig
from prime_rl.configs.components.trainer.moe import LLEPConfig
from prime_rl.trainer.distributed.token_dispatcher import TorchTokenDispatcher # noqa: E402


Expand Down
2 changes: 1 addition & 1 deletion benchmarks/llep/check_grads.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
sys.path.insert(0, str(Path(__file__).parent))
from common import clamped_swiglu, make_routing # noqa: E402

from prime_rl.configs.trainer import LLEPConfig # noqa: E402
from prime_rl.configs.components.trainer.moe import LLEPConfig
from prime_rl.trainer.models.layers.activations import ClampedSilu # noqa: E402
from prime_rl.trainer.models.layers.llep_mega_moe import LLEPMegaMoEExpertCompute # noqa: E402
from prime_rl.trainer.models.layers.mega_moe import MegaMoEExpertCompute, reserve_sms_for_comm # noqa: E402
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/llep/check_moe_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import torch
import torch.distributed as dist

from prime_rl.configs.trainer import LLEPConfig
from prime_rl.configs.components.trainer.moe import LLEPConfig
from prime_rl.trainer.distributed.token_dispatcher import FusedTokenDispatcher
from prime_rl.trainer.models.deepseek_v4.configuration_deepseek_v4 import DeepseekV4Config
from prime_rl.trainer.models.deepseek_v4.moe import DeepseekV4MoE
Expand Down
2 changes: 1 addition & 1 deletion docs/algorithms.md
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ class MyAlgorithm(Algorithm):
assign_advantage(trace, advantage)
```

Add a typed `MyAlgoConfig` to `prime_rl.configs.algorithm` and its discriminated union, then register `"my_algo": MyAlgorithm` in `ALGORITHM_CLASSES`. Pick `score_episode` for rollout-local work on the trace graph, `score_sample` for model calls on a rollout's samples, and `score_group` for group-relative credit. `assign_advantage` credits every sampled token on the trace's trainable branches with one value.
Add a typed `MyAlgoConfig` to `prime_rl.configs.blocks.algorithm` and its discriminated union, then register `"my_algo": MyAlgorithm` in `ALGORITHM_CLASSES`. Pick `score_episode` for rollout-local work on the trace graph, `score_sample` for model calls on a rollout's samples, and `score_group` for group-relative credit. `assign_advantage` credits every sampled token on the trace's trainable branches with one value.

Curriculum admission and metrics read each trace's advantage after group scoring.

Expand Down
2 changes: 1 addition & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ Then inspect the resolved config:

```bash
ls /tmp/reverse-dry/check/configs/latest/resolved/
# rl.json trainer.json orchestrator.json inference.json
# rl.json trainer.json orchestrator.json engine.json router.json envs/
```

Each per-process JSON contains the final, validated configuration that the run
Expand Down
2 changes: 1 addition & 1 deletion docs/eval.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Against a disaggregated prefill/decode deployment, list the engines in `client.a

## Configuration

Multi-source runs use a TOML (`EvalConfig` in `packages/prime-rl-configs/src/prime_rl/configs/eval.py`). The eval block is flattened to the top level — `[[source]]`, `[client]`, `[concurrency]`, `[sampling]`, `[select]`, `group_size` — and each source takes the same `env` block as `[[orchestrator.eval.source]]`:
Multi-source runs use a TOML (`EvalConfig` in `packages/prime-rl-configs/src/prime_rl/configs/entrypoints/eval.py`). The eval block is flattened to the top level — `[[source]]`, `[client]`, `[concurrency]`, `[sampling]`, `[select]`, `group_size` — and each source takes the same `env` block as `[[orchestrator.eval.source]]`:

```toml
model = "Qwen/Qwen3-4B"
Expand Down
6 changes: 3 additions & 3 deletions docs/inference.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ The single-node deployment is the default deployment shape. It runs the inferenc
type = "single_node"
```

The launcher starts a `vllm-router` on `inference.server.port` (default `8000`) fronting the vLLM engine on `inference.backend_port` (default `8100`). Clients connect to the router URL; admin operations (weight updates, health checks) bypass the router and hit the engine port directly — the RL entrypoint wires `orchestrator.model.client.admin_base_url` accordingly.
The launcher starts a `vllm-router` on `inference.server.port` (default `8000`) fronting the vLLM engine on `inference.backend_port` (default `server.port + 100`, i.e. `8100`). Clients connect to the router URL; admin operations (weight updates, health checks) bypass the router and hit the engine port directly — the RL entrypoint wires `orchestrator.model.client.admin_base_url` accordingly.

This deployment shape runs the inference server on a single node, if configured with NVLink enabled, it allows you more freedom in terms of parallelism configurations.

Expand Down Expand Up @@ -207,7 +207,7 @@ On top of vLLM's API, each engine serves the routes the orchestrator drives it w

A request to a guarded route must carry the token in the `X-Prime-Admin-Token` header, or it gets a `401`. A process that sends the token reads it from `PRIME_RL_ADMIN_TOKEN`. A process that only checks it can instead be given its SHA-256 digest in `PRIME_RL_ADMIN_TOKEN_SHA256`, so it cannot make the calls it guards. The orchestrator sends the header on its engine admin clients only — never to the router. `/liveness` and vLLM's own health routes stay open for probes.

The `rl` and `sft` launchers handle the token themselves, locally and on SLURM: they generate a fresh one per run (or reuse `PRIME_RL_ADMIN_TOKEN` when the launching environment or `.env` sets it). The process that calls the engines' admin routes gets the token: the orchestrator, or an `sft` run's online evals. The engines, started with `--server.require-admin-token`, and the control APIs get its digest. The env worker pools and the router get neither, and neither is written to a config or to the SLURM script. To call a run's control API yourself, set `PRIME_RL_ADMIN_TOKEN` before launching and send it in the header.
The `rl` and `sft` launchers handle the token themselves, locally and on SLURM: they generate a fresh one per run (or reuse `PRIME_RL_ADMIN_TOKEN` when the launching environment or `.env` sets it). The process that calls the engines' admin routes gets the token: the orchestrator, or an `sft` run's online evals. The engines, whose configs set `server.require_admin_token`, and the control APIs get its digest. The env worker pools and the router get neither, and neither is written to a config or to the SLURM script. To call a run's control API yourself, set `PRIME_RL_ADMIN_TOKEN` before launching and send it in the header.

A standalone `eval` generates no token: set `PRIME_RL_ADMIN_TOKEN` yourself to guard its control API. It starts its env worker pools without it.

Expand Down Expand Up @@ -310,7 +310,7 @@ HiSparse (vLLM, DSA sparse-MLA models such as GLM-5.x) keeps the sparse-MLA KV i
host_pool_gib = 160 # pinned host RAM per GPU worker
```

prime-rl adds vLLM's `HiSparseConnector` to the KV transfer config. Under disaggregated P/D it applies to decode instances only: the launcher writes one engine config per role (`inference-prefill.json`, `inference-decode.json`) and drops HiSparse from the prefill one. Budget decode-node RAM as `GPUs per node × host_pool_gib`. Prefill KV offload works with it, but decode cannot also offload KV: set `inference.deployment.decode_kv_cache_offload = "None"`. Native offload rejects HiSparse's host-resident KV layout, and Mooncake would store that layout under the same keys as prefill's regular layout, so prefill fails to load it. Without P/D, native offload is rejected and Mooncake offload works. vLLM checks HiSparse's requirements at startup: no pipeline or decode context parallelism, and a model with `index_topk`. vLLM also rejects `cudagraph_mode = "FULL"`; the P/D decode launch uses `FULL_DECODE_ONLY`, which it accepts. Size decode `max_num_seqs` explicitly (e.g. 96 per rank): the GPU buffers scale with it.
prime-rl adds vLLM's `HiSparseConnector` to the KV transfer config. Under disaggregated P/D it applies to decode instances only: the launcher writes one engine config per role (`engine-prefill.json`, `engine-decode.json`) and drops HiSparse from the prefill one. Budget decode-node RAM as `GPUs per node × host_pool_gib`. Prefill KV offload works with it, but decode cannot also offload KV: set `inference.deployment.decode_kv_cache_offload = "None"`. Native offload rejects HiSparse's host-resident KV layout, and Mooncake would store that layout under the same keys as prefill's regular layout, so prefill fails to load it. Without P/D, native offload is rejected and Mooncake offload works. vLLM checks HiSparse's requirements at startup: no pipeline or decode context parallelism, and a model with `index_topk`. vLLM also rejects `cudagraph_mode = "FULL"`; the P/D decode launch uses `FULL_DECODE_ONLY`, which it accepts. Size decode `max_num_seqs` explicitly (e.g. 96 per rank): the GPU buffers scale with it.

### Speculative Decoding

Expand Down
14 changes: 7 additions & 7 deletions docs/training.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ This page covers everything you need to launch, observe, checkpoint, and recover
| `uv run sft` | Supervised fine-tuning on a HF dataset. | Launches torchrun internally; never call torchrun directly. |
| `uv run pretrain` | Pretraining from scratch on tokenized shards. | Launches torchrun internally; see [Pretraining](#pretraining). |
| `uv run inference` | vLLM server. | Always use this entrypoint over `vllm serve` — it adds `/update_weights`, `/load_lora_adapter`, and `/init_broadcaster`. |
| `uv run engine` | One vLLM engine without a router. | Launchers start these for multi-node and P/D ranks, from the engine part of the inference config. |
| `uv run orchestrator` | Standalone orchestrator process. | Pair with a separately-launched inference server and one `env-worker-pool` per source. |
| `uv run eval` | Multi-env evals against a live inference server. | One epoch per source, pinned (or adaptive) concurrency, cursor checkpoints + `--resume`, dashboard + optional platform upload; see [Eval](eval.md). |
| `uv run env-worker-pool` | One source's worker pool replica: a broker and its env workers. | Launchers start these automatically. Use this command for standalone pools, including sources whose `serve.address` points to an externally managed pool. |
Expand Down Expand Up @@ -83,9 +84,8 @@ Orchestrator
```

An external orchestrator, such as Kubernetes, can run a run's pools itself instead of the
launcher. `dump_env_worker_pool_components(config)` (in `prime-rl-configs`) gives the
`EnvWorkerPoolConfig` of each pool the run would start, keyed `<split>/<source name>`, without
writing files. Run `env-worker-pool @ <config>` for each with `PRL_ENV_BIND_ADDRESS` set to
launcher. `config.components()` (in `prime-rl-configs`) gives the `EnvWorkerPoolConfig` of each
pool the run would start, keyed `envs/<split>/<source name>`, without writing files. Run `env-worker-pool @ <config>` for each with `PRL_ENV_BIND_ADDRESS` set to
where it should listen (e.g. `tcp://0.0.0.0:5000`), and give the orchestrator
`PRL_ENV_ADDRESSES`, a JSON object of the same keys to the addresses peers reach them at. A
source's own `serve.address` still wins, and a source with neither waits on its address file
Expand Down Expand Up @@ -511,7 +511,7 @@ uv run rl @ rl.toml --ckpt.interval 25 --ckpt.keep-interval 100 # …plus perma

### Asynchronous Checkpoints

By default a trainer step waits until its checkpoint is written to storage. With `--ckpt.async-save` (`--trainer.ckpt.async-save` also works for `rl`), a save only copies each rank's model and optimizer state into pinned host memory. A background thread then writes the copy to storage while training continues:
By default a trainer step waits until its checkpoint is written to storage. With `--ckpt.async-save`, a save only copies each rank's model and optimizer state into pinned host memory. A background thread then writes the copy to storage while training continues:

```bash
uv run rl @ rl.toml --ckpt.interval 2 --ckpt.async-save
Expand All @@ -532,7 +532,7 @@ Some things to know:

#### Remote Checkpoints

`[ckpt.remote]` mirrors trainer checkpoints to an S3-compatible object store, with a retention policy of its own (`[trainer.ckpt.remote]` also works for `rl`):
`[ckpt.remote]` mirrors trainer checkpoints to an S3-compatible object store, with a retention policy of its own:

```toml
[ckpt]
Expand Down Expand Up @@ -723,7 +723,7 @@ Only these fields are live; every other field is frozen:
| `eval.source[*].interval` | Changes eval cadence from the next policy update. |
| `train.source[*].algo.length_penalty` | Changes a GRPO source's length penalty: its weights, its type, or turning it on (a config) or off (`null`). It applies to every group scored from the next step on, including groups already running, since a group is scored when its last rollout finishes. Set it per source: the group-level `train.algo` is only a default for the sources and is frozen. |

Frozen fields include the model, tokenizer, renderer, transports, monitors, logging, checkpointing, output directory, padding and the trainer topology, which are fixed at launch. `seq_len` and `max_steps` are frozen because the trainer depends on them. Eval group sizes, algorithms (except the length penalty), curricula, eval sampling and task selection are frozen, as are adding, removing, renaming or reordering sources and turning eval on or off. In the config, a live field is annotated with `Annotated[T, Live()]` (from `prime_rl.configs.diff`); every other field is frozen.
Frozen fields include the model, tokenizer, renderer, transports, monitors, logging, checkpointing, output directory, padding and the trainer topology, which are fixed at launch. `seq_len` and `max_steps` are frozen because the trainer depends on them. Eval group sizes, algorithms (except the length penalty), curricula, eval sampling and task selection are frozen, as are adding, removing, renaming or reordering sources and turning eval on or off. In the config, a live field is annotated with `Annotated[T, Live()]` (from `prime_rl.utils.diff`); every other field is frozen.

### Exporting Checkpoints

Expand Down Expand Up @@ -806,7 +806,7 @@ uv run rl @ rl.toml --monitors.wandb # default project, ran
uv run rl @ rl.toml --monitors.wandb.project my-proj --monitors.wandb.name run-42
```

The trainer and orchestrator log into a **single shared W&B run**, so all metrics from both processes land in one place. Shared mode requires the W&B SDK ≥ 0.19.9 and is incompatible with `monitors.wandb.offline = true`.
The trainer and orchestrator log into a **single shared W&B run**, so all metrics from both processes land in one place. Shared mode requires the W&B SDK ≥ 0.19.9 and a connection to the W&B server, so `rl` rejects `monitors.wandb.offline = true`.

prime-rl deliberately logs a **large number of metrics** for maximum observability: every rollout metric is emitted per subset (`all`/`effective`), per statistic (`mean`/`max`/`min`/`p10`/`p90`), and per environment alongside a cross-env aggregate, so a multi-env run can emit thousands of series. To keep that navigable, every training run (RL and SFT) gets an **auto-created `overview` saved view** curating the handful of metrics that matter into `train`, `eval`, `stability`, and `performance` sections (with per-env breakdowns). The view is created once per project and adapts to the run's environments; if a later run uses a different set of environments, a new versioned view (`overview-v2`, …) is created instead of overwriting the first.

Expand Down
Loading