Files
prime-rl/examples
carstenandClaude Opus 5.5 699342d3dc Merge upstream/main into trinity-dsv41; port V4.1 engram onto shared n-gram module
Merges upstream/main (eed0e44c) into trinity-dsv41 (PR #4057 + trinity LoRA warm
start, adapter reload timeouts, renderers fork). Submodule pins for verifiers,
prime-envs and prime-kernels follow upstream/main; renderers stays on the
trinity fork.

Following b417ea31 (#4293), the three n-gram files take upstream's side and
DeepSeek-V4.1's engram is ported onto the shared module:

- engram.py: DeepseekV41NGramHasher(NGramHasher) replaces EngramHasher. It
  maps tokens through the compressed token map, cuts look-back at document
  starts only (no EOS reset), pads with compressed_token_map[pad_token_id],
  takes consecutive_primes_from(engram_vocab_size, skip=24*table, count=24)
  as head sizes, and uses odd PCG64 multipliers seeded with
  10007 * engram_layer_ids[table]. Table rows come from the config
  (384006168 / 384016682) and are checked to hold every bucket.
  DeepseekV41Engram is now only the gate (wkv, q/k weights).
- modeling: DeepseekV41Model.ngram = NGramEmbeddings(hasher, {1: 0, 14: 1},
  head_dim=256, non-persistent layout, deduplicating lookup). The row is
  hashed once and looked up outside the layers. layers[i].engram runs the
  gate inside the AC-wrapped compiled block. PackedContext carries
  cu_seqlens.
- conversion: HF layers.{i}.engram.embed.weight <-> model.ngram.tables.{i}.weight.
  The gate keeps its HF name, so vLLM-side names are unchanged.
- layers/ngram.py: NGramTable/NGramEmbeddings gain persistent_layout and
  deduplicate_lookup options.
- ngram_lookup.py: RowShardedLookup(deduplicate=True) sends unique ids
  (torch.unique) and sums repeated-row grads in fp32. ngram_runtime warms up
  the all-to-all before training.
- model.py: drops AllToAllEmbeddingParallel, the FSDP-ignored table path, the
  hand-applied divide factor and the dp_replicate guard. freeze_engram_tables
  is keyed on NGramTable. optim/__init__.py drops the "engrams." Muon rule.
- transports: the fp8 row-chunk NCCL export is keyed on NGramTables that no
  ChunkedConvOp converts (utils.weights.get_row_chunked_tables). It handles
  plain, 1-D Shard(0) and multi-dim meshes (replicate or size-1 FSDP dims).
  filesystem.py rejects such tables by the same rule instead of
  hasattr(rows_per_rank).
- dsv41_indexer.py: upstream moved fp8_indexer to DeepGEMM and removed
  _triton_fp8_indexer_kernel, so V4.1's two-level indexer now vendors that
  Triton kernel (KEY_ALIGNMENT 16) to keep scoring unchanged.

Equivalence against the pre-merge tree (HEAD 282af805):
- Hashed ids are bit-identical for two synthetic configs with packed
  multi-document rows (incl. 1-token docs, 24 heads/table, many collisions).
  Primes, offsets, multipliers and pad id are identical. The real config
  gives identical 2x24 primes, multipliers and 384006168/384016682 rows.
- The table lookup + gate matches the old DeepseekV41Engram bitwise
  (outputs and grads of the table, wkv, q/k and the streams), fp32 and bf16,
  CPU and CUDA.
- A 6-layer V4.1 stack (attention/MoE stubbed), loaded from the same HF
  state dict, matches bitwise in its output and all 58 HF-named grads.
- RowShardedLookup(deduplicate) on gloo with 2 and 3 ranks and uneven rows:
  outputs bitwise equal to a local lookup and to the old _AllToAllLookup.
  fp32 grads are bitwise equal to the old path. bf16 grads differ by about
  1 bf16 ulp, because the old path accumulated into an fp32 master.
- The fp8 export on gloo (plain, 1-D, replicate x shard, size-1 x shard)
  reassembles byte-identical to quantize_rows_ue8m0 of the full table.

Untested here (no SM90 GPUs, one free GPU): multi-GPU FSDP+RowShardedLookup
training, the NCCL export through PyNccl into vLLM, the vLLM RowChunkWriter,
and the GPU-only test_deepseek_v41.py (skipped on SM86).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 17:55:47 +00:00
..

Examples

End-to-end usage examples for prime-rl, referenced from the top-level README.

New here? Follow basic/reverse-text/ first — it trains a small model end-to-end on 2 GPUs and introduces the launch → dashboard → checkpoint flow the advanced examples reuse.

advanced/ — frontier models, multi-node

Larger runs on frontier models, one folder per model, each with a launch README covering requirements, credentials, launch, monitoring, and resume:

  • qwen3-30b-a3b/ — Qwen3-30B-A3B RL on math (i3_math), SWE (r2e-gym), and agentic tool use (general-agent on Modal). 2 train + 2 infer nodes; the SWE config runs at 131k context with ep = 8 + cp = 2.
  • glm-4.5-air/ — GLM-4.5-Air (100B MoE) RL across search, SWE, and terminal domains at 131k context, with agents in sandboxes. 2 train + 4 infer nodes (SWE: 1 + 3).
  • glm-5.3/ — the GLM-5 family at scale: 16 trainer nodes, P/D-disaggregated FP8 inference, and an llm-d router + Mooncake KV-offload variant. Also ships standalone infer/ pre-flights.
  • intellect-3.1/ — reproduce the INTELLECT-3.1 run: 4 train + 12 infer nodes on SWE.
  • qwen3-235b-a22b/ — SFT max trainer perf: Qwen3-235B-A22B on 4 trainer nodes at 16k context, a throughput reference using the max trainer throughput recipe.

All advanced configs submit through SLURM (the rl entrypoint writes the sbatch job when the config has a [slurm] table) and are monitored with uv run dashboard. See the per-model README for the full walkthrough.

basic/ — 1 to 8 GPUs

Walk-throughs for the core environments (baseline eval → optional SFT warmup → RL → eval), each with its own README:

extra/ — beyond the core loop

Examples that don't follow the basic eval → SFT → RL walk-through pattern:

  • dynamo/ — five-step Qwen3 math training with external Dynamo inference and NCCL weight updates
  • vlm/ — Qwen3.5 / Qwen3.8 multi-node image RL and dense + MoE LoRA SFT
  • Frontier-model configs without launch walkthroughs (minimax-m2.5, nemotron-3-super, deepseek-v4-flash) live in configs/advanced/.