Files
691dd4ef14 chore: overhaul public configs/ and examples/ (#3085)
* chore: overhaul public configs/ and examples/

Restructure the public configs/ and examples/ trees for clarity.

- examples/: split into basic/ (core-env tutorials) and advanced/
  (folder-per-model: qwen3-30b-a3b, glm-4.5-air, glm-5.2, minimax-m2.5,
  nemotron-3-super, intellect-3.1), each with a README; drop multinode/
  and the example screenshots.
- configs/: add basic/ (small 2-GPU dev mirrors of the core envs, one folder
  + README each, validated at 1 step); rename debug/algorithms -> debug/algo;
  move debug/{rl,sft} -> debug/fake/{rl,sft}.toml; remove stale/internal
  configs (gsm8k, nemotron_*, hendrycks_math, general_agent, elastic,
  debug/v1, debug/{infer,orch,multimodal}.toml, debug/{hendrycks_sanity,moe,multi_env}).
- Remove the k8s/ Helm chart and its docs.
- Repoint README, docs/, nightly tests, and CI to the new paths; lowercase
  prime-rl throughout docs and READMEs.

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

* chore: drop per-model READMEs in examples/advanced

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

* chore(k8s): keep Helm chart, refresh reverse-text example configs

Keep the k8s/ Helm chart (undo its removal earlier in this branch) and bring
its reverse-text example back in sync with the current config layout.

The chart invoked examples/reverse_text/rl/{orch,infer,train}.toml — a split
config layout flattened into a single rl.toml months ago (#1859), so the
shipped example had pointed at non-existent files. Add current, validated
orch/infer/train configs under k8s/prime-rl/examples/reverse-text/ (split from
examples/basic/reverse_text/rl.toml), point the chart and docs at them, and
COPY k8s/ into the CUDA image so /app/k8s/... resolves at runtime.

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

* chore(configs): hyphenate all directory names in configs/, examples/, k8s/

Normalize directory naming to hyphens, matching the model dirs and logical
ids (reverse-text-v1, prime-rl). Renames the env/task dirs that still used
underscores:

  examples/basic/{reverse_text,alphabet_sort,wiki_search,hendrycks_sanity}
  configs/basic/{reverse_text,alphabet_sort,wiki_search,hendrycks_sanity}
  configs/ci/integration/reverse_text{,_lora,_moe,_multi_run,_rl_opd,_rl_sft,_sft,_sft_lora}

to the same names with hyphens, and updates every path reference (README,
docs, skills, nightly + integration test path args, the cpu_tests
config-import check). Python test files/modules and *.toml filenames keep
underscores.

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

* chore(examples): eval CLI migration, SLURM cleanup, batch sizes, glm-5.2 layout

- Migrate every eval command in examples/basic READMEs from `vf-eval` to the v1
  `eval` CLI (pydantic-config): `-b` -> `--client.base-url`, `--max-tokens`/`-t`
  -> `--sampling.max-tokens`, `--env-args` -> `--args`, plus `-r 3` (v1 defaults
  to 1 rollout; these READMEs report 20x3), `--harness.id null` (these envs train
  with the null harness), and `--no-push`. Drop the now-dead vf-eval skip in
  tests/unit/test_configs.py.
- Remove all SLURM overlays (slurm_rl.toml, slurm_sft.toml) from examples/basic.
  Move the slim-wheel SFT+[slurm] parse fixture to configs/ci/slim_sft.toml and
  repoint cpu_tests.yaml; drop the SLURM section from the hendrycks-sanity README
  and the SLURM line from the start-run skill.
- Tune basic example batch/group sizes: alphabet-sort 256/16, wordle 512/16
  (wiki-search already 512/16).
- Restructure examples/advanced/glm-5.2: inference configs ->
  infer/{pd,pd-llmd}.toml, RL configs -> {swe,swe-llmd}.toml; repoint docs.

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

* docs: fix outdated docs/skills/configs surfaced by v1 audit

Swept docs/, skills/, READMEs, and config TOMLs for outdated content (special
focus on v0->v1 drift). Verified every fix against current code.

docs/
- configuration.md: repoint 5 dead Basic example links to examples/basic/<hyphen>;
  scope the "each dir has a README" claim to basic (advanced dirs are config-only).
- algorithms.md: opd reference-model field is `teacher` not `model`; renderer names
  `glm-5`/`glm-4.5` (were invalid `glm5`/`glm4.5`); rewrite the per-env algorithm
  example in the v1 taskset/harness form (was the v0 bare-`id` form).
- development.md: drop invalid `--data.type null` (SFT DataConfig has no such type).
- inference.md: fix "Dissagregation" typo + dead P/D anchor.
- overview.md: token-in route is `/inference/v1/generate`.

skills/
- monitor-run: correct the metric tables to the real
  {scope}/{subset}/<metric>/<stat> scheme (num_total_tokens, has_error,
  time/wait_for_policy, dispatcher/*); the old seq_len / errored_rollouts /
  scheduler/* / generate_completions names never existed.
- install: drop the deep-gemm mention (no such section) from the description.

READMEs
- examples/README.md: basic runs on 1-8 GPUs (not 2); hyphenate env names.
- configs/README.md: drop stale "standalone entrypoint configs"; hyphenate.
- wiki-search: eval inference uses `--model.*` (not `--inference.model.*`) and drops
  the auto-derived `enable_auto_tool_choice` flag; "native V1 tools" not "MCP".
- reverse-text: fix dead sft/train.toml path -> sft.toml.
- hyphenate configs/basic/* README headings.

configs/
- qwen3-30b-a3b/tool.toml: move `min_tier` into the taskset (was under a v0
  `[...env.args]` block a v1 taskset never reads); group_size alias.
- glm-5.2/swe-llmd.toml: rollouts_per_example -> group_size.

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

* fix(configs): use prime-qwen3 renderer for reverse-text (was default)

The reverse-text configs run PrimeIntellect/Qwen3-0.6B-Reverse-Text-SFT, whose
`-SFT` suffix misses MODEL_RENDERER_MAP's exact-match lookup and so fell back to
the DefaultRenderer. reverse-text is single-turn and always sends a system
prompt ([system, user, assistant]); the prime-qwen3 renderer is token-for-token
identical to the model's apply_chat_template for that shape (verified via
render_ids parity), and unlike the stock qwen3 renderer it does not inject an
empty <think></think> block. Switch the 7 standard + 3 distill reverse-text
configs to prime-qwen3.

Kept `default` where no hand-coded renderer fits (each errors on the model's
tokenizer): hendrycks-sanity (DeepSeek-R1-Distill-Qwen-1.5B), reverse-text-moe
(samsja/mini-glm-moe), intellect-3.1 (INTELLECT-3-Base).

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

* fix(configs): use prime-qwen3 (not qwen3) for PrimeIntellect Qwen3 configs

The stock `qwen3` renderer injects an empty <think></think> block the
PrimeIntellect Qwen3 template never emits, so it mismatches these models'
apply_chat_template — single-turn for reverse-text, and every multi-turn shape
for wordle (verified via render_ids parity) — corrupting training tokenization.

- configs/basic/wordle/rl.toml: qwen3 + thinking_retention="all" -> prime-qwen3,
  matching the tutorial examples/basic/wordle (which already uses prime-qwen3).
- configs/debug/algo/{echo,grpo,max_rl,self_distill,mixed_grpo_opd,opd,opd_lora}.toml
  and configs/ci/integration/reverse-text-rl-opd/start.toml: qwen3 -> prime-qwen3
  (all run PrimeIntellect/Qwen3-0.6B-Reverse-Text-{SFT,RL}).

prime-qwen3 handles the PI template's think retention natively, so the explicit
thinking_retention="all" is dropped.

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

* fix(k8s): use prime-qwen3 renderer in reverse-text orch config

The k8s reverse-text orchestrator config was split from the reverse-text example
before that example migrated to prime-qwen3, and the renderer migration was
scoped to configs/ and examples/ — so this one kept the stale `default`. Align
it with the source (PrimeIntellect/Qwen3-0.6B-Reverse-Text-SFT → prime-qwen3).

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

* chore(k8s): drop redundant renderer comment in reverse-text orch config

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

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-20 10:59:06 -07:00

13 KiB
Raw Permalink Blame History

Scaling

This page covers how to scale prime-rl from a single GPU to a 1000-GPU cluster: single-node and multi-node deployments, FSDP / expert parallelism / context parallelism, and throughput benchmarking. See Training for detailed documentation of the trainer configuration and Inference for the inference configuration.

Table of Contents

Single-Node vs. Multi-Node Deployment

The rl, sft, and inference entrypoints all accept a [deployment] block (type = "single_node" or "multi_node") that picks how the trainer / orchestrator / inference processes are placed across hardware. Single-node runs locally; multi-node currently goes through SLURM — the launcher writes an sbatch script that places inference replicas, the orchestrator, and the trainer with the right rendezvous endpoints, IPs, ports, and shared-filesystem paths wired in.

Single-Node

RL Placement

rl defaults to 1 trainer GPU and 1 inference GPU. To give inference 6 GPUs with data parallelism and the trainer the remaining 2 on an 8-GPU node:

uv run rl @ rl.toml \
  --deployment.num-infer-gpus 6 \
  --deployment.num-train-gpus 2 \
  --inference.parallel.dp 6

The launcher allocates GPUs in order from CUDA_VISIBLE_DEVICES (or all visible GPUs): inference first, trainer next. To target a specific physical subset, pin CUDA_VISIBLE_DEVICES before launching.

For quick A/B ablations on the same node, run two RL instances side-by-side in separate tmux sessions, each pinned to half the GPUs and a separate inference port:

# session 1, GPUs 0–1, default port 8000
bash scripts/tmux.sh -s exp1 -o outputs/exp1
CUDA_VISIBLE_DEVICES=0,1 uv run rl @ rl.toml --output-dir outputs/exp1

# session 2, GPUs 2–3, port 8001
bash scripts/tmux.sh -s exp2 -o outputs/exp2
CUDA_VISIBLE_DEVICES=2,3 uv run rl @ rl.toml \
  --inference.server.port 8001 \
  --orchestrator.model.client.base-url http://localhost:8001/v1 \
  --output-dir outputs/exp2

SFT and Torchrun

uv run sft handles distributed launch internally. To scale from 1 to N GPUs, set the deployment GPU count (or just let it pick up WORLD_SIZE). For non-default layouts, the manual equivalent is:

uv run torchrun \
  --nproc-per-node 8 \
  --local-ranks-filter 0 \
  src/prime_rl/trainer/sft/train.py @ sft.toml

--local-ranks-filter 0 keeps console output to rank 0 only; per-rank stdout/stderr is still captured in <output_dir>/logs/trainer/torchrun/.

Multi-Node

Multi-node deployments (RL or SFT) are launched via SLURM — set [deployment] type = "multi_node" plus the matching [slurm] block, and the launcher writes the sbatch script that places inference, orchestrator, and trainer across the requested nodes with the inter-process wiring set up correctly. See SLURM § Examples for full configs.

Parallelism Knobs

FSDP

FSDP2 is the default model sharding strategy. By default the trainer fully shards parameters, gradients, and optimizer state across the data-parallel mesh. Tweakable knobs:

Knob Effect
trainer.model.dp_replicate Number of dimensions to replicate instead of shard. Set to 2 to run 2-way DP replication × FSDP sharding within each replica — useful for very large clusters where pure FSDP communication dominates.
trainer.model.reshard_after_forward If true (default), parameters are resharded after the forward pass to free memory; the backward pass re-gathers. Set false to keep params resident — faster but more memory.
trainer.model.fsdp_cpu_offload Offload params + grads + optimizer state to CPU. Big memory win, large throughput hit.
trainer.model.optim_cpu_offload Offload only optimizer state. Mid-ground — small throughput cost, decent memory savings, especially at low GPU count.

Expert Parallelism

EP shards MoE expert weights across the EP mesh, dramatically reducing the FSDP communication volume per layer and improving the training throughput. EP is only available with the custom model implementation (model.impl = "custom" or "auto" for supported families).

ep defaults to "auto", which resolves at startup to the largest valid EP degree up to 8. It loads the model config to read num_experts, then picks the biggest divisor of num_experts that also divides the FSDP island size (world_size // dp_replicate), is a multiple of cp, and is <= 8. For non-MoE models, resolves to 1 (no-op). Set ep to an explicit integer to override:

[trainer.model]
impl = "custom"
ep = 8                     # explicit EP degree; must divide num_experts
ep_comm_backend = "torch"  # or "deepep"

ep_comm_backend = "deepep" uses DeepEP's custom dispatch/combine kernels for speed, with two extra knobs (deepep_num_sms, deepep_token_chunk_size) — tune on your hardware.

Context Parallelism

CP shards a single sequence across multiple GPUs along the token dimension — for long-context sequences. We reccomend using ulysses style CP for most of the models to get the most throughput. Some models (e.g. GLM-5) only support ring style CP. Wrong setting will be rejected on validation.

ulysses head-shards Q/K/V, so the CP degree must divide num_attention_heads. GQA models with fewer KV heads than the CP degree (e.g. NemotronH: 32 query heads, 2 KV heads) are supported via KV-head replication; the CP degree must then be a multiple of num_key_value_heads. Hybrid Mamba layers head-shard independently (cp_mamba), which requires the CP degree to divide mamba_num_heads and n_groups.

[trainer.model]
impl = "custom"
attn = "auto"                # auto = FA3 on Hopper, FA4 on Blackwell; or flash_attention_2/3/4
cp = 2                       # CP degree
cp_style = "ulysses"         # "ring"

Activation Checkpointing and Offloading

Knob Memory ↓ Throughput ↓
trainer.model.ac large ~25%
trainer.model.ac.mode = "selective" medium small
trainer.model.ac_offloading extra a bit more

AC and AC offloading are enabled by default (full mode). For the best memory/throughput tradeoff, switch to selective AC (custom impl only):

[trainer.model.ac]
mode = "selective"
targets = ["norm", "attn_proj"]  # see Reference for the full list per architecture

ac_offloading is also on by default with max_inflight_activations = 5. We've observed this feature to be very effective, lowering the peak memory usage by 30-40% in some cases, while only lossing ~3-5% of throughput. To disable either, set model.ac = "None" or model.ac_offloading = "None".

Optimizer Offloading

Offloading optimizer states to CPU is enabled by default (optim_cpu_offload = true) — a near-free memory win at low GPU counts:

[trainer.model]
optim_cpu_offload = true   # already the default

Mutually exclusive with fsdp_cpu_offload. Also incompatible with trainer.max_concurrent_runs > 1 (multi-tenant training) — set optim_cpu_offload = false for multi-run. Muon doesn't support fsdp_cpu_offload but does support optim_cpu_offload.

LM Head Chunking

The vanilla LM head materializes a [batch * seq, vocab] logits tensor on every step — a major memory tax when the vocabulary is large (often >100K). fused_lm_head_token_chunk_size swaps in a custom fused linear + logprob/entropy kernel that streams through chunk_size tokens at a time, avoiding the materialization. It defaults to 1024 for RL training:

[trainer.model]
fused_lm_head_token_chunk_size = 1024       # default
# fused_lm_head_token_chunk_size = "disabled"  # vanilla LM head

Drop the chunk size further when peak memory is still tight (e.g. with very long sequences); raise it to amortize kernel-launch overhead. SFT training silently disables this (not supported yet). Only available with model.impl = "custom".

Memory-Tight Recipe

The kitchen-sink config for fitting large MoE on limited GPUs at acceptable throughput. AC, AC offloading, compile, fused LM head chunking, optimizer offload, and EP auto-resolution are on by default — only CP needs to be set explicitly (and EP overridden if auto-resolution is not desired):

[trainer.model]
impl = "custom"
ep = 8
cp = 2

[trainer.model.ac]
freq = 1

[trainer.model.ac_offloading]
max_inflight_activations = 1

The defaults already cover: fused LM head chunking (1024), torch.compile (fullgraph=False), AC (full mode), AC offloading (max_inflight_activations=5), and optimizer CPU offload. Walks through every memory lever in order: FSDP+EP shard the weights, CP shards the activations along the token dim, AC + AC offloading shrink the activation footprint, fused LM head chunks the loss, torch.compile reduces fragmentation, optim offload moves Adam state off GPU. Apply selectively — each knob has a throughput cost.

SLURM

The rl, sft, and inference entrypoints all submit to SLURM when a [slurm] table is present — there's no separate entrypoint.

The prime-rl checkout and its uv venv must live on a shared filesystem visible to every node. The generated sbatch script runs a single uv sync --all-extras --all-packages on the batch node (not once per node), so all ranks share that one environment — a node-local venv would leave the other nodes stale.

Activation

A SLURM config is usually a thin overlay that adds [slurm] (and [deployment] for multi-node) on top of a base config. Configs are composed left-to-right via the @ CLI syntax — see Configuration § TOML Composition:

# my_slurm.toml
output_dir = "/shared/outputs/my-rl"

[slurm]
job_name = "my-rl-run"

Launch:

uv run rl @ base_rl.toml @ my_slurm.toml             # submits via sbatch
uv run rl @ base_rl.toml @ my_slurm.toml --dry-run   # writes the sbatch script + resolved config, exits

[deployment] Block

[deployment] is a discriminated union picked by type — single_node or multi_node for RL/SFT, with an extra disaggregated variant for inference. RL multi-node:

[deployment]
type = "multi_node"
num_train_nodes = 2
num_infer_nodes = 1              # optional when inference.deployment defines the node topology
gpus_per_node = 8                # default
nodes_per_fsdp_group = 1         # optional — controls FSDP island size

SFT multi-node:

[deployment]
type = "multi_node"
num_nodes = 2
gpus_per_node = 8

Examples

Full multi-node configs ship under examples/advanced/:

  • nemotron-3-super/swe.toml — 4 trainer + 1 inference node RL on a 120B hybrid-Mamba MoE with NCCL weight broadcast.
  • glm-5.2/ — large-scale and P/D-disaggregated inference across the GLM-5 family.

For inference-only multi-node, set [deployment] type = "multi_node" on an inference TOML — each node runs an independent vLLM replica (TP and DP must fit within one node), and the launcher prints one URL per node. Front the URLs with a router or point clients at any of them.

Custom Templates

For unusual partitions, module loads, or environment setup, supply your own Jinja2 template:

uv run rl @ my_config.toml --slurm.template-path path/to/my_template.sbatch.j2

The default templates live under src/prime_rl/templates/ — copy one as a starting point.

Benchmarking

Every entrypoint supports a --bench flag that runs a few warm-up + measurement steps with fake data and prints a rich-formatted throughput / MFU table:

# SFT trainer alone
uv run sft @ sft.toml --bench
uv run sft ... --data.type fake --data.length variable --bench   # variable-length fake data

# RL trainer alone (no inference involved)
uv run trainer @ train.toml --data.fake --bench

# Inference alone — start the server normally, then bench the orchestrator
uv run inference @ infer.toml
uv run orchestrator @ orch.toml --bench

# Full RL stack (trainer with fake data, inference with real data from orchestrator)
uv run rl @ rl.toml --bench

Persist results with --bench.output-json. Use this to compare parallelism configs before committing a multi-day run.