Compare commits

...
Author SHA1 Message Date
c7dc7929a0 chore: bump renderers to v0.1.8 (#3048)
Docker Push / Push CUDA image to Docker (push) Canceled after 0s
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-15 16:54:16 -07:00
0d2a7f5a12 chore: bump verifiers + research-environments (#3041)
Docker Push / Push CUDA image to Docker (push) Canceled after 0s
* chore: bump verifiers + research-environments to latest main

verifiers -> 1cfdd39c (incl. docker-runtime entrypoint fix #2015).
research-environments -> dd80d75b (incl. terminal-bench-2 use_prime_registry
fix #668).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* test: carry provider usage in advantage test rollouts

verifiers #2040 made Trace token counts usage-based, so the synthetic
rollouts (which only had token ids) reported 0 output/input tokens and the
length-penalty tests failed. Attach provider usage to the final sampled
turn so num_output_tokens / num_input_tokens reflect the intended lengths.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-15 16:16:59 -07:00
1cb5d91ab2 feat(trainer): ulysses CP beyond num_kv_heads via GQA KV-head replication (#3042)
Docker Push / Push CUDA image to Docker (push) Canceled after 0s
* fix(trainer): fuse relu2 MoE activation via torch.compile

F.relu(x).square() ran eagerly (the expert path graph-breaks out of the
layer-level compile at the @expert_parallel all-to-all and the _grouped_mm
custom op), materializing an extra full-size copy of the MoE intermediate —
the largest activation for high top-k models (NemotronH Super: top-22,
moe_intermediate 2688; 57.75 GiB at 65k tokens/GPU) and the empirical OOM
site. An explicit torch.compile on relu2 fuses relu+square into a single
pointwise kernel. Measured on Nemotron Super (2xH200 nodes, 16k tokens/GPU):
OOM -> fits at 126.5/139.8 GiB peak.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* feat(trainer): ulysses CP beyond num_kv_heads via GQA KV-head replication

Ulysses CP head-shards Q/K/V, capping the CP degree at num_key_value_heads —
for hybrid-Mamba GQA models like NemotronH Super/Ultra/Nano (2 KV heads) that
means cp <= 2, i.e. at most 2-way context sharding regardless of node count.
(NVIDIA post-trained Super at 256k-512k with CP=64 on Megatron's
sequence-sharded, Mamba-aware CP; prime-rl's ring CP is softmax-only.)

Replicate each KV head cp/num_kv_heads times before the existing seq->head
all-to-all. GQA groups query heads contiguously, so rank r's query-head slice
[r*Hq/cp, (r+1)*Hq/cp) attends KV head floor(r*Hkv/cp) — exactly the replica
the all-to-all lands on rank r. Backward of repeat_interleave sums gradients
over replicas, the exact GQA KV gradient. Q path and the num_kv_heads >= cp
case are unchanged; the Mamba layers already head-shard independently via
cp_mamba (128 heads, n_groups=8 -> cp <= 8 for NemotronH).

New constraint: cp % num_kv_heads == 0 when num_kv_heads < cp (asserted).
Unlocks cp=4/8 for NemotronH on H200 where cp=2 made 131k context
memory-infeasible (65k tokens/GPU through a top-22/512-expert MoE).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* chore: drop relu2 comment

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-16 00:35:58 +02:00
8 changed files with 154 additions and 9 deletions
+1 -1
+1 -1
+2
View File
@@ -107,6 +107,8 @@ ep_comm_backend = "torch" # or "deepep"
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`.
```toml
[trainer.model]
impl = "custom"
@@ -798,6 +798,7 @@ class MoE(nn.Module):
self.expert_bias = torch.zeros(self.experts.num_experts, dtype=torch.float32)
@torch.compile(dynamic=True)
def relu2(x: torch.Tensor) -> torch.Tensor:
return F.relu(x).square()
@@ -19,8 +19,17 @@ Key benefit: the attention kernel itself does not need to be CP-aware. The
all-to-all is purely on Q/K/V tensors, so this works out of the box with
softmax flash-attn, linear attention, mamba, etc., without rewriting kernels.
GQA models with fewer KV heads than cp_size (e.g. NemotronH: 32 query heads, 2
KV heads) are handled by replicating each KV head cp_size / num_key_value_heads
times before the seq->head all-to-all. Query heads are grouped contiguously in
GQA, so the replicated layout lands every rank on exactly the KV head its local
query-head slice attends to; the backward of the replication sums gradients
over replicas, which is the exact GQA KV gradient.
Constraints:
- cp_size must divide both num_attention_heads and num_key_value_heads.
- cp_size must divide num_attention_heads.
- cp_size must divide num_key_value_heads, OR num_key_value_heads must divide
cp_size (the KV-replication path).
- Sequence length must be divisible by cp_size.
"""
@@ -41,6 +50,24 @@ def update_ulysses_params(cu_seqlens: torch.Tensor, max_seqlen: int) -> None:
ULYSSES_PARAMS["max_seqlen"] = int(max_seqlen)
def _replicate_kv_heads(t: torch.Tensor, cp_size: int) -> torch.Tensor:
"""Replicate KV heads so a GQA tensor with fewer heads than cp_size can be
head-sharded: [S_local, H_kv, D] -> [S_local, cp_size, D].
Each KV head is repeated cp_size / H_kv times. GQA groups query heads
contiguously (query head j attends KV head j // (H_q / H_kv)), so after the
seq->head all-to-all rank r holds query heads [r * H_q/cp, (r+1) * H_q/cp)
— all attending KV head floor(r * H_kv / cp) — and replica index r maps to
the same head: floor(r / (cp / H_kv)). The backward sums gradients over
replicas, which is exactly the GQA KV gradient.
"""
s_local, h, d = t.shape
assert cp_size % h == 0, (
f"num_key_value_heads ({h}) must divide cp_size ({cp_size}) for the ulysses KV-replication path"
)
return t.repeat_interleave(cp_size // h, dim=1)
def _all_to_all_seq_to_head(t: torch.Tensor, cp_size: int, cp_group: dist.ProcessGroup) -> torch.Tensor:
"""Redistribute [S_local, H, D] -> [S_global, H_local, D].
@@ -48,7 +75,10 @@ def _all_to_all_seq_to_head(t: torch.Tensor, cp_size: int, cp_group: dist.Proces
ends up with the full sequence but only H/cp_size heads. Differentiable.
"""
s_local, h, d = t.shape
assert h % cp_size == 0, f"num_heads ({h}) must be divisible by cp_size ({cp_size})"
assert h % cp_size == 0, (
f"num_heads ({h}) must be divisible by cp_size ({cp_size}); "
"for GQA KV tensors with fewer heads than cp_size, replicate first via _replicate_kv_heads"
)
h_local = h // cp_size
# [S_local, cp_size, H_local, D] -> [cp_size, S_local, H_local, D]
@@ -96,8 +126,15 @@ def ulysses_flash_attn_varlen_func(
`cu_seqlens_*` and `max_seqlen_*` describe the *full* (un-sharded) sequence,
because after the seq->head all-to-all each rank holds the full sequence.
GQA with num_key_value_heads < cp_size: K/V heads are replicated up to
cp_size before the all-to-all (see `_replicate_kv_heads`), so each rank runs
grouped attention on its query-head slice with the single matching KV head.
"""
q = _all_to_all_seq_to_head(q, cp_size, cp_group)
if k.shape[1] < cp_size:
k = _replicate_kv_heads(k, cp_size)
v = _replicate_kv_heads(v, cp_size)
k = _all_to_all_seq_to_head(k, cp_size, cp_group)
v = _all_to_all_seq_to_head(v, cp_size, cp_group)
@@ -55,8 +55,15 @@ def _build_rollout(
)
parent = len(nodes) - 1
# Trace token counts are usage-based, so carry provider usage on the final sampled turn:
# every model-generated token as completion, the leading prompt + tool observations as the
# fed-in context (num_input_tokens = num_total_tokens - num_output_tokens).
output_tokens = sum(sampled_lengths)
input_tokens = 1 + sum(obs_lengths)
for i, n_sampled in enumerate(sampled_lengths):
ids = _take(n_sampled)
is_last = i == len(sampled_lengths) - 1
nodes.append(
vf.MessageNode(
message=vf.AssistantMessage(content="a"),
@@ -65,6 +72,7 @@ def _build_rollout(
logprobs=[-0.1] * n_sampled,
sampled=True,
parent=parent,
usage=vf.Usage(prompt_tokens=input_tokens, completion_tokens=output_tokens) if is_last else None,
)
)
parent = len(nodes) - 1
Generated
+101 -4
View File
@@ -41,7 +41,9 @@ members = [
"alphabet-sort-v1",
"apex-shortlist-v1",
"arxivmath-v1",
"automationbench-v1",
"bfcl-v3-v1",
"browsecomp-plus-v1",
"browsecomp-v1",
"browser-cua-example",
"browser-dom-example",
@@ -107,6 +109,7 @@ members = [
"scicode-v1",
"scratchpad-v1",
"self-reward",
"senior-swe-bench-v1",
"sentence-repeater",
"simpleqa-v1",
"simpleqa-verified-v1",
@@ -457,6 +460,40 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/64/b4/17d4b0b2a2dc85a6df63d1157e028ed19f90d4cd97c36717afef2bc2f395/attrs-26.1.0-py3-none-any.whl", hash = "sha256:c647aa4a12dfbad9333ca4e71fe62ddc36f4e63b2d260a37a8b83d2f043ac309", size = 67548, upload-time = "2026-03-19T14:22:23.645Z" },
]
[[package]]
name = "automation-bench"
version = "1.0.5"
source = { git = "https://github.com/mikasenghaas/AutomationBench.git?rev=6f0e683#6f0e6834930cf6906ed932e9c5b716206def40d7" }
dependencies = [
{ name = "anthropic" },
{ name = "httpx" },
{ name = "pydantic" },
{ name = "python-dotenv" },
{ name = "rich" },
{ name = "verifiers" },
]
[[package]]
name = "automationbench-v1"
version = "0.1.0"
source = { editable = "deps/research-environments/environments/tool_use/automationbench_v1" }
dependencies = [
{ name = "automation-bench" },
{ name = "datasets" },
{ name = "mcp" },
{ name = "openai" },
{ name = "verifiers" },
]
[package.metadata]
requires-dist = [
{ name = "automation-bench", git = "https://github.com/mikasenghaas/AutomationBench.git?rev=6f0e683" },
{ name = "datasets" },
{ name = "mcp", specifier = "<2" },
{ name = "openai" },
{ name = "verifiers", specifier = ">=0.2.1.dev42" },
]
[[package]]
name = "backoff"
version = "2.2.1"
@@ -634,6 +671,18 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/1e/e2/0e93b865f648b5519360846669a35f28ee8f4e1d93d054f6850d8afbabde/blis-1.3.3-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:8177879fd3590b5eecdd377f9deafb5dc8af6d684f065bd01553302fb3fcf9a7", size = 14250939, upload-time = "2025-11-17T12:27:53.847Z" },
]
[[package]]
name = "bm25s"
version = "0.3.9"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "numpy" },
]
sdist = { url = "https://files.pythonhosted.org/packages/7c/ab/39d08d4589dad6f5735a6b03ee083088dc37fba57fa45d4a0749393b9295/bm25s-0.3.9.tar.gz", hash = "sha256:895c679d952b7de8355edb5f3e1a620a1e2f294d1d42b919bf0821cce2e2f597", size = 80528, upload-time = "2026-05-13T23:08:20.952Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/48/83/06582913e2af0cf498cc478350070490b019c6f6b523cb8b6cfafd32f009/bm25s-0.3.9-py3-none-any.whl", hash = "sha256:db997475e82c9e81262b83fefe6a71304f2fdd0dafd037c8929828865fa6d465", size = 74475, upload-time = "2026-05-13T23:08:19.557Z" },
]
[[package]]
name = "boto3"
version = "1.43.40"
@@ -662,6 +711,31 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/dc/8c/5f7e73fd66b28f0705bc55d7060d41ef72328b656b86ca53e75765b3ba2c/botocore-1.43.40-py3-none-any.whl", hash = "sha256:0bc9d352267c9e48415c5d7bb61ff05c3f193eac2fc7e69cfd229a05fbab67d6", size = 15323870, upload-time = "2026-07-03T00:28:12.56Z" },
]
[[package]]
name = "browsecomp-plus-v1"
version = "0.1.0"
source = { editable = "deps/research-environments/environments/search/browsecomp_plus_v1" }
dependencies = [
{ name = "bm25s" },
{ name = "datasets" },
{ name = "mcp" },
{ name = "openai" },
{ name = "pystemmer" },
{ name = "tokenizers" },
{ name = "verifiers" },
]
[package.metadata]
requires-dist = [
{ name = "bm25s", specifier = ">=0.2.0" },
{ name = "datasets" },
{ name = "mcp", specifier = ">=1,<2" },
{ name = "openai" },
{ name = "pystemmer" },
{ name = "tokenizers" },
{ name = "verifiers", specifier = ">=0.2.0" },
]
[[package]]
name = "browsecomp-v1"
version = "0.1.0"
@@ -4890,8 +4964,8 @@ dependencies = [
[package.optional-dependencies]
all = [
{ name = "deep-ep", version = "1.1.0+1fd57b0", source = { url = "https://github.com/PrimeIntellect-ai/prime-rl/releases/download/v0.5.0/deep_ep-1.1.0+1fd57b0-cp312-cp312-linux_aarch64.whl" }, marker = "platform_machine == 'aarch64' and sys_platform == 'linux'" },
{ name = "deep-ep", version = "1.2.1+29d31c0", source = { url = "https://github.com/PrimeIntellect-ai/prime-rl/releases/download/v0.5.0/deep_ep-1.2.1+29d31c0-cp312-cp312-linux_x86_64.whl" }, marker = "platform_machine == 'x86_64' and sys_platform == 'linux'" },
{ name = "deep-ep", version = "1.1.0+1fd57b0", source = { url = "https://github.com/PrimeIntellect-ai/prime-rl/releases/download/v0.5.0/deep_ep-1.1.0+1fd57b0-cp312-cp312-linux_aarch64.whl" }, marker = "platform_machine != 'x86_64'" },
{ name = "deep-ep", version = "1.2.1+29d31c0", source = { url = "https://github.com/PrimeIntellect-ai/prime-rl/releases/download/v0.5.0/deep_ep-1.2.1+29d31c0-cp312-cp312-linux_x86_64.whl" }, marker = "platform_machine == 'x86_64'" },
{ name = "deep-gemm", version = "2.5.0+891d57b", source = { url = "https://github.com/PrimeIntellect-ai/prime-rl/releases/download/v0.5.0/deep_gemm-2.5.0+891d57b-cp312-cp312-linux_aarch64.whl" }, marker = "platform_machine != 'x86_64'" },
{ name = "deep-gemm", version = "2.5.0+891d57b", source = { url = "https://github.com/PrimeIntellect-ai/prime-rl/releases/download/v0.5.0/deep_gemm-2.5.0+891d57b-cp312-cp312-linux_x86_64.whl" }, marker = "platform_machine == 'x86_64'" },
{ name = "flash-attn", marker = "platform_machine == 'x86_64'" },
@@ -4904,8 +4978,8 @@ all = [
{ name = "vllm-router", version = "0.1.26", source = { url = "https://github.com/PrimeIntellect-ai/router/releases/download/v0.1.26/vllm_router-0.1.26-cp38-abi3-manylinux_2_28_x86_64.whl" }, marker = "platform_machine == 'x86_64'" },
]
disagg = [
{ name = "deep-ep", version = "1.1.0+1fd57b0", source = { url = "https://github.com/PrimeIntellect-ai/prime-rl/releases/download/v0.5.0/deep_ep-1.1.0+1fd57b0-cp312-cp312-linux_aarch64.whl" }, marker = "platform_machine == 'aarch64' and sys_platform == 'linux'" },
{ name = "deep-ep", version = "1.2.1+29d31c0", source = { url = "https://github.com/PrimeIntellect-ai/prime-rl/releases/download/v0.5.0/deep_ep-1.2.1+29d31c0-cp312-cp312-linux_x86_64.whl" }, marker = "platform_machine == 'x86_64' and sys_platform == 'linux'" },
{ name = "deep-ep", version = "1.1.0+1fd57b0", source = { url = "https://github.com/PrimeIntellect-ai/prime-rl/releases/download/v0.5.0/deep_ep-1.1.0+1fd57b0-cp312-cp312-linux_aarch64.whl" }, marker = "platform_machine != 'x86_64'" },
{ name = "deep-ep", version = "1.2.1+29d31c0", source = { url = "https://github.com/PrimeIntellect-ai/prime-rl/releases/download/v0.5.0/deep_ep-1.2.1+29d31c0-cp312-cp312-linux_x86_64.whl" }, marker = "platform_machine == 'x86_64'" },
{ name = "deep-gemm", version = "2.5.0+891d57b", source = { url = "https://github.com/PrimeIntellect-ai/prime-rl/releases/download/v0.5.0/deep_gemm-2.5.0+891d57b-cp312-cp312-linux_aarch64.whl" }, marker = "platform_machine != 'x86_64'" },
{ name = "deep-gemm", version = "2.5.0+891d57b", source = { url = "https://github.com/PrimeIntellect-ai/prime-rl/releases/download/v0.5.0/deep_gemm-2.5.0+891d57b-cp312-cp312-linux_x86_64.whl" }, marker = "platform_machine == 'x86_64'" },
{ name = "nixl" },
@@ -5499,6 +5573,18 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/0c/34/c110ecc14814be490f258549192579ec02a9f3792587e933b254bcd24aa7/pyqwest-0.6.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:8de70fc18b524e09883b161f79fe21a647302a0c9950ecefeb34a1c1f27269a9", size = 5764873, upload-time = "2026-05-19T03:20:17.61Z" },
]
[[package]]
name = "pystemmer"
version = "3.1.0"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/78/95/bb893462b08db211b248f6b1aaa0dc07d068dc86f180178bc9072fef86bb/pystemmer-3.1.0.tar.gz", hash = "sha256:083cc3ed90f4c3b0668f8e31c2925cbb4db3bf0fd6d710e0ad0914f33685f7df", size = 302551, upload-time = "2026-05-22T11:23:44.581Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/06/55/78699a2621a472be98bae7fb36bdda610b7d1c8bcd8ff448301230260cf9/pystemmer-3.1.0-cp312-cp312-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl", hash = "sha256:550bd609aa8dc324033eb1c8d34bfd68649183bbdab871ff534332dcafdc5e5a", size = 752410, upload-time = "2026-05-22T11:14:12.075Z" },
{ url = "https://files.pythonhosted.org/packages/67/63/e3937ac1df5243e94bde11fc1e57584480de419587f46a4badf5088e7ca6/pystemmer-3.1.0-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:7c6db50dd5e92a2a0acf2b2cec55fddcff3928bf490e26d0c45bc0483272a46c", size = 761062, upload-time = "2026-05-22T11:14:13.78Z" },
{ url = "https://files.pythonhosted.org/packages/e7/63/1f7ef438e19029025fc73fe95480d0dbb2ff323f1aec9c087ad9eb952afb/pystemmer-3.1.0-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:b86b0b14634788060cab98ad0cae023620aa7b29f9155e8b474632fc80793405", size = 756304, upload-time = "2026-05-22T11:14:15.419Z" },
{ url = "https://files.pythonhosted.org/packages/ad/5e/816d59b780aa552c87a7e25148005f41be18193482b122d67c6235741b31/pystemmer-3.1.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:6a1289aa31f5f613a31916e7d4e6eaf6b0e6e70a3d494bf08b1d999a0aaf458e", size = 754520, upload-time = "2026-05-22T11:14:16.754Z" },
]
[[package]]
name = "pytest"
version = "9.0.3"
@@ -6138,6 +6224,17 @@ requires-dist = [
{ name = "verifiers", specifier = ">=0.1.4" },
]
[[package]]
name = "senior-swe-bench-v1"
version = "0.1.0"
source = { editable = "deps/research-environments/environments/swe/senior_swe_bench_v1" }
dependencies = [
{ name = "verifiers", extra = ["harbor"] },
]
[package.metadata]
requires-dist = [{ name = "verifiers", extras = ["harbor"], specifier = ">=0.2.1.dev40" }]
[[package]]
name = "sentence-repeater"
version = "0.1.1"