verifiers 0.4.2.dev128__py3-none-any.whl → 0.4.2.dev129__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.
verifiers/v1/cli/run.py CHANGED
@@ -8,6 +8,7 @@ import asyncio
8
8
  import os
9
9
  import sys
10
10
  from pathlib import Path
11
+ from typing import Literal, overload
11
12
 
12
13
  from pydantic_config import cli
13
14
 
@@ -42,9 +43,24 @@ def ensure_fresh(out: Path) -> None:
42
43
  )
43
44
 
44
45
 
45
- async def run_episodes(config: RunnerConfig) -> list[Episode]:
46
+ @overload
47
+ async def run_episodes(
48
+ config: RunnerConfig, *, collect: Literal[True] = True
49
+ ) -> list[Episode]: ...
50
+
51
+
52
+ @overload
53
+ async def run_episodes(
54
+ config: RunnerConfig, *, collect: Literal[False]
55
+ ) -> tuple[int, int, float]: ...
56
+
57
+
58
+ async def run_episodes(
59
+ config: RunnerConfig, *, collect: bool = True
60
+ ) -> list[Episode] | tuple[int, int, float]:
46
61
  """Run `num_rollouts` episodes per selected task and append each to `traces.jsonl`
47
- as it completes."""
62
+ as it completes. With `collect=False`, stream-aggregate `(ok, episodes, mean_reward)`
63
+ and drop each finished episode immediately instead of keeping them all in memory."""
48
64
  env = load_environment(config.env)
49
65
  taskset = env.taskset.select(config.select)
50
66
  if not taskset.bounded:
@@ -61,29 +77,43 @@ async def run_episodes(config: RunnerConfig) -> list[Episode]:
61
77
  asyncio.Semaphore(config.max_concurrent) if config.max_concurrent else None
62
78
  )
63
79
  write_lock = asyncio.Lock()
80
+ ok = episodes = traces = 0
81
+ reward_sum = 0.0
64
82
 
65
83
  async def on_complete(episode: Episode) -> None:
84
+ nonlocal ok, episodes, traces, reward_sum
66
85
  episode.record_run(EvalRunInfo(id=config.run.id, name=config.run.name))
67
86
  await append_episode(out, episode, write_lock)
87
+ episodes += 1
88
+ ok += int(episode.ok)
89
+ traces += len(episode.traces)
90
+ reward_sum += sum(trace.reward for trace in episode.traces)
91
+
92
+ async def run_one(slot) -> Episode | None:
93
+ episode = await env.run_slot(slot, ctx, semaphore, on_complete)
94
+ if collect:
95
+ return episode
96
+ slot.episode = None
97
+ slot.traces.clear()
98
+ return None
68
99
 
69
100
  async with env.serving():
70
- rollouts: list[asyncio.Future[Episode]] = []
101
+ rollouts: list[asyncio.Future[Episode | None]] = []
71
102
  try:
72
103
  # Scheduled inside the try: a lazy taskset can raise after earlier tasks started.
73
104
  for task in taskset:
74
105
  for slot in env.slots(task, config.num_rollouts):
75
- rollouts.append(
76
- asyncio.ensure_future(
77
- env.run_slot(slot, ctx, semaphore, on_complete)
78
- )
79
- )
80
- return list(await asyncio.gather(*rollouts))
106
+ rollouts.append(asyncio.ensure_future(run_one(slot)))
107
+ results = await asyncio.gather(*rollouts)
81
108
  except BaseException:
82
109
  # Unwind every sibling before `serving()` tears down the resources they use.
83
110
  for rollout in rollouts:
84
111
  rollout.cancel()
85
112
  await asyncio.gather(*rollouts, return_exceptions=True)
86
113
  raise
114
+ if collect:
115
+ return [episode for episode in results if episode is not None]
116
+ return ok, episodes, reward_sum / traces if traces else 0.0
87
117
 
88
118
 
89
119
  def main(argv: list[str] | None = None) -> None:
@@ -120,12 +150,9 @@ def main(argv: list[str] | None = None) -> None:
120
150
  # A first Ctrl-C raises KeyboardInterrupt so each rollout's teardown still runs.
121
151
  install_interrupt()
122
152
  try:
123
- episodes = asyncio.run(run_episodes(config))
153
+ ok, total, reward = asyncio.run(run_episodes(config, collect=False))
124
154
  except KeyboardInterrupt:
125
155
  raise SystemExit(130)
126
- traces = [trace for episode in episodes for trace in episode.traces]
127
- ok = sum(episode.ok for episode in episodes)
128
- reward = sum(trace.reward for trace in traces) / len(traces) if traces else 0.0
129
- print(f"{ok}/{len(episodes)} episodes ok, mean reward {reward:.3f}: {out}")
130
- if ok < len(episodes):
156
+ print(f"{ok}/{total} episodes ok, mean reward {reward:.3f}: {out}")
157
+ if ok < total:
131
158
  raise SystemExit(1)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: verifiers
3
- Version: 0.4.2.dev128
3
+ Version: 0.4.2.dev129
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
@@ -26,7 +26,7 @@ verifiers/v1/cli/debug.py,sha256=U5TwxxqyrIOz5GbITBAp2y6oSIPxjmFttuwm3XOKy0U,114
26
26
  verifiers/v1/cli/output.py,sha256=vCscZ-g-sa-SLWDDQNoXBWelC_Je8lBdodvZGOe__eo,3285
27
27
  verifiers/v1/cli/resolve.py,sha256=Q1EHM7wWQo0YkwJA898qtZbYLaIkjIVq3Q7kUp2YIxs,4346
28
28
  verifiers/v1/cli/resume.py,sha256=hqV5AxxqeIInJeEZQerQznuijhMNijFEFcHZIltfLdE,470
29
- verifiers/v1/cli/run.py,sha256=fB3OyDGjj5leA0kCIuKiiMxJfhv_4afIUwT9_KDXXuE,4988
29
+ verifiers/v1/cli/run.py,sha256=IpOCMbRd5gOBaVMtsWMaDSxMm6hkQxRqQ1JLNmBm1T0,5803
30
30
  verifiers/v1/cli/validate.py,sha256=l_NekW1v00Wgr-l2f96rOti4KcLbYZgksb8CCZE3_20,20447
31
31
  verifiers/v1/clients/__init__.py,sha256=3rXv205sRheGvG8yNDmFwpq8qK9dlt7S_ia1zGWhNk0,598
32
32
  verifiers/v1/clients/base.py,sha256=C0G5lRm3nxt1xmPoA2cweBgCnN2KcLepmCYq1vdDrnU,1691
@@ -188,8 +188,8 @@ verifiers/v1/utils/scope.py,sha256=zbs4pj6AVk4jywlAJ3AX0Q0_kzB9dBB02nY-9H4ELdQ,8
188
188
  verifiers/v1/utils/score.py,sha256=493yJVMw8teCu9JxapxMFPFzI0hNUqdo0Y2nGW4kckk,6200
189
189
  verifiers/v1/utils/trace_store.py,sha256=7F6xMhYgl3qmylnCU8-ekqswH16fUat1uegeM1OR9QQ,2563
190
190
  verifiers/v1/utils/version.py,sha256=-obEo_-l9-D8FLef4hYxncOe-uJpxrM1g2Hig_37Sgs,1607
191
- verifiers-0.4.2.dev128.dist-info/METADATA,sha256=GtQMyIW-aEilqGH_PyoR0Ryem4JWZ401QkKz97_eLLo,5118
192
- verifiers-0.4.2.dev128.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
193
- verifiers-0.4.2.dev128.dist-info/entry_points.txt,sha256=qdMg7ajiFpDsHf7tuPMRclJXizu1J6LTWawS5YS0B0I,137
194
- verifiers-0.4.2.dev128.dist-info/licenses/LICENSE,sha256=v0RrUsdV3IDoZhrRce297IXS3xMHNJ-_LdLpFAUWb9k,1072
195
- verifiers-0.4.2.dev128.dist-info/RECORD,,
191
+ verifiers-0.4.2.dev129.dist-info/METADATA,sha256=PnxAp4-B116SB4k7q58kPzucp3WbFoKP0_YVhlSQTLg,5118
192
+ verifiers-0.4.2.dev129.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
193
+ verifiers-0.4.2.dev129.dist-info/entry_points.txt,sha256=qdMg7ajiFpDsHf7tuPMRclJXizu1J6LTWawS5YS0B0I,137
194
+ verifiers-0.4.2.dev129.dist-info/licenses/LICENSE,sha256=v0RrUsdV3IDoZhrRce297IXS3xMHNJ-_LdLpFAUWb9k,1072
195
+ verifiers-0.4.2.dev129.dist-info/RECORD,,