verifiers 0.4.1.dev136__py3-none-any.whl → 0.4.1.dev138__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4,7 +4,6 @@ import contextlib
4
4
  import time
5
5
  from collections import deque
6
6
  from pathlib import Path
7
- from typing import TYPE_CHECKING
8
7
 
9
8
  from pydantic import BaseModel
10
9
  from rich import get_console
@@ -30,9 +29,6 @@ from verifiers.v1.utils.format import (
30
29
  )
31
30
  from verifiers.v1.utils.interrupt import cleaning_up
32
31
 
33
- if TYPE_CHECKING:
34
- from verifiers.v1.utils.platform import PushState
35
-
36
32
  # For sizing pages to the terminal: detects the real terminal height/width each access (the live
37
33
  # view writes to the same terminal). Reused so we don't rebuild it every refresh tick.
38
34
  _CONSOLE = get_console()
@@ -153,7 +149,7 @@ def _aligned(rows: list[list[str]]) -> list[str]:
153
149
  def _interrupt_footer() -> Group | None:
154
150
  """The graceful-shutdown notice under the rollouts once Ctrl-C has begun teardown — the
155
151
  on-screen echo of the warning (console logging is silenced in rich mode); a further Ctrl-C
156
- is ignored while it shows. Sits beside the `--push` line, mirroring its placement."""
152
+ is ignored while it shows."""
157
153
  if not cleaning_up():
158
154
  return None
159
155
  return Group(
@@ -287,29 +283,6 @@ def _prime_rl_footer() -> Group:
287
283
  return Group(Text(""), Text(PRIME_RL_HINT, style="dim", overflow="fold"))
288
284
 
289
285
 
290
- def _push_footer(push: "PushState | None") -> Group | None:
291
- """The `--push` line under the rollouts: dim with the run's URL while it streams,
292
- white once pushed, red when it failed. `None` when `--push` is off or the run stayed
293
- local."""
294
- if push is None or not push.started:
295
- return None
296
- if push.error and push.url:
297
- # The run exists and holds what streamed up; only closing it out failed.
298
- line = Text(f"Traces pushed ({push.url})", style="white", overflow="fold")
299
- line.append(f" not closed out: {push.error}", style="red")
300
- elif push.error:
301
- line = Text(f"Trace push failed ({push.error})", style="red", overflow="fold")
302
- elif (incomplete := push.incomplete) and push.url:
303
- label = "Traces pushed" if push.finished else "Pushing traces"
304
- line = Text(f"{label} ({push.url})", style="white", overflow="fold")
305
- line.append(f" incomplete: {incomplete}", style="red")
306
- elif not push.finished:
307
- line = Text(f"Pushing traces ({push.url})", style="dim", overflow="fold")
308
- else:
309
- line = Text(f"Traces pushed ({push.url})", style="white", overflow="fold")
310
- return Group(Rule(style="dim"), line)
311
-
312
-
313
286
  class TraceStats:
314
287
  """Resource totals for a dashboard frame, retained once the episode is final."""
315
288
 
@@ -835,7 +808,6 @@ def _render(
835
808
  header: Group | Table,
836
809
  runtime_type: str,
837
810
  completed: dict[str, TraceStats],
838
- push: "PushState | None" = None,
839
811
  tail: LogTail | None = None,
840
812
  ) -> Group:
841
813
  now = time.time()
@@ -848,14 +820,10 @@ def _render(
848
820
  for trace in slot.traces
849
821
  if trace.id not in completed
850
822
  )
851
- # The --push status line (and, on Ctrl-C, the cleanup notice) appear under the rollouts. Measure
823
+ # The Ctrl-C cleanup notice and the prime-rl hint appear under the rollouts. Measure
852
824
  # the fixed top (header + progress + rule) and the footer so the rollout rows fill what's left;
853
825
  # page through them (timer / arrows) when they'd overflow (else rich truncates).
854
- footers = [
855
- f
856
- for f in (_push_footer(push), _interrupt_footer(), _prime_rl_footer())
857
- if f is not None
858
- ]
826
+ footers = [f for f in (_interrupt_footer(), _prime_rl_footer()) if f is not None]
859
827
  footer = Group(*footers)
860
828
  progress = Progress(slots, start, completed)
861
829
  top = Group(header, progress, Rule(style="dim"))
@@ -888,7 +856,6 @@ async def dashboard(
888
856
  slots: list[RunSlot],
889
857
  config: EvalConfig,
890
858
  start: float,
891
- push: "PushState | None" = None,
892
859
  ):
893
860
  pager = Pager()
894
861
  completed: dict[str, TraceStats] = {}
@@ -909,9 +876,7 @@ async def dashboard(
909
876
  else None
910
877
  )
911
878
  async with live_view(
912
- lambda: _render(
913
- slots, start, pager, header, runtime_type, completed, push, tail
914
- ),
879
+ lambda: _render(slots, start, pager, header, runtime_type, completed, tail),
915
880
  on_key=None if tail is not None else pager.on_key,
916
881
  ):
917
882
  yield
@@ -22,15 +22,7 @@ from verifiers.v1.clients import ModelContext
22
22
  from verifiers.v1.configs.cli.eval import EvalConfig
23
23
  from verifiers.v1.env import Env, RunSlot
24
24
  from verifiers.v1.episode import Episode, EvalRunInfo
25
- from verifiers.v1.utils.aio import run_shielded
26
25
  from verifiers.v1.utils.eval import plan_rollouts
27
- from verifiers.v1.utils.platform import (
28
- PushState,
29
- abort_run,
30
- finish_run,
31
- log_episodes,
32
- open_run,
33
- )
34
26
  from verifiers.v1.utils.trace_store import append_episode
35
27
 
36
28
  logger = logging.getLogger(__name__)
@@ -40,7 +32,7 @@ T = TypeVar("T")
40
32
 
41
33
  async def gather_rollouts(rollouts: Iterable[Awaitable[T]]) -> list[T]:
42
34
  """`asyncio.gather`, but one rollout failing cancels the rest and waits for them
43
- to unwind, so nothing keeps uploading into a run the caller is already closing.
35
+ to unwind, so no rollout outlives the eval it belongs to.
44
36
  Not a `TaskGroup`: that wraps errors in an `ExceptionGroup`, and `main` would no
45
37
  longer see a `KeyboardInterrupt` as Ctrl-C."""
46
38
  tasks = [asyncio.ensure_future(rollout) for rollout in rollouts]
@@ -124,43 +116,23 @@ async def run_eval(config: EvalConfig) -> list[Episode]:
124
116
  asyncio.Semaphore(config.max_concurrent) if config.max_concurrent else None
125
117
  )
126
118
  write_lock = asyncio.Lock()
127
- push_state = PushState()
128
119
 
129
- # Opened before the first rollout so every episode streams as it lands.
130
- run = open_run(config, push_state, num_examples=len(tasks))
131
120
  # The run identity: every process this run spawns inherits it.
132
121
  os.environ.setdefault("VF_RUN_ID", config.run.id)
133
- # Resumed rollouts are part of this run too.
134
- log_episodes(run, finished)
135
122
 
136
123
  async def on_complete(episode: Episode) -> None:
137
124
  episode.record_run(EvalRunInfo(id=config.run.id, name=config.run.name))
138
125
  await append_episode(out, episode, write_lock)
139
- await asyncio.to_thread(log_episodes, run, [episode])
140
126
 
141
- # The run is closed out whatever breaks, env setup and teardown included.
142
- try:
143
- async with _in_process(env, config, semaphore, on_complete) as run_slot:
144
- # the env's own slots: it fills their live traces as the rollouts run
145
- planned = [slot for task, _, n in plan if n for slot in env.slots(task, n)]
146
- slots = [RunSlot.finished(episode) for episode in finished] + planned
147
- display = (
148
- dashboard(slots, config, start, push=push_state)
149
- if config.rich is not None
150
- else contextlib.nullcontext()
151
- )
152
- async with display:
153
- results = await gather_rollouts(run_slot(slot) for slot in planned)
154
- episodes = finished + list(results)
155
- # Drain and close out off the event loop so the view keeps refreshing.
156
- # Shielded: a Ctrl-C here must not cancel the close-out before the
157
- # worker picks it up (a cancelled executor item never runs), so it
158
- # runs to completion first and the interrupt is re-raised after —
159
- # by which point the run is finished and `abort_run` has nothing to do.
160
- await run_shielded(
161
- asyncio.to_thread(finish_run, run, episodes, push_state)
162
- )
163
- except BaseException as e:
164
- await asyncio.to_thread(abort_run, run, e, push_state)
165
- raise
166
- return episodes
127
+ async with _in_process(env, config, semaphore, on_complete) as run_slot:
128
+ # the env's own slots: it fills their live traces as the rollouts run
129
+ planned = [slot for task, _, n in plan if n for slot in env.slots(task, n)]
130
+ slots = [RunSlot.finished(episode) for episode in finished] + planned
131
+ display = (
132
+ dashboard(slots, config, start)
133
+ if config.rich is not None
134
+ else contextlib.nullcontext()
135
+ )
136
+ async with display:
137
+ results = await gather_rollouts(run_slot(slot) for slot in planned)
138
+ return finished + list(results)
@@ -47,29 +47,13 @@ class RunConfig(BaseConfig):
47
47
  """Run directory name — the run writes to `output_dir / dir`. Defaults to `run.name`;
48
48
  set it only when the directory should differ from the display name."""
49
49
 
50
- attach: str | None = None
51
- """Stream into a run the launcher already created on the platform instead of opening a
52
- new one — its evaluation id. Hosted evaluations pass the sandbox's `$EVALUATION_ID`
53
- here; the platform owns that run's record and status, and a run that cannot be
54
- attached to is an error rather than a local fallback. Requires `push`."""
55
-
56
- _id: str | None = PrivateAttr(default=None)
50
+ _id: str = PrivateAttr(default_factory=lambda: uuid4().hex)
57
51
 
58
52
  @property
59
53
  def id(self) -> str:
60
- """The run's one id, assigned by `open_run` from the prime-runs handle: the
61
- platform's evaluation id online, the SDK's local id otherwise. The run mints
62
- none of its own, so the run dir, every trace and the dashboard agree."""
63
- if self._id is None:
64
- raise RuntimeError("the run has no id until `open_run` has opened it")
54
+ """Stamped on every trace and exported as `$VF_RUN_ID`."""
65
55
  return self._id
66
56
 
67
- def assign_id(self, run_id: str) -> None:
68
- """Called once by `open_run`, before the first rollout."""
69
- if self._id is not None and self._id != run_id:
70
- raise RuntimeError(f"the run already has id {self._id!r}")
71
- self._id = run_id
72
-
73
57
 
74
58
  class EvalConfig(BaseConfig):
75
59
  env: SerializeAsAny[EnvConfig] = SingleAgentEnvConfig()
@@ -112,10 +96,6 @@ class EvalConfig(BaseConfig):
112
96
  rich: RichConfig | None = Field(default_factory=RichConfig)
113
97
  """The live dashboard (on by default; `--no-rich` streams logs to the console
114
98
  instead); `--rich.show-logs` swaps the rollout rows for the run's logs."""
115
- push: bool = True
116
- """Upload the finished run to the Prime Intellect platform (the private Evaluations
117
- tab) at the end of the eval. On by default; disable with `--no-push`. Needs
118
- `$PRIME_API_KEY` or `prime login`."""
119
99
  output_dir: Path = Field(
120
100
  Path("outputs"), validation_alias=AliasChoices("output_dir", "o")
121
101
  )
@@ -139,11 +119,3 @@ class EvalConfig(BaseConfig):
139
119
  if self.run.dir is None:
140
120
  self.run.dir = self.run.name
141
121
  return self
142
-
143
- @model_validator(mode="after")
144
- def attach_needs_push(self):
145
- if self.run.attach and not self.push:
146
- raise ValueError(
147
- "run.attach names a run on the platform, so it needs push (drop --no-push)"
148
- )
149
- return self
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: verifiers
3
- Version: 0.4.1.dev136
3
+ Version: 0.4.1.dev138
4
4
  Summary: Verifiers: Environments for LLM Reinforcement Learning
5
5
  Project-URL: Homepage, https://github.com/primeintellect-ai/verifiers
6
6
  Project-URL: Documentation, https://github.com/primeintellect-ai/verifiers
@@ -36,8 +36,7 @@ Requires-Dist: numpy>=2.1.0
36
36
  Requires-Dist: openai<3.0.0,>=2.54.0
37
37
  Requires-Dist: orjson>=3.10.0
38
38
  Requires-Dist: prime-pydantic-config[toml]>=0.4.3
39
- Requires-Dist: prime-runs>=0.1.5
40
- Requires-Dist: prime-sandboxes>=0.5.3
39
+ Requires-Dist: prime-sandboxes>=0.5.4
41
40
  Requires-Dist: prime-tunnel>=0.1.14
42
41
  Requires-Dist: pydantic>=2.12.3
43
42
  Requires-Dist: pyzmq>=27.1.0
@@ -28,14 +28,14 @@ verifiers/v1/cli/resume.py,sha256=hqV5AxxqeIInJeEZQerQznuijhMNijFEFcHZIltfLdE,47
28
28
  verifiers/v1/cli/validate.py,sha256=kKZXoi7xmpL6NGz8QRl5_BGEi2nzw5PXdig1hKtVqw8,21771
29
29
  verifiers/v1/cli/dashboard/__init__.py,sha256=v-baMxQuWxOCsbU7-p_jj2Q9BUnTN-TWi1q2hK6rU2s,198
30
30
  verifiers/v1/cli/dashboard/base.py,sha256=kUP93zJSIVLptSbnWX6MOy8kGg63fpeAzPqakCpPyDc,3547
31
- verifiers/v1/cli/dashboard/eval.py,sha256=O7_Szm2YcsXRoGkCFgHMGH59IB0hkW_zdRVKe5SqWyg,38927
31
+ verifiers/v1/cli/dashboard/eval.py,sha256=ic75fpIOn1myY8pMzDF7zAF8pnG_9AaTMhSXFlxXNz0,37405
32
32
  verifiers/v1/cli/dashboard/replay.py,sha256=N9c1J8QXfr2Dw4Ww-bBUthxskhQrNwmqe6QLHPtiBqA,2798
33
33
  verifiers/v1/cli/dashboard/validate.py,sha256=xrpK3Y90JsoDCQYLLvvsnJ4CPRMvSSJIghfHK62E6FQ,3687
34
34
  verifiers/v1/cli/eval/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
35
35
  verifiers/v1/cli/eval/hint.py,sha256=NXP2_JYrQHguqr68LxOJG3lYAsue_VNoepyTVPn-N4E,256
36
36
  verifiers/v1/cli/eval/main.py,sha256=46aHpha6yhFzbqUrRogC5wC2XAwdZcpp-4siqLpUExY,5984
37
37
  verifiers/v1/cli/eval/resume.py,sha256=rnqkNIuuZ5zx8O-eEfALOJ1GEOUmSRnKHQrsU3dduU8,2187
38
- verifiers/v1/cli/eval/runner.py,sha256=utBDBgU7H_utJBDqQ4bOuG3aLFHTaCSb3OW602L5X8I,6468
38
+ verifiers/v1/cli/eval/runner.py,sha256=kBOb9zOXAgRbEnKZNB0YC5Mq3hX6yfISArZC8yo2QO4,5116
39
39
  verifiers/v1/clients/__init__.py,sha256=Ysig0tE_0E4Jsfgfes1XHN-fK1s_RCXdqZD6E7lK4PU,507
40
40
  verifiers/v1/clients/base.py,sha256=C0G5lRm3nxt1xmPoA2cweBgCnN2KcLepmCYq1vdDrnU,1691
41
41
  verifiers/v1/clients/client.py,sha256=HT3aQiOyYYjvz_cKEXchtUSD07-4VehebWUJL9AyON8,3166
@@ -60,7 +60,7 @@ verifiers/v1/configs/taskset.py,sha256=rQow8AJL34n-ZVQ_4GPjPIW5fzBL5QU_RTjJO9tlm
60
60
  verifiers/v1/configs/cli/__init__.py,sha256=YMDUPdbRlDJ77dhj3QqzmyRhqNgUvuQdpj_bdBqzZPM,78
61
61
  verifiers/v1/configs/cli/debug.py,sha256=1vddnShdwYzRJp0Ubl9sp7sgnR3m2JKHkAOk741UnWU,2748
62
62
  verifiers/v1/configs/cli/env.py,sha256=qg2LNOasAU0yg3b0xqXpx3cIj4nHbHSlK3Ldc3NhiT4,2667
63
- verifiers/v1/configs/cli/eval.py,sha256=ACZ320tTv-CnoYIZQwOdsuaZXL2RM_7ZMWghT0rQx4g,6871
63
+ verifiers/v1/configs/cli/eval.py,sha256=GkfKLOS7zotKfxCu7NlTr5qFfk7deScdz0B5jELtLh8,5449
64
64
  verifiers/v1/configs/cli/replay.py,sha256=vUCNs-9j1CXcAZhGozN1EaztcXK_dYVK3iN_fRmbSXw,2929
65
65
  verifiers/v1/configs/cli/validate.py,sha256=X0xDn4R8aPHq94qcCHTZxupL2gJOVNfnjp_gj5C3DiI,4178
66
66
  verifiers/v1/dialects/__init__.py,sha256=MNOYM2NdTlSxGK4VtoEjMtD5zya2MpjPDX5jMvZUWEo,736
@@ -202,15 +202,14 @@ verifiers/v1/utils/logging.py,sha256=-zgaM-HZsgxumZ4wYNlRMZepp6JanCSjeL2wSVulwJM
202
202
  verifiers/v1/utils/memory.py,sha256=ZkIvGk6uITAH5sKon65LifKPbvZr8mJ__PVc23FZpOQ,1835
203
203
  verifiers/v1/utils/network.py,sha256=SI6_PXHIAPows6VBpK75N6dMbPw6lWQQ3OjBQkSDGN4,1463
204
204
  verifiers/v1/utils/paths.py,sha256=it_4JWf_8bPZe4TRcyvL7_KJ4fsbEsxhhIY_xA8Ikus,308
205
- verifiers/v1/utils/platform.py,sha256=YwTHVA1Onn74lG6S3sdHus9OlP-rAbwkk9Po7h-BjpE,7159
206
205
  verifiers/v1/utils/prime.py,sha256=UTYRjp9cbjNb6CVmBHda-1wWZAIIfxNOmTyNuT7_wL4,970
207
206
  verifiers/v1/utils/retries.py,sha256=xTDdORf9BmFq7HhxEjNkhuduOSVekCl4l2ei9ZlQIIQ,6052
208
207
  verifiers/v1/utils/scope.py,sha256=bzUEiWDOVdbj7dXOwGOlzsQ_-Xu0j9NR5TalQB-8TS8,838
209
208
  verifiers/v1/utils/score.py,sha256=493yJVMw8teCu9JxapxMFPFzI0hNUqdo0Y2nGW4kckk,6200
210
209
  verifiers/v1/utils/trace_store.py,sha256=Qo9qvsJAl8PoRUavjQAfUB2VNxmUtYQtU2ejLKPzY9c,3382
211
210
  verifiers/v1/utils/version.py,sha256=-obEo_-l9-D8FLef4hYxncOe-uJpxrM1g2Hig_37Sgs,1607
212
- verifiers-0.4.1.dev136.dist-info/METADATA,sha256=TeU-Dx8RKSHnC5XQMaXr2CZR_GHJP_L6WHjsPkgsKao,5265
213
- verifiers-0.4.1.dev136.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
214
- verifiers-0.4.1.dev136.dist-info/entry_points.txt,sha256=O1bIO0gyJWuLfWtTGF0h-JkNz6FkyXP7Z9iMFYnjeMI,222
215
- verifiers-0.4.1.dev136.dist-info/licenses/LICENSE,sha256=v0RrUsdV3IDoZhrRce297IXS3xMHNJ-_LdLpFAUWb9k,1072
216
- verifiers-0.4.1.dev136.dist-info/RECORD,,
211
+ verifiers-0.4.1.dev138.dist-info/METADATA,sha256=9zl7UKv7um2ViGZzaPhEF1A5KOFFpV_xgnFGKhagWAU,5232
212
+ verifiers-0.4.1.dev138.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
213
+ verifiers-0.4.1.dev138.dist-info/entry_points.txt,sha256=O1bIO0gyJWuLfWtTGF0h-JkNz6FkyXP7Z9iMFYnjeMI,222
214
+ verifiers-0.4.1.dev138.dist-info/licenses/LICENSE,sha256=v0RrUsdV3IDoZhrRce297IXS3xMHNJ-_LdLpFAUWb9k,1072
215
+ verifiers-0.4.1.dev138.dist-info/RECORD,,
@@ -1,179 +0,0 @@
1
- """The eval's run on the Prime Intellect platform (`--no-push` to keep it local)."""
2
-
3
- import asyncio
4
- import logging
5
- import os
6
- from collections.abc import Mapping
7
- from dataclasses import dataclass
8
- from typing import Any
9
-
10
- import prime_runs as pr
11
- from prime_runs.projection import (
12
- build_samples, # noqa: F401 - prime-rl imports it from here
13
- )
14
-
15
- from verifiers.v1.configs.cli.eval import EvalConfig
16
- from verifiers.v1.episode import Episode
17
-
18
- logger = logging.getLogger(__name__)
19
-
20
-
21
- @dataclass
22
- class PushState:
23
- """The dashboard's view of the run: reads through to it, owns no I/O."""
24
-
25
- run: pr.Run | None = None
26
- error: str | None = None
27
-
28
- @property
29
- def incomplete(self) -> str | None:
30
- """Current upload errors and record losses, including while the run is active."""
31
- return _losses(self.run) if self.run is not None else None
32
-
33
- @property
34
- def url(self) -> str | None:
35
- return self.run.url if self.run is not None else None
36
-
37
- @property
38
- def finished(self) -> bool:
39
- return self.run is not None and self.run.finished
40
-
41
- @property
42
- def started(self) -> bool:
43
- """A live run, or a reason there isn't one."""
44
- return self.error is not None or self.url is not None
45
-
46
-
47
- def open_run(config: EvalConfig, state: PushState, *, num_examples: int) -> pr.Run:
48
- """Open the run this eval streams into, before the first rollout, and give the
49
- config the run's id. A run that cannot be opened is logged and replaced by a
50
- disabled one; the eval goes on. With `run.attach` the run already exists on the
51
- platform (a hosted evaluation's launcher created it and is waiting on it), so
52
- there is no local fallback: failing to attach fails the eval."""
53
- attach = config.run.attach
54
- identity: dict[str, Any] = {
55
- "name": config.run.name,
56
- # Resolved by name via the hub's get-or-create; no taskset, nothing to attach to.
57
- "environments": [config.env.taskset.id] if config.env.taskset.id else [],
58
- "model": config.model,
59
- "framework": "verifiers",
60
- # The v0 keys the dashboard's lists read. The config itself is a follow-up:
61
- # a dump or the launched file can carry credentials and needs masking first.
62
- "config": {
63
- "model": config.model,
64
- "num_examples": num_examples,
65
- "rollouts_per_example": config.num_rollouts,
66
- },
67
- }
68
- if config.push and os.getenv(pr.MODE_ENV, "").strip().lower() == "disabled":
69
- if attach:
70
- raise RuntimeError(
71
- f"run.attach={attach!r} names a run on the platform, but "
72
- f"{pr.MODE_ENV}=disabled would keep this eval local"
73
- )
74
- # The SDK's own kill switch; the explicit `mode="online"` below would override it.
75
- logger.info("--push: %s=disabled; running without a platform run", pr.MODE_ENV)
76
- elif config.push:
77
- try:
78
- state.run = pr.init(mode="online", id=attach, **identity)
79
- except Exception as e:
80
- if attach:
81
- # The launcher's run would sit at running until it times out; a local
82
- # run nobody reads is not a substitute.
83
- raise RuntimeError(
84
- f"--run.attach: could not attach to run {attach!r} ({type(e).__name__}: {e})"
85
- ) from e
86
- logger.warning(
87
- "--push: could not open the run (%s: %s); running without it",
88
- type(e).__name__,
89
- e,
90
- )
91
- state.error = f"{type(e).__name__}: {e}"
92
- if state.run is None:
93
- state.run = pr.init(mode="disabled", **identity)
94
- # The run's one id: the platform's when online, the SDK's local one otherwise.
95
- # The SDK keys every upload to it regardless; this is for the local records.
96
- config.run.assign_id(state.run.id)
97
- return state.run
98
-
99
-
100
- def log_episodes(run: pr.Run, episodes: list[Episode]) -> None:
101
- """Hand finished episodes to the run, best effort: the SDK already keeps upload
102
- failures on its own thread, so this only guards the hand-off itself. A problem
103
- here is the platform's, never the eval's."""
104
- if not episodes:
105
- return
106
- try:
107
- run.log_episodes(episodes)
108
- except Exception as e: # noqa: BLE001 - the rollouts are on disk; report, don't raise
109
- logger.warning(
110
- "--push: could not queue %d episode(s) (%s: %s)",
111
- len(episodes),
112
- type(e).__name__,
113
- e,
114
- )
115
-
116
-
117
- def finish_run(run: pr.Run, episodes: list[Episode], state: PushState) -> None:
118
- """Drain, write the run's aggregates, close it out. Blocking: call it off the loop."""
119
- try:
120
- summary = pr.metrics.from_episodes(episodes)
121
- except Exception as e: # noqa: BLE001 - close the run even without its headline
122
- logger.warning(
123
- "--push: could not aggregate the run's metrics (%s: %s)",
124
- type(e).__name__,
125
- e,
126
- )
127
- summary = None
128
- _close(run, state, summary=summary)
129
-
130
-
131
- def abort_run(run: pr.Run, error: BaseException, state: PushState) -> None:
132
- """Close the run out after the eval broke, so it doesn't sit at running. Not
133
- for a break during `finish_run`: that close-out completes on its own thread
134
- and the SDK lets the first `finish()` decide the status — it sets `run.status`
135
- as it starts, so an in-flight one is visible here before it is `finished`."""
136
- if run.finished or run.status is not pr.RunStatus.RUNNING:
137
- return
138
- if isinstance(error, (KeyboardInterrupt, asyncio.CancelledError)):
139
- status, message = pr.RunStatus.CANCELLED, "interrupted"
140
- else:
141
- status, message = pr.RunStatus.FAILED, f"{type(error).__name__}: {error}"
142
- _close(run, state, status=status, error=message)
143
-
144
-
145
- def _close(
146
- run: pr.Run,
147
- state: PushState,
148
- summary: Mapping[str, Any] | None = None,
149
- status: pr.RunStatus = pr.RunStatus.COMPLETED,
150
- error: str | None = None,
151
- ) -> None:
152
- """`run.finish()`, best effort: the results are on disk, so nothing here may raise."""
153
- try:
154
- run.finish(summary, status=status, error=error)
155
- except Exception as e: # noqa: BLE001 - the run is over; report, don't raise
156
- logger.warning(
157
- "--push: could not close out the run (%s: %s)", type(e).__name__, e
158
- )
159
- if state.error is None:
160
- state.error = f"{type(e).__name__}: {e}"
161
- else:
162
- if incomplete := state.incomplete:
163
- logger.warning("--push: %s, but %s", status.value, incomplete)
164
- if run.url:
165
- # The run's own status: `finish()` is a no-op once another caller closed it.
166
- logger.info("--push: %s -> %s", run.status.value, run.url)
167
-
168
-
169
- def _losses(run: pr.Run) -> str | None:
170
- """What the run could not finish or store, or `None`."""
171
- parts = list(run.errors)
172
- parts.extend(
173
- f"{count} record(s) not stored by the {sink} sink"
174
- for sink, count in sorted(run.failed_records.items())
175
- if count
176
- )
177
- if run.dropped_records:
178
- parts.append(f"{run.dropped_records} record(s) never queued (uploader overrun)")
179
- return "; ".join(parts) or None