Files
trinity-rl/envs/nemotron_reasoning/nemotron_reasoning_v1/judge.py
T
carstenandClaude Opus 5.5 609e832572 Move to current prime-rl, verifiers and renderers; DeepSeek V4.1 support
Bump prime-rl to trinity-dsv41: upstream main, PR #4057 (DeepSeek V4.1
Flash) with the engram port onto the shared n-gram module, and renderers
tracking its trinity-dsv41 branch (v0.2.0 + the Hermes parser).

Port the envs to the current verifiers v1 API, rl.toml to the new config
schema (IPO loss kept as the new default), and bootstrap/launch/prepare
scripts to the new layout.

Decensor now runs DecensorEnv: the simulated user writes reviewed
follow-ups up to each row's target_turns and every assistant turn is
judged. Earlier runs trained on the first turn only.
tests/test_multiturn_env.py drives the full loop against a mock endpoint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 14:39:44 +00:00

51 lines
1.8 KiB
Python

"""The answer-equivalence judge for the science subtask.
Ported from v0's `judge_equivalence` / `EQUIVALENCE_PROMPT`. Unlike the anti-hacking guard
judges (which fail *open*), this is a correctness grader and faithfully stays fail-*closed*:
a missing or self-contradictory verdict parses to `None`, and the task treats that as "not
equivalent" (0.0) rather than crediting an unverified answer. `EquivalenceJudge.parse`
returns `None` on no verdict; the task reward maps `None` to 0.0.
"""
from __future__ import annotations
import verifiers.v1 as vf
from nemotron_guard_v1.judges import SDK_TIMEOUT, SDKRetryJudge
from verifiers.v1.configs.client import ClientTimeoutConfig
from nemotron_reasoning_v1.answers import parse_equivalence_score
EQUIVALENCE_PROMPT = """You are grading final-answer equivalence.
Task:
{question}
Reference answer:
{expected}
Candidate answer:
{candidate}
Score 1 if the candidate final answer is mathematically, scientifically, or factually equivalent to the reference answer. Score 0 otherwise. Ignore formatting differences, but do not give credit for unsupported guesses or answers that only partially overlap.
Output exactly:
<score>0</score> or <score>1</score>
"""
class EquivalenceJudgeConfig(vf.JudgeConfig):
"""Same local vLLM endpoint the v0 reasoning env graded science answers against."""
model: str = "google/gemma-4-26B-A4B-it"
base_url: str = "http://localhost:3001/v1"
api_key_var: str = "VLLM_API_KEY"
sampling: vf.SamplingConfig = vf.SamplingConfig(temperature=0.0, max_tokens=2048)
timeout: ClientTimeoutConfig = SDK_TIMEOUT
class EquivalenceJudge(SDKRetryJudge, vf.Judge[float, EquivalenceJudgeConfig]):
prompt = EQUIVALENCE_PROMPT
def parse(self, response: vf.JudgeResponse[float]) -> float | None:
return parse_equivalence_score(response.text)