Compare commits

...
Author SHA1 Message Date
f2ead102d1 feat(laguna): support per-element attention gating (#3229)
Laguna's config carries a `gating` field that prime-rl's port dropped, so
g_proj was always sized for per-head gating:

    self.g_proj = nn.Linear(config.hidden_size, num_heads, bias=False)

That matches Laguna S (`gating = "per-head"`, g_proj [48, 3072]) and is wrong
for Laguna M (`gating = "per-element"`, g_proj [8192, 4096] = num_heads x
head_dim). Loading M.1 fails with

    ValueError: Size mismatch between saved torch.Size([8192, 4096]) and
    current: torch.Size([64, 4096]) for model.layers.0.self_attn.g_proj.weight

Carry `gating` on LagunaConfig and size g_proj from it, following upstream's
semantics exactly (poolside/Laguna-M.1 modeling_laguna.py):

    True / "per-element"  one gate per (head, head_dim) channel
    "per-head"            one gate per head, broadcast across head_dim
    False                 no gating

Note the default is `True`, not "per-head": a checkpoint that omits the field
gets per-element upstream, so defaulting the other way would silently mis-size
it. bool and str are both accepted for the same reason.

Verified against both checkpoints: g_proj matches [48, 3072] for S-2.1 and
[8192, 4096] for M.1, and the gate math is bit-identical to upstream in both
modes (max abs diff 0.0). End to end, a 4-node trainer probe loads the real
452GB M.1 checkpoint through load_dcp_from_hf with no size mismatch, where it
previously failed at model construction.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-10 21:41:50 -07:00
halleriteandGitHub c698bdeb2a chore: bump research-environments for the toolset register() fix (#3230) 2026-08-10 20:11:43 +02:00
6e33f3f82f chore: bump verifiers for the unbounded model-call timeout (#3227)
Bumps deps/verifiers 29e3a0f7 -> a298bcfe, picking up two commits:

  a298bcfe fix(v1): restore the unbounded model-call timeout (#2304)
  9ca7f5d6 Fix plain HTTP CONNECT for Docker framework routes (#2298)

verifiers#2218 had consolidated client construction into
build_async_openai/DEFAULT_TIMEOUT and, in doing so, replaced the relay
client's explicit `timeout=None` with a 600s read timeout mirroring the OAI
SDK default. That cap reached every model-call path, since DEFAULT_TIMEOUT
feeds clients/eval.py as well as build_async_openai, which judge.py and
clients/train.py use.

600s is fine for chat-shaped evals and wrong for RL: a single agentic turn on
a long SWE trajectory routinely runs past ten minutes, and when it does the
rollout dies as `ProviderError: Request timed out` even though the model was
still producing. Because it truncates the longest trajectories specifically,
the loss is biased rather than uniform. Seen on the laguna-s SWE RL run here.
#2304 restores unbounded read/write/pool and keeps connect at 5.0 so an
unreachable endpoint still fails fast.

No lockfile change: verifiers is an editable path dependency
(`source = { editable = "deps/verifiers" }`), and neither commit touches its
pyproject, so only the submodule pointer moves.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-08 21:41:10 -07:00
c282262e6e fix(slurm): export ORCH_PROCID so the orchestrator actually launches (#3225)
#3189 hoisted ORCH_PROCID out of the srun body into the outer batch script so
ORCH_ADDR could be derived from it. ORCH_ADDR was exported; ORCH_PROCID was
not.

The srun body is a quoted heredoc, so `$ORCH_PROCID` in

    if [ "$SLURM_PROCID" -eq "$ORCH_PROCID" ]; then

is expanded per task, and a plain (unexported) shell variable never reaches
the task environment. The test becomes `[ "4" -eq "" ]`, which errors with
"integer expression expected" and evaluates false on every rank, so the block
that starts the orchestrator and both env servers is skipped entirely.

The failure is silent and expensive. Inference comes up, the trainer reaches
weight-broadcast init, and then the job sits there until the 3600s NCCL
watchdog fires on a 1-element ALLREDUCE, holding the whole allocation. There
is no error in the job log pointing at the orchestrator, and no
orchestrator.log to look at, because the `tee` that would create it is inside
the skipped block. Observed on a 6-node run: 20 minutes in, only
PRIME-RL::Trainer processes on the orchestrator node and no logs/envs/
directory, which the block's own `mkdir -p` would have created.

Export it. Verified by rendering multi_node_rl.sbatch.j2 and running the guard
with SLURM_PROCID=4: the branch is taken now and skipped before.

Audited the other templates for the same pattern — variables assigned in the
outer script but read inside a quoted heredoc. multi_node_sft, single_node_rl
and single_node_sft are clean. Two apparent hits are false positives:
HOSTNAMES is rebuilt inside the body from the exported HOSTNAMES_STR, and
inference.sbatch.j2's DP_PER_NODE is rendered directly into the body by Jinja.

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-08 20:51:20 -07:00
6 changed files with 28 additions and 11 deletions
+1 -1
@@ -130,6 +130,7 @@ echo "MASTER_PORT=${MASTER_PORT}"
# The ZMQ rollout transport binds in the orchestrator process, so both sides must
# address the orchestrator's node.
{% if num_infer_nodes > 0 and orchestrator_on_inference %}ORCH_PROCID=$((NUM_INFER_NODES - 1)){% else %}ORCH_PROCID=$NUM_INFER_NODES{% endif %}
export ORCH_PROCID
export ORCH_ADDR="${HOSTNAMES[$ORCH_PROCID]}"
echo "ORCH_ADDR=${ORCH_ADDR}"
@@ -64,6 +64,7 @@ class LagunaConfig(PretrainedConfig):
eos_token_id: int | list[int] | None = None,
head_dim: int = 128,
attention_bias: bool = False,
gating: bool | str = True,
partial_rotary_factor: float | None = None,
num_attention_heads_per_layer: list[int] | None = None,
mlp_layer_types: list[str] | None = None,
@@ -98,6 +99,7 @@ class LagunaConfig(PretrainedConfig):
self.layer_types = layer_types or ["full_attention"] * num_hidden_layers
self.head_dim = head_dim
self.attention_bias = attention_bias
self.gating = gating
self.partial_rotary_factor = partial_rotary_factor
self.num_attention_heads_per_layer = num_attention_heads_per_layer or [num_attention_heads] * num_hidden_layers
self.mlp_layer_types = mlp_layer_types or ["dense"] + ["sparse"] * (num_hidden_layers - 1)
@@ -106,7 +106,16 @@ class LagunaFlashAttention(FlashAttention):
self.attention_dropout = config.attention_dropout
self.is_local_attention = config.layer_types[layer_idx] == "sliding_attention"
self.sliding_window = config.sliding_window if self.is_local_attention else None
self.g_proj = nn.Linear(config.hidden_size, num_heads, bias=False)
# Attention output gating, mirroring the upstream Laguna implementation:
# True / "per-element" (Laguna M): one gate per (head, head_dim) channel
# "per-head" (Laguna S): one gate per head, broadcast across head_dim
# False: no gating
gating = getattr(config, "gating", True)
self.gating = bool(gating)
self.gate_per_head = gating == "per-head"
if self.gating:
gate_size = num_heads if self.gate_per_head else num_heads * self.head_dim
self.g_proj = nn.Linear(config.hidden_size, gate_size, bias=False)
self.o_proj = nn.Linear(num_heads * self.head_dim, config.hidden_size, bias=config.attention_bias)
def forward(
@@ -127,8 +136,13 @@ class LagunaFlashAttention(FlashAttention):
)
input_shape = hidden_states.shape[:-1]
attn_output = attn_output.view(*input_shape, self.num_heads, self.head_dim)
gate = F.softplus(self.g_proj(hidden_states).float()).to(attn_output.dtype)
attn_output = (attn_output * gate.unsqueeze(-1)).view(*input_shape, -1)
if self.gating:
gate = F.softplus(self.g_proj(hidden_states).float()).to(attn_output.dtype)
# per-head gates broadcast across head_dim; per-element gates are already
# one-per-channel and line up with the [..., num_heads, head_dim] view.
gate = gate.unsqueeze(-1) if self.gate_per_head else gate.view(*attn_output.shape)
attn_output = attn_output * gate
attn_output = attn_output.view(*input_shape, -1)
return self.o_proj(attn_output), None
Generated
+6 -6
View File
@@ -460,7 +460,7 @@ requires-dist = [
{ name = "datasets" },
{ name = "mcp", specifier = "<2" },
{ name = "openai" },
{ name = "verifiers", specifier = ">=0.2.2.dev65" },
{ name = "verifiers", specifier = ">=0.3.0" },
]
[[package]]
@@ -584,7 +584,7 @@ dependencies = [
requires-dist = [
{ name = "bfcl-eval", git = "https://github.com/mikasenghaas/gorilla.git?subdirectory=berkeley-function-call-leaderboard&rev=898763a" },
{ name = "soundfile", specifier = ">=0.13.0" },
{ name = "verifiers", specifier = ">=0.2.2.dev65" },
{ name = "verifiers", specifier = ">=0.3.0" },
]
[[package]]
@@ -694,7 +694,7 @@ requires-dist = [
{ name = "openai" },
{ name = "pystemmer" },
{ name = "tokenizers" },
{ name = "verifiers", specifier = ">=0.2.2.dev65" },
{ name = "verifiers", specifier = ">=0.3.0" },
]
[[package]]
@@ -1523,7 +1523,7 @@ dependencies = [
[package.metadata]
requires-dist = [
{ name = "datasets", specifier = ">=4.0.0,<5" },
{ name = "verifiers", specifier = ">=0.2.2.dev65" },
{ name = "verifiers", specifier = ">=0.3.0" },
]
[[package]]
@@ -1924,7 +1924,7 @@ dependencies = [
[package.metadata]
requires-dist = [
{ name = "pydantic" },
{ name = "verifiers", extras = ["harbor"], specifier = ">=0.2.2.dev65" },
{ name = "verifiers", extras = ["harbor"], specifier = ">=0.3.0" },
]
[[package]]
@@ -3348,7 +3348,7 @@ requires-dist = [
{ name = "datasets", specifier = ">=4.0.0,<5" },
{ name = "httpx" },
{ name = "prime-sandboxes", specifier = ">=0.2.19" },
{ name = "verifiers", specifier = ">=0.2.2.dev65" },
{ name = "verifiers", specifier = ">=0.3.0" },
]
[[package]]