#3638 set a reduce-scatter buffer cap of 2 on the fp32 MoE router's FSDP unit. Back then the experts were their own FSDP unit, so with one buffer the router's reduce-scatter had to wait for the experts' large reduce-scatter to finish, stalling backward. #3753 later moved the experts into the block's FSDP unit (for `fullgraph` compile). With that layout and full activation checkpointing, the expert reduce-scatter finishes inside the next layer's recompute, so the second buffer no longer buys anything. This PR makes the cap configurable (`model.reduce_scatter_max_input_buffers`), sets it once on the root FSDP module, and changes the default to 1 (torch's default). - Before: fp32-router runs had an effective cap of 2 (torch takes the max over all units), bf16-router runs had 1. Now every run uses the configured value, 1 by default. - A single root-level call is enough: torch keeps one reduce-scatter queue and resolves the cap once as the max over all FSDP units. - Cap 2 helps only when reduce-scatters are exposed, which in our runs needed short sequences without activation checkpointing (last rows and the second figure). It is free with the fp32 router but costs ~9 GiB/GPU on the bf16 path with `ep=1`. Cap 3 never beat 2. **Why one buffer is enough now.** The block and the fp32 router are still separate FSDP units with separate reduce-scatters. The cap is a single global count of reduce-scatters allowed in flight, and at cap 1 each unit's hook must wait for the previous reduce-scatter to finish before launching its own. What #3753 changed is which reduce-scatter that is when the router's hook runs in layer `L`'s backward: ``` Before #3753 (experts are their own unit), cap 1, backward of layer L: compute [ recompute L ][ MoE bwd L ][ router bwd ][ STALL ][ attn bwd L ] RS stream [====== experts L RS ======][ router L ] ^ launched just before the router hook, with no compute in between to hide it After #3753 (experts in the block's unit), cap 1, backward of layer L: compute [ recompute L ][ MoE bwd L ][ router bwd ][ attn bwd L ] RS stream [== block L+1 RS ==] [ router L ] ^ launched at the end of layer L+1, so it has all of layer L's recompute and MoE backward to finish ``` Before #3753 that big reduce-scatter launched just before the router's hook, with no compute in between to hide it, and cap 2 was the fix. Now it is the previous layer's, launched a whole layer earlier, so the current layer's recompute and MoE backward run while it finishes. It only stalls when that compute is shorter than the reduce-scatter (the second figure). Median s/step and rank-0 peak GiB, GLM-4.5-Air truncated to 24 layers (16 for 8k without AC), 2x8 H200, fp32 router, untraced, lower is better. Spread is the gap between two same-code runs on different node pairs. | layout | tokens/GPU, AC | cap 1 (PR) | cap 2 (main) | cap 3 | spread | peak GiB, cap 1 / 2 / 3 | | ------ | -------------- | ---------- | ------------ | ----- | ------ | ----------------------- | | `ep=8` | 16k, full | 4.697 | 4.650 | 4.693 | 0.068 | 75.3 / 75.1 / 76.1 | | `ep=1` | 16k, full | 4.535 | 4.521 | 4.543 | 0.041 | 88.9 / 88.4 / 98.0 | | `ep=8` | 4k, full | 1.238 | 1.234 | 1.237 | 0.002 | 63.6 / 63.6 / 63.6 | | `ep=1` | 4k, full | 2.056 | 2.064 | 2.050 | 0.006 | 80.1 / 80.1 / 88.8 | | `ep=8` | 1k, none | 0.848 | 0.841 | 0.826 | 0.011 | 68.2 / 68.2 / 68.1 | | `ep=1` | 8k, none | 1.318 | 1.279 | 1.280 | 0.001 | 102.7 / 102.7 / 111.4 | | `ep=1` | 4k, none | 1.761 | 1.629 | 1.627 | 0.002 | 109.6 / 109.6 / 118.3 | | `ep=1` | 1k, none | 1.651 | 1.515 | 1.506 | 0.005 | 85.6 / 85.6 / 94.4 | In a whole-step trace (`ep=8`, 16k tokens/GPU, full AC, rank 0), neither `main` nor this PR has a compute-stream gap of 2 ms or more anywhere inside the model's backward. The only such gaps are at the start of forward, the start of backward, and the end of backward, where the last hooks and FSDP's final callback wait on the last reduce-scatters. Notation in the figures (`RS` = reduce-scatter, `AG` = all-gather): - `E`: the experts' gradient reduce-scatter, over the ranks that hold copies of the same experts. - `D`: the reduce-scatter of the block's dense parameters (attention, norms, shared experts). - `R`: the fp32 router's reduce-scatter (the router is its own FSDP unit). - `D+E`: the whole block's reduce-scatter, used when there is no EP and the block has one parameter group.  **Figure:** one layer of backward at a production shape (`ep=8`, 16k tokens/GPU, full activation checkpointing), before and after this PR. The expert reduce-scatter (orange, top row) finishes while the next layer is still recomputing, well before anything waits on it, so dropping to cap 1 adds no stall.  **Figure:** what failure looks like: the compute stream waiting on a reduce-scatter (red). It shows up at this odd shape we don't run in production (one node, 8 layers, `ep=2`, 2k tokens/GPU, no activation checkpointing), where each layer's expert reduce-scatter outlasts the compute that would hide it. Raising the cap to 2 (bottom) removes most of the wait and makes the step 6.5% faster (0.277 to 0.259 s) at no extra memory. We include it to show what to look for in traces and when to bump the cap. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
prime-rl: Async RL Training at Scale
Overview
prime-rl is a framework for large-scale reinforcement learning. It is designed to be easy to use and hackable, yet capable of scaling to 1000+ GPUs. Here is what we think sets it apart:
- Fully asynchronous RL for high-throughput agentic training at scale.
- Performant: built to train 1T+ MoE models on 1000+ GPUs with FSDP2 for training and vLLM for inference, with FP8 inference, PD disaggregation, EP and CP parallelism, and more.
- Native integration with
verifiersenvironments through the Environments Hub, including built-in support for SWE and agentic environments. - End-to-end post-training: SFT, RL training, and evals.
- Multi-node deployment with Slurm support.
- Multimodal support for VLMs such as Qwen3.5.
- Hackable, modular, and extensible by design.
- One-line SLURM deployment for frontier models — e.g.
GLM-5FP8 with P/D disaggregation, thellm-drouter, and Mooncake KV offload.
Models support
The trainer runs the PrimeRL model implementations under src/prime_rl/trainer/models/: dense Llama, Qwen3 and Qwen3.5, plus the families in the table below, with expert parallelism (EP) for MoE layers, context parallelism (CP) for long sequences, and additional kernels like quack-kernels. Other architectures fail at trainer setup.
| Family | Example IDs | MoE | EP | CP |
|---|---|---|---|---|
GLM-5 (glm_moe_dsa) |
zai-org/GLM-5, zai-org/GLM-5-FP8 |
yes | ✅ | ✅ |
Qwen3 MoE (qwen3_moe) |
Qwen/Qwen3-30B-A3B, … |
yes | ✅ | ✅ |
Qwen3.5 MoE (qwen3_5_moe) |
Qwen/Qwen3.5-35B-A3B, … |
yes | ✅ | ✅ |
| Qwen3.5 VLMs | see advanced.md (qwen3_5, qwen3_5_moe) |
MoE only on MoE VLMs | MoE only | ✅ |
Poolside Laguna (laguna) |
poolside/Laguna-XS.2 |
yes | ✅ | ✅ |
MiniMax M2 (minimax_m2) |
MiniMax/MiniMax-M2 |
yes | ✅ | ✅ |
Nemotron H (nemotron_h) |
nvidia/Nemotron-3-Nano-30B-A3B, nvidia/Nemotron-3-Super-120B-A12B, … |
yes | ✅ | ✅ |
Trinity (afmoe) |
arcee-ai/Trinity-Mini, … |
yes | ✅ | ✅ |
GLM-4 · GLM-4.5 MoE · INTELLECT-3 (glm4_moe) |
THUDM/GLM-4-9B-0414, zai-org/GLM-4.5-Air, zai-org/GLM-4.5, PrimeIntellect/INTELLECT-3, … |
yes | ✅ | ✅ |
GPT-OSS (gpt_oss) |
unsloth/gpt-oss-20b-BF16, … |
yes | ✅ | ✅ |
Setup
We develop and test on NVIDIA RTX 3090/4090/5090, A100, H100, H200, and B200. If your setup fails, please create an issue.
Prerequisites
Currently, you need at least one NVIDIA GPU to use prime-rl. If you don't already have access to one, we recommend our compute platform for everything from renting on-demand single GPUs for developing, debugging and small ablations, to reserving 1000+ GPU clusters for production-scale training.
Quick Setup
Set up prime-rl in a single command.
curl -sSL https://raw.githubusercontent.com/PrimeIntellect-ai/prime-rl/main/scripts/install.sh | bash
Manual Setup
- Clone the repository
git clone https://github.com/PrimeIntellect-ai/prime-rl.git
cd prime-rl
- Initialize submodules
git submodule update --init -- deps/verifiers deps/renderers deps/prime-envs deps/pydantic-config
- Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh
source $HOME/.local/bin/env
- Install dependencies from the lock file
uv sync --all-extras
Note
: Environments are opt-in uv workspace members —
uv sync --all-extrasdoes not install them. To train on them, install all withuv sync --all-extras --all-packages, or a subset withuv sync --package prime-rl --package <env>.
Validate your environment setup
- Check that the environment uses Python 3.12
uv run python -V
- Check that
flash-attnis installed
uv run python -c "import flash_attn"
- Check that you can run SFT trainer (this requires 1 GPU)
uv run sft @ configs/debug/fake/sft.toml
- Check that you can run the inference server (this requires 1 GPU)
uv run inference --vllm.model Qwen/Qwen3-0.6B
- Check that the full RL stack (inference + orchestrator + trainer) runs end-to-end (this requires 2 GPUs)
uv run rl @ examples/basic/reverse-text/rl.toml
Additional Setup
- If you want to log your runs to W&B, log in
uv run wandb login
# Or set `export WANDB_API_KEY=...`
- If you require gated/ private models or datasets from HuggingFace, log in
uv run hf auth login
# Or set `export HF_TOKEN=...`
Training Examples
We provide end-to-end training examples in the examples directory to highlight features of the framework and guide you through the process of training your own models.
Basic Training: 1 to 8 GPUs
Follow this guide to learn the basics of prime-rl. You can train your own models on 1 to 8 GPUs. Ideal for getting started and exploring the capabilities of the framework. These guides cover most use cases -- single-turn, multi-turn, tool calling, etc. -- on toy environments and small models.
- Reverse Text: Train
Qwen3-0.6Bto reverse a small chunk of text. Demonstrates tiny-scale single-turn SFT and RL training. Can be trained on a single consumer GPU in a few minutes, and is ideal for getting started. - Wordle: Train
Qwen3-1.7Bto play Wordle. A fun example of multi-turn SFT and RL training. Can be trained on a 2-4 H100 GPUs in a few hours. Ideal for exploring the multi-turn training capabilities of the framework. - Alphabet Sort: Train
Qwen3-4B-Instruct-2507to sort names alphabetically. Demonstrates multi-turn RL training via LoRA without SFT warmup. Can be trained on a single H100 GPU in just over an hour. Ideal for exploring LoRA-based training. - Wiki Search: Train
Qwen3-4B-Instruct-2507to answer trivia questions by searching through a Wikipedia. Demonstrates multi-turn with web search tool use. - Hendrycks Sanity: Run a sanity check experiment on
Qwen3-1.7Busing a subset of MATH filtered to problems thatDeepSeek-R1-Distill-Qwen-1.5Bpartially solves (20-80%). Useful for algorithm ablations.
Advanced Training: 32 - 2048 GPUs:
Follow this guide to train large models on hard reasoning and agentic tasks. These guides are designed to be run from a Slurm cluster.
- Qwen3-30B-A3B: Train
Qwen3-30B-A3Bon math, SWE, and agentic tool use. - GLM-4.5-Air: Train
GLM-4.5-Airon search, SWE, and terminal tasks. - GLM-5: Large-scale
GLM-5/GLM-5.3training with P/D disaggregation, thellm-drouter, and FP8.
Docs
Check out the docs directory for in-depth guides on how to use prime-rl.
- Overview - Architecture, install, and a copy-pasteable end-to-end RL run
- Configuration - TOML composition, CLI overrides, env vars, validation
- Training - RL, SFT, checkpointing, observability, rules of thumb
- Eval - Standalone evals against any inference server, online evals, resume, platform upload
- Scaling - Single-GPU through multi-node, FSDP/EP/CP, SLURM, benchmarking
- Algorithms - Async/off-policy training, the AIPO loss, advantage and filter plugins, trajectory merging
- Advanced - Custom modeling, multimodal training, LoRA
- Development - Test suite, pre-commit hooks, adding a new model
Contributing
We warmly welcome community contributions! We use issues to track bugs, feature requests, and share our internal roadmap. If you encounter bugs, have pain points during development, or have ideas for new features, please open an issue.
Contributions are welcome via PR. Please follow these guidelines:
- Install the pre-commit hooks to ensure your code is formatted correctly.
- Please keep your PR in "Draft" until it is ready for review.
- If your PR resolves an issue, please link the issue in the PR description
- If you can, try running the test suite locally to ensure your changes are working as expected.
Pre-Commit Hooks
Please install the pre-commit hooks to ensure your code is formatted correctly.
uv run pre-commit install
Tests
uv run pytest -v # everything
uv run pytest tests/unit -v # unit only
uv run pytest tests/integration -v # integration only
uv run pytest -v -m "not gpu" # CPU-only (inverse of the gpu marker)
License
This project is licensed under the Apache 2.0 license, as found in the License file.
Citation
If you find our work useful, feel free to cite it using
@misc{primeintellect2025prime-rl,
author = {Prime Intellect},
title = {prime-rl},
url = {https://github.com/PrimeIntellect-ai/prime-rl},
year = {2025}
}