Files
prime-rl/docs/advanced.md
T
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

9.8 KiB

Advanced

This page covers the specialized features layered on top of the core training stack: our custom model implementations (with EP for MoE families and CP for long-context training), multimodal training, LoRA training, multi-tenant training, and disaggregated prefill/decode inference. For developer-side workflows (adding new model architectures, debugging modeling code at small scale), see Development.

Table of Contents

Custom Modeling

prime-rl ships custom optimized model implementations for several MoE families. With model.impl = "auto" (default) the trainer picks the custom path when the HF config type is registered, falling back to plain HF otherwise. To force one:

[trainer.model]
impl = "custom"        # or "hf" to force the HF path
Family HF config types EP CP
GLM-5 / GLM-5.2 (glm_moe_dsa) zai-org/GLM-5, zai-org/GLM-5-FP8, zai-org/GLM-5.2, zai-org/GLM-5.2-FP8 ✅ ✅
Qwen3 MoE Qwen/Qwen3-30B-A3B, … ✅ ✅
Qwen3.5 MoE Qwen/Qwen3.5-35B-A3B, … ✅ ✅
Qwen3 / Qwen3.5 VLMs see Multimodal training MoE only ✅
Laguna poolside/Laguna-XS.2 ✅ ✅
MiniMax M2 MiniMax/MiniMax-M2 ✅ ✅
Nemotron H nvidia/Nemotron-3-Nano-30B-A3B, … ✅ ❌
Trinity (AFMoE) arcee-ai/Trinity-Mini, … ✅ ✅
GLM-4 / GLM-4.5 / INTELLECT-3 THUDM/GLM-4-9B-0414, zai-org/GLM-4.5, PrimeIntellect/INTELLECT-3, … ✅ ✅
GPT-OSS (HF MoE) openai/gpt-oss-20b, openai/gpt-oss-120b ❌ ✅

The custom path enables you to set EP, CP, selective activation checkpointing, low-precision training ([trainer.model.quantization]), and faster MoE kernels (moe_use_grouped_mm = true, default). Forcing impl = "hf" is mostly useful when debugging — it's slower and disables most MoE-specific knobs.

Low-precision training

Set [trainer.model.quantization] to train dense linears and MoE expert GEMMs in low precision. Two backends are available via the type discriminator:

  • type = "fp8" — DeepGEMM FP8 blockwise (requires SM90+ / Hopper). Options: enable_grouped_gemm (FP8 MoE expert GEMM). Both default on.
  • type = "mxfp8" — torchao MXFP8 microscaling (requires SM100+ / Blackwell). Options: enable_grouped_gemm, enable_a2a (MXFP8 expert-parallel all-to-all), and recipe (mxfp8_rceil default or mxfp8_rceil_wgrad_with_hp).
[trainer.model.quantization]
type = "mxfp8"
recipe = "mxfp8_rceil"
enable_a2a = true

GLM-5.2 adds IndexShare: the DSA sparse-attention indexer runs only on a subset of layers and the remaining layers reuse the cached top-k indices. The trainer reads this schedule from the model's indexer_types config field and enables the index cache automatically, so no extra config is needed. To override the schedule manually, set [trainer.model.index_cache] (topk_freq or topk_pattern).

Expert Parallelism Backends

model.ep_comm_backend picks the all-to-all kernel used for EP dispatch/combine:

  • torch (default): TorchTitan's all-to-all collective. Works everywhere, no extra install.
  • deepep: Utilizes DeepEP's custom all-to-all collectives. This provides better performance if EP dimension spans multiple nodes. We provide pre-built binaries for H100/H200 with cuda runtime 12.9 installed, you can install them by running uv sync --all-extras. DeepEP requires some careful tuning to achieve optimal performance, tuning parameters are deepep_num_sms and deepep_token_chunk_size.

With DeepEP, gradient clipping is currently not supported. (optim.max_norm is set to None automatically.)

Multimodal Training

Supported Families

The built-in VLM registry covers:

Family model_type Vision attr LM attr
Qwen3-VL qwen3_vl model.visual model.language_model
Qwen3-VL MoE qwen3_vl_moe model.visual model.language_model
Qwen3.5 qwen3_5 model.visual model.language_model
Qwen3.5-MoE qwen3_5_moe model.visual model.language_model

For a model not in the table, look up the attribute paths on the loaded HF model with model.named_children() and set them under [model.vlm] directly.

Enabling VLM Mode

Add [model.vlm] and bfloat16 dtypes:

[model]
name = "Qwen/Qwen3-VL-4B-Instruct"
optimization_dtype = "bfloat16"
reduce_dtype = "bfloat16"

[model.vlm]
vision_encoder_attr = "model.visual"
language_model_attr = "model.language_model"
# freeze_vision_encoder = true  # default; set false to fine-tune the encoder

The weight-broadcast key prefix is derived as {language_model_attr}.layers. automatically.

To add a new model family permanently, append an entry to VLM_REGISTRY in src/prime_rl/utils/vlm.py.

Limitations

  • Vision encoder frozen by default. Set freeze_vision_encoder = false to fine-tune it; in that case it's FSDP-sharded per block. The combination freeze_vision_encoder = false + LoRA is rejected by a config validator — LoRA freezes everything non-adapter, so unfreezing the encoder under LoRA would be a silent no-op.
  • No multimodal-safe truncation. Token sequences are truncated to seq_len, but pixel_values and image_grid_thw pass through unchanged. If a sample's tokens overflow, image tokens may get dropped while image tensors still describe the full image set. Set seq_len to cover your longest sample.
  • bfloat16 mandatory. The trainer config validator refuses any other optimization_dtype / reduce_dtype for VLMs — vLLM serves VLMs in bfloat16 and a mismatch breaks the importance ratio.
  • Higher KL mismatch with multi-image inputs. Expect noisier mismatch_kl than text-only; this is from minor numerical differences between the trainer's and vLLM's image processing.
  • Images aren't logged to monitors. Sample logging captures the prompt text but not the actual images.

LoRA Training

LoRA is enabled by adding [model.lora]:

[model.lora]
rank = 16
alpha = 32
dropout = 0.0

target_modules defaults to a reasonable cross-family set (q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj, experts, plus a few latent-projection names for Nemotron). Unknown names are silently ignored, so the defaults work across architectures. Add architecture-specific names to extend coverage (e.g. in_proj / out_proj for Mamba).

LoRA is supported across SFT and RL. For RL, NCCL weight broadcast is not supported with LoRA — the default NCCL transport automatically falls back to filesystem when LoRA is enabled. To save the raw adapter alongside the merged HF weights:

[ckpt.weights]
save_adapter_separately = true

LoRA pairs naturally with multi-tenant training — each tenant gets its own adapter and the backbone is shared across all of them in trainer memory.

Multi-Tenant Training

Multi-tenant training lets a single trainer + inference deployment serve many concurrent LoRA "tenants" — each a fully isolated run with its own orchestrator, LoRA adapter, optimizer, scheduler, checkpoints, and progress tracking — sharing the same backbone weights and the same vLLM server. This is the topology behind hosted training on the Prime Intellect platform (Lab). The trainer-side implementation is the MultiRunManager singleton, enabled by setting trainer.max_concurrent_runs > 1. For the full API surface, see src/prime_rl/trainer/runs.py.

Disaggregated Prefill/Decode Inference

For large MoE serving, splitting prefill and decode onto separate vLLM groups can substantially improve throughput. Pick the prefill:decode ratio based on workload shape:

Workload P:D ratio Why
Agentic (SWE, Lean) 3:1 Long growing contexts → prefill-heavy
Non-agentic (math, chat) 1:2 Short prompts, long generations → decode-heavy

Example config: examples/advanced/glm-5.2/swe.toml — full RL run on GLM-5 with P/D disaggregation behind a vllm-router, FP8 inference, and NCCL weight broadcast, paired with an inference config from examples/advanced/glm-5.2/infer/.

Monitor live queue depths to detect imbalance:

curl -s http://<prefill_node>:8100/metrics | grep num_requests_waiting
curl -s http://<decode_node>:8200/metrics | grep num_requests_waiting

If prefill queues and decode is idle, add prefill nodes (and vice versa).

Required setup for disaggregated P/D (NIXL/UCX). The pip-wheel NIXL's bundled UCX segfaults on the prefill→decode KV transfer (signal 11: invalid permissions for mapped object in libucs.so) — reproduced on vLLM 0.22 and 0.23, with/without mooncake, with/without llm-d. Building NIXL against UCX 1.19.x from source is therefore required (not optional) for disaggregated P/D.

salloc -N 1 --gres=gpu:1 bash -c 'bash scripts/install_nixl_from_source.sh'
uv pip install --reinstall --no-deps deps/nixl_cu12-*.whl

The script writes UCX 1.19 to third_party/ucx/; the bundled sbatch templates prepend it to LD_LIBRARY_PATH so it overrides the system version. Re-run both commands after every uv sync, since the lock pins the wheel.