Files
prime-rl/examples/advanced/glm-5.3
28c5f576a0 feat: rename off-policy steps to staleness (#4253)
## Summary

- Rename the orchestrator config field `max_off_policy_steps` to
`max_staleness`. Update every config and example that sets it.
- Define two staleness levels and use them in code, metrics, and docs:
- **Token staleness**: the policy version a batch trains on minus the
policy version that sampled the token. Tokens without a policy label
(Dynamo engines) take their rollout's dispatch version, which is the
same rule the masking uses.
- **Rollout staleness**: the max token staleness of the rollout. It
splits into **in-flight** staleness (weight updates between the oldest
token and completion) and **in-queue** staleness (weight updates while
the rollout waits to ship).
- Replace `episode_staleness` and `token_policy_ages` with one
`rollout_staleness` helper that returns both levels.
- Rename the per-step metrics from `off_policy/*` to `staleness/*`:
  - `staleness/token/mean`, `staleness/token/masked`
  - `staleness/rollout/{mean,max}`
- `staleness/rollout/in_flight/{mean,max}`,
`staleness/rollout/in_queue/{mean,max}`
  - `staleness/rollout/dropped`
- Remove the live `dispatcher/off_policy/{mean,max}` gauge. The
per-batch staleness metrics replace it.
- Change the console step log from `Max Off-Policy` to `Max Staleness`.
- Docs: add the token and rollout staleness definitions to
`docs/algorithms.md` (section renamed to "Async Training & Staleness").
List the staleness metrics in `docs/training.md`. Update `docs/ipo.md`,
the README, the `monitor-run` skill, and the dashboard producer regex.

## Breaking

- `orchestrator.max_off_policy_steps` is now
`orchestrator.max_staleness`. Configs that use the old name fail
validation. Migration: rename the key.
- Metric renames (update W&B panels and alerts):

  | Old | New |
  |---|---|
  | `off_policy/{mean,max}` | `staleness/rollout/{mean,max}` |
| `off_policy/in_flight/{mean,max}` |
`staleness/rollout/in_flight/{mean,max}` |
| `off_policy/in_queue/{mean,max}` |
`staleness/rollout/in_queue/{mean,max}` |
  | `off_policy/token/mean` | `staleness/token/mean` |
  | `off_policy/token/max` | removed: equal to `staleness/rollout/max` |
  | `off_policy/token/masked` | `staleness/token/masked` |
  | `off_policy/dropped` | `staleness/rollout/dropped` |
| `dispatcher/off_policy/{mean,max}` | removed: use the per-batch
`staleness/rollout/*` |

- Value changes:
- Rollout staleness now comes from token policy labels, not from the
dispatch version. A rollout whose first token was sampled after a weight
update now reports a lower value.
- Token staleness now counts unlabelled tokens at their dispatch
version. Before, it skipped them.
- Frozen-sourced rollouts are left out of the staleness stats. Before,
they counted as 0.

## Verification

- `uv run pytest tests/unit/orchestrator`: 132 passed.
`test_token_policy_ages.py` is now `test_rollout_staleness.py` and
covers the token and rollout levels and the in-flight/in-queue split.
- `OrchestratorConfig(max_staleness=16)` validates, and
`OrchestratorConfig(max_off_policy_steps=16)` raises `ValidationError`.
- I did not run `tests/unit/test_configs.py` to completion. It fails
locally because the taskset packages (`reverse_text`, `gsm8k`,
`scaleswe`, …) are not installed. Every failure is a
`ModuleNotFoundError` for a taskset package.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Breaking config and metric renames affect existing runs and
monitoring; staleness computation changes may shift reported values
without changing masking logic tied to `max_staleness`.
> 
> **Overview**
> Renames the orchestrator knob **`max_off_policy_steps`** to
**`max_staleness`** everywhere (config schema, example/advanced TOMLs,
docs). Behavior is unchanged: it still caps how old a sampled token can
be before masking or dropping queued samples; rollouts are not cancelled
for staleness.
> 
> **Staleness model and metrics** are tightened and renamed.
**`rollout_staleness`** replaces separate **`episode_staleness`** /
**`token_policy_ages`** helpers: rollout staleness is the **max token
staleness** (from engine `weight_versions`, with unlabeled tokens using
dispatch version), split into in-flight vs in-queue. Shipped-batch
logging and W&B-style keys move from **`off_policy/*`** to
**`staleness/token/*`** and **`staleness/rollout/*`**; live
**`dispatcher/off_policy/{mean,max}`** gauges are removed. Console logs
say **Max Staleness** instead of Max Off-Policy.
> 
> Docs and ops surfaces (**`algorithms.md`**, **`training.md`**, IPO
ablation copy, **`monitor-run`** skill, dashboard orch key regex) use
the new vocabulary. **Breaking:** old config key fails validation;
dashboards/alerts must remap metrics (including removed
**`off_policy/token/max`** and dispatcher off-policy gauges). Reported
staleness values can shift slightly because rollout stats are
token-label-based and frozen-sourced rollouts are omitted from
aggregates.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
c569e1512817bfd292ad14efc768ec7d1a76acf8. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-25 06:13:06 -07:00
..

GLM-5 family at scale

Large-scale RL and serving for the GLM-5 family — zai-org/GLM-5.3-BF16 for training and serving alike, quantized to per-block FP8 online on the vLLM side — at 131k context: 16 trainer nodes on the custom MoE implementation (expert + context parallelism) and P/D-disaggregated FP8 inference. The swe-llmd.toml append fronts the same inference plane with the llm-d router (Endpoint Picker + Envoy): its active-request-scorer load-balances in flight — instead of reacting to delayed metrics like the default vllm-router — which, combined with prefix-cache affinity for grouped rollouts, keeps prefill and decode ranks evenly loaded under RL's bursty request pattern. It also offloads KV to a Mooncake distributed CPU pool (1TB per node by default).

Config What it runs Topology
swe.toml Base GLM-5.3 RL: trains on r2e-gym (rlm harness), FP8-quantized trainer (deepgemm_fp8 MoE compute), serves GLM-5.3-BF16 with online per-block FP8 quantization behind the default vllm-router. 16 train + 16 infer nodes
swe-llmd.toml Append for swe.toml: swaps in the llm-d router (EPP scorer tuning) + Mooncake KV offload — launch as rl @ swe.toml @ swe-llmd.toml. same
infer/pd.toml Inference-only pre-flight: P/D-disaggregated GLM-5-FP8. 6 infer nodes
infer/pd-llmd.toml Inference-only pre-flight: GLM-5.2-FP8 with llm-d + Mooncake. 16 infer nodes

Requirements

  • A Slurm cluster with 8-GPU nodes, a shared filesystem, and at least 32 nodes (16 trainer + 16 inference) for the RL configs. This guide assumes the shared filesystem is mounted at /shared — adjust to your own path. If you have fewer nodes, drop seq_len, lower num_train_nodes, and reduce cp accordingly.
  • InfiniBand/RDMA NICs for the Mooncake KV pool (llm-d append).
  • Sandboxes. Rollout and eval agents run in sandboxes, wired for Prime Intellect Sandboxes by default. If you use those, install the prime CLI separately and log in:
uv tool install prime
prime login   # or: prime config set-api-key <your-key>

To run on your own infrastructure instead, swap env.agent.runtime on each source for a runtime your environments support (e.g. a local Docker backend).

  • Environment variables, exported in the shell you launch from — the launcher passes its environment to every component:

    • HF_TOKEN — the GLM-5 family checkpoints are gated models.
    • WANDB_API_KEY — both RL variants log to W&B ([monitors.wandb]).

Install llm-d (llm-d append only)

The llm-d router ships as vendored binaries (epp, envoy, pd-sidecar). Build them once into third_party/llmd/bin:

bash scripts/install_llmd.sh

Setup

Clone prime-rl onto the shared filesystem and install everything, including the environments — they are opt-in uv workspace members, so --all-packages is required:

git clone https://github.com/PrimeIntellect-ai/prime-rl.git /shared/prime-rl
cd /shared/prime-rl
git submodule update --init -- deps/verifiers deps/renderers deps/prime-envs deps/pydantic-config
uv sync --all-extras --all-packages

Tweak before launching

  • swe.toml marks two # FILL IN values: output_dir (point it at your shared filesystem) and [slurm] partition.
  • swe-llmd.toml [inference.kv_cache_offload] device_name — the RDMA NIC list for Mooncake. Auto-detection is unreliable; set it by hand from nvidia-smi topo -m on your nodes.
  • swe-llmd.toml [inference.kv_cache_offload.cpu] num_bytes — 1TB per node by default; lower it if your nodes have less RAM.

Start the run

The rl entrypoint submits an sbatch job whenever the config has a [slurm] table — there is no separate launcher. From the shared checkout:

# GLM-5.3 RL behind the default vllm-router
uv run rl @ examples/advanced/glm-5.3/swe.toml

# with the llm-d router + Mooncake KV offload appended
uv run rl @ examples/advanced/glm-5.3/swe.toml @ examples/advanced/glm-5.3/swe-llmd.toml

The inference configs are standalone pre-flights: they serve the FP8 checkpoint through the same entrypoint the trainer uses (/update_weights, /load_lora_adapter, /init_broadcaster included — never call vllm serve directly), and are a fast way to check that this cluster can serve the model at all before committing it to a run:

uv run inference @ examples/advanced/glm-5.3/infer/pd.toml
uv run inference @ examples/advanced/glm-5.3/infer/pd-llmd.toml

Monitor with the dashboard

Start the local run dashboard on the head node — it only reads the run directories, so it is safe to point at a live run while the job is training:

uv run dashboard /shared/outputs   # serves http://localhost:7788

If the head node is remote, forward the port from your laptop and open http://localhost:7788 in a browser:

ssh -L 7788:localhost:7788 <head-node>

Pick the run and you get five views:

  • Metrics — the W&B-style overview, read from the run's metrics.jsonl. Watch reward/{all,env}/mean trend upward over steps, and seq_len/* + is_truncated/* for rollout health.
  • Configs — the launch TOML next to the merged, resolved per-process configs the run actually started with.
  • Trace — a per-episode rollout viewer with per-token overlays (advantage, entropy, sampling mismatch, loss/content masks), showing the transcript, a wall-clock timeline, a terminal replay of model and tool activity, and a semantic graph of the model-call chain.
  • Logs — the merged component logs (trainer, orchestrator, inference), also on disk under <run_dir>/logs/.
  • Reports — markdown reports written to <run_dir>/reports/, if any tooling produces them.

Pass several output directories to track parallel experiments side by side (uv run dashboard /shared/outputs/a /shared/outputs/b); a taken port automatically bumps to the next free one. SLURM stdout/stderr and the generated sbatch script land in <run_dir>/launcher/.

Checkpoint and resume

Both RL configs ship without [ckpt] — add a [ckpt] overlay (e.g. interval = 100) for periodic checkpoints. To resume, re-run the same command with --resume (latest checkpoint) or --resume.step <N>, a stable --run.name, and a --max-steps at least the target final step. Trainer checkpoints are DCP-sharded; export HF-format weights with tools/convert_dcp_to_bf16.py. See Training for the full resume and export reference.

See Scaling for SLURM details and Inference for the disaggregated-inference and router reference.

SFT

The SFT configs live under sft/h200/ — they are tuned for 8-GPU H200 nodes. Compose the base config with a data overlay:

uv run sft @ examples/advanced/glm-5.3/sft/h200/base.toml @ examples/advanced/glm-5.3/sft/h200/math-10k.toml

This will start a SFT run with the following configuration:

  • The model is zai-org/GLM-5.3-BF16
  • The data is PrimeIntellect/INTELLECT-3-SFT-10K (math split)
  • 8 nodes at 131k context: CP 8, EP 8, full activation checkpointing with activation offloading, optimizer state offloaded to CPU
  • DSA attention runs on the FlashMLA sparse forward and the cuDNN sparse backward (the default model.dsa_backend = "cudnn_flashmla")

For a fake-data dry run, append fake.toml instead. You can use the same dashboard to monitor the SFT run.

12 nodes at 16k

For 16k-token samples, append 16k-12-node.toml after the data overlay:

uv run sft @ examples/advanced/glm-5.3/sft/h200/base.toml @ examples/advanced/glm-5.3/sft/h200/math-10k.toml @ examples/advanced/glm-5.3/sft/h200/16k-12-node.toml

On 12 nodes the sharded model state fits in GPU memory without CP or any offloading. Each GPU runs one 16k sequence per step (batch 96), and transformer blocks compile with fullgraph = true. Full activation checkpointing stays on; peak memory is about 115 GiB per GPU.