Compare commits

...
Author SHA1 Message Date
2bc136cf85 refactor: share trace_to_sample with verifiers in the prime monitor (#2974)
Docker Push / Push CUDA image to Docker (push) Canceled after 0s
* refactor: share trace_to_sample with verifiers in the prime monitor

Replace the monitor's hand-rolled v1-trace -> sample conversion in
`_rollouts_to_parquet_bytes` with `verifiers.v1.samples.trace_to_sample`, the same
canonical converter verifiers' eval `uv run eval --push` uses. Both producers now emit
one identically-shaped sample record; the RFT-only parquet columns (run/step/advantage/
problem_id/env_name) are layered on here. Behavior-preserving: the parquet schema and all
column values are unchanged (verified against the existing monitor unit tests).

Bumps the deps/verifiers submodule to the verifiers PR that adds `trace_to_sample`.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* chore: bump deps/verifiers (drop trace_to_sample unit test)

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

* chore: bump deps/verifiers (run-metrics aggregation + main merge)

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

* chore: bump deps/verifiers (inline push run-metrics)

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

* chore: bump deps/verifiers (drop URL from push log)

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

* chore: bump deps/verifiers (platform sample/metric shape fixes)

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

* chore: bump deps/verifiers (compute_metrics docstring)

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

* chore: bump deps/verifiers (per-rollout reward columns)

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

* chore: bump deps/verifiers (crash-safe --push upload)

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

* chore: bump deps/verifiers (drop trajectory reward + reward-name suffixing)

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

* chore: bump deps/verifiers (num_examples in push metadata)

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

* chore: bump deps/verifiers (trace_to_sample folded into push.py)

samples.py was dropped on the verifiers branch - trace_to_sample now
lives in verifiers.v1.push

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

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-08 17:10:42 -07:00
2 changed files with 24 additions and 30 deletions
+1 -1
+23 -29
View File
@@ -16,6 +16,7 @@ import pyarrow as pa
import pyarrow.parquet as pq
from prime_cli.core.config import Config as PrimeConfig
from transformers.tokenization_utils import PreTrainedTokenizer
from verifiers.v1.push import trace_to_sample
from prime_rl.configs.orchestrator import OrchestratorConfig
from prime_rl.configs.shared import PrimeMonitorConfig
@@ -325,36 +326,29 @@ class PrimeMonitor(Monitor):
)
def _rollouts_to_parquet_bytes(self, rollouts: list[Rollout], step: int) -> bytes | None:
"""Convert rollouts to Parquet bytes for upload. One row per rollout, built from the
message graph: the conversation is the unit (no prompt/completion split — meaningless in
a multi-turn branch), so `completion` carries the main (last) branch's full message list
and `trajectory` carries one message list per branch (`trace.branches`)."""
"""Convert rollouts to Parquet bytes for upload. One row per rollout. The conversation
is the unit (no prompt/completion split — meaningless mid-branch): `completion` is the
last branch's messages and `trajectory` is one message list per branch. Shares
`verifiers.v1.push.trace_to_sample` with verifiers' eval `--push`, so a training-run
sample and an eval sample land on the platform identically; the RFT-only columns
(run/step/advantage/problem_id/env_name) are layered on here."""
now = datetime.now(timezone.utc)
rows = []
for sample_id, rollout in enumerate(rollouts):
branches = rollout.branches
if not branches:
sample = trace_to_sample(rollout, rollout_number=sample_id + 1)
trajectory = sample["trajectory"]
if not trajectory: # no branches (e.g. a rollout that errored before any message)
continue
main_messages = [m.model_dump(mode="json") for m in branches[-1].messages]
advantage = rollout.scalar_advantage()
trajectory = [{**branch, "advantage": advantage} for branch in trajectory]
task_idx = rollout.task.idx
example_id = sample["example_id"]
try:
problem_id = int(task_idx) if task_idx is not None else sample_id
problem_id = int(example_id) if example_id is not None else sample_id
except (TypeError, ValueError):
problem_id = sample_id
trajectory_data = [
{
"messages": [m.model_dump(mode="json") for m in branch.messages],
"reward": rollout.reward,
"advantage": rollout.scalar_advantage(),
"num_input_tokens": branch.num_input_tokens,
"num_output_tokens": branch.num_output_tokens,
}
for branch in branches
]
rows.append(
{
"run_id": self.run_id,
@@ -363,18 +357,18 @@ class PrimeMonitor(Monitor):
"problem_id": problem_id,
"sample_id": sample_id,
"prompt": "",
"completion": json.dumps(main_messages),
"trajectory": json.dumps(trajectory_data),
"completion": json.dumps(sample["completion"]),
"trajectory": json.dumps(trajectory),
"answer": "",
"env_name": rollout.env_name,
"task": rollout.task.model_dump_json(),
"task": json.dumps(sample["task"]),
"info": json.dumps(rollout.info),
"reward": rollout.reward,
"advantage": rollout.scalar_advantage(),
"metrics": json.dumps(rollout.metrics),
"timing": rollout.timing.model_dump_json(),
"num_input_tokens": branches[-1].num_input_tokens,
"num_output_tokens": branches[-1].num_output_tokens,
"reward": sample["reward"],
"advantage": advantage,
"metrics": json.dumps(sample["metrics"]),
"timing": json.dumps(sample["timing"]),
"num_input_tokens": trajectory[-1]["num_input_tokens"],
"num_output_tokens": trajectory[-1]["num_output_tokens"],
"created_at": now,
}
)