verifiers 0.4.1.dev96__py3-none-any.whl → 0.4.1.dev97__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.
@@ -6,7 +6,6 @@ The judge has its own non-training trace and writes rubric verdicts to a file.
6
6
  """
7
7
 
8
8
  import copy
9
- import json
10
9
  import re
11
10
  from pathlib import Path
12
11
 
@@ -28,6 +27,9 @@ from verifiers.v1.utils.compile import validate_pairing
28
27
 
29
28
  VERDICT_FILE = "/tmp/verdict.json"
30
29
  TRACE_FILE = "/tmp/trace.json"
30
+ HIDDEN_REASONING = {"reasoning_content", "provider_state"}
31
+ """Message fields a judge's trace file leaves out by default: hidden reasoning and
32
+ provider-only state."""
31
33
 
32
34
  GRADE_PROMPT = """\
33
35
  You are grading another agent's attempt at a task. Verify the work EMPIRICALLY:
@@ -138,16 +140,12 @@ class JudgeTask(vf.Task):
138
140
  ) -> "JudgeTask":
139
141
  """Build the verdict task for the already prepared scoring workspace."""
140
142
  solved = solution.task.data
141
- record = solution.to_record()
142
143
  # This snapshot is evidence for verification, not its final outcome.
143
144
  # stop() marks the agent loop completed before rollout scoring finishes.
144
- record.pop("ok", None)
145
+ exclude: dict = {"ok": True}
145
146
  if not config.include_hidden_reasoning:
146
- for node in record["nodes"]:
147
- message = node["message"]
148
- message.pop("reasoning_content", None)
149
- message.pop("provider_state", None)
150
- files = {TRACE_FILE: json.dumps(record).encode()}
147
+ exclude["nodes"] = {"__all__": {"message": HIDDEN_REASONING}}
148
+ files = {TRACE_FILE: solution.to_json(exclude=exclude)}
151
149
  template = config.build_prompt()
152
150
  body = _render(template, prompt=solved.prompt_text)
153
151
  if "{prompt}" not in template:
@@ -9,7 +9,6 @@ score averaged across them.
9
9
  """
10
10
 
11
11
  import asyncio
12
- import json
13
12
  import random
14
13
  import shlex
15
14
  import statistics
@@ -19,6 +18,7 @@ from pydantic import BaseModel, ConfigDict, Field
19
18
 
20
19
  import verifiers.v1 as vf
21
20
  from verifiers.v1.envs.agentic_judge.env import (
21
+ HIDDEN_REASONING,
22
22
  VERDICT_FILE,
23
23
  JudgeTaskConfig,
24
24
  ScoreConfig,
@@ -130,13 +130,10 @@ class RankTask(vf.Task):
130
130
 
131
131
  @staticmethod
132
132
  def record(attempt: vf.Trace) -> bytes:
133
- record = attempt.to_record()
134
133
  # This snapshot is evidence for verification, not its final outcome.
135
- record.pop("ok", None)
136
- for node in record["nodes"]:
137
- node["message"].pop("reasoning_content", None)
138
- node["message"].pop("provider_state", None)
139
- return json.dumps(record).encode()
134
+ return attempt.to_json(
135
+ exclude={"ok": True, "nodes": {"__all__": {"message": HIDDEN_REASONING}}}
136
+ )
140
137
 
141
138
  async def setup(self, trace: vf.Trace, runtime: vf.Runtime) -> None:
142
139
  # Archive bytes are the attempts': confine every member to its declared
verifiers/v1/episode.py CHANGED
@@ -3,13 +3,22 @@
3
3
  import uuid
4
4
  from typing import Annotated, Any, Generic, Literal, Self
5
5
 
6
+ import orjson
6
7
  from pydantic import BaseModel, Field, computed_field, model_validator
7
8
 
8
9
  from verifiers.v1.configs.agent import WireAgentConfig
9
10
  from verifiers.v1.graph import RECORD_FLOAT_DECIMALS
10
11
  from verifiers.v1.state import State, StateT
11
12
  from verifiers.v1.task import DataT, WireTaskData
12
- from verifiers.v1.trace import EXCLUDE_FIELDS, AgentConfigT, Error, Trace, TraceTask
13
+ from verifiers.v1.trace import (
14
+ RECORD_DUMP_EXCLUDE,
15
+ AgentConfigT,
16
+ Error,
17
+ Trace,
18
+ TraceTask,
19
+ add_record_streams,
20
+ merge_exclude,
21
+ )
13
22
  from verifiers.v1.types import Usage
14
23
 
15
24
 
@@ -154,15 +163,34 @@ class Episode(BaseModel, Generic[DataT, StateT, AgentConfigT]):
154
163
  return grouped
155
164
 
156
165
  def to_record(
157
- self, float_decimals: int | None = RECORD_FLOAT_DECIMALS
166
+ self,
167
+ float_decimals: int | None = RECORD_FLOAT_DECIMALS,
168
+ exclude: dict | set | None = None,
158
169
  ) -> dict[str, Any]:
159
170
  """JSON record without raw trace tensors, which remain on the msgpack wire.
160
- Per-token float streams are rounded to `float_decimals` (`None` keeps every digit)."""
161
- return self.model_dump(
171
+ Per-token node streams are numpy arrays (`graph.RECORD_STREAMS`): encode it with
172
+ `to_json`, or with orjson and `OPT_SERIALIZE_NUMPY`. Per-token float streams are
173
+ rounded to `float_decimals` (`None` keeps every digit). `exclude` is a pydantic
174
+ exclude spec for the other fields; the streams are always included."""
175
+ record = self.model_dump(
162
176
  mode="json",
163
- exclude={"traces": {"__all__": EXCLUDE_FIELDS}},
177
+ exclude=merge_exclude(
178
+ {"traces": {"__all__": RECORD_DUMP_EXCLUDE}}, exclude
179
+ ),
164
180
  exclude_none=True,
165
- context={"float_decimals": float_decimals},
181
+ )
182
+ for trace_record, trace in zip(record["traces"], self.traces, strict=True):
183
+ add_record_streams(trace_record, trace, float_decimals, exclude_none=True)
184
+ return record
185
+
186
+ def to_json(
187
+ self,
188
+ float_decimals: int | None = RECORD_FLOAT_DECIMALS,
189
+ exclude: dict | set | None = None,
190
+ ) -> bytes:
191
+ """`to_record` as compact UTF-8 JSON. NaN and infinity become `null`."""
192
+ return orjson.dumps(
193
+ self.to_record(float_decimals, exclude), option=orjson.OPT_SERIALIZE_NUMPY
166
194
  )
167
195
 
168
196
 
verifiers/v1/graph.py CHANGED
@@ -88,19 +88,40 @@ ROUNDED_STREAMS = (
88
88
  """Float streams a JSON record rounds to `float_decimals`. Loss weights stay exact: a 1/T
89
89
  weight would round to zero."""
90
90
 
91
+ RECORD_STREAMS = ("token_ids", "mask", "is_content", *ROUNDED_STREAMS, "loss_weights")
92
+ """Per-token node fields a JSON record (`to_record`) carries as numpy arrays — `loss_weights`
93
+ as a dict of them — so an encoder writes each stream in one pass instead of element by
94
+ element."""
95
+
96
+
97
+ def round_stream(values: list | np.ndarray, decimals: int) -> np.ndarray:
98
+ """A float stream rounded to `decimals`, in float64."""
99
+ return np.round(np.asarray(values, dtype=np.float64), decimals)
100
+
101
+
102
+ def _record_array(values: list | np.ndarray, decimals: int | None) -> np.ndarray:
103
+ """A stream as a record array: C-contiguous, which numpy-aware encoders require. Floats
104
+ widen to float64 so they print the digits a list of Python floats does — float32 would
105
+ print its own shortest form."""
106
+ array = np.asarray(values)
107
+ if array.dtype.kind == "f":
108
+ if decimals is not None:
109
+ return round_stream(array, decimals)
110
+ return array.astype(np.float64)
111
+ return np.ascontiguousarray(array)
112
+
91
113
 
92
114
  def _serialize_stream(
93
115
  values: list | np.ndarray, info: FieldSerializationInfo, rounded: bool
94
116
  ) -> list | dict:
95
- """JSON records: a list. Python dumps: a list too, unless the context sets `token_arrays`,
117
+ """JSON dumps: a list. Python dumps: a list too, unless the context sets `token_arrays`,
96
118
  when the msgpack wire carries a raw-bytes `__nd__` dict."""
97
119
  context = info.context or {}
98
120
  if info.mode_is_json():
99
- values = as_list(values)
100
121
  decimals = context.get("float_decimals", RECORD_FLOAT_DECIMALS)
101
122
  if not rounded or decimals is None:
102
- return values
103
- return [round(value, decimals) for value in values]
123
+ return as_list(values)
124
+ return round_stream(values, decimals).tolist()
104
125
  if context.get("token_arrays"):
105
126
  return encode_ndarray(np.asarray(values))
106
127
  return as_list(values)
@@ -207,6 +228,26 @@ class MessageNode(BaseModel):
207
228
  else self.renderer_token_ids
208
229
  )
209
230
 
231
+ def record_streams(
232
+ self, float_decimals: int | None, exclude_none: bool
233
+ ) -> dict[str, Any]:
234
+ """This node's `RECORD_STREAMS` for its JSON record, as numpy arrays. Float streams
235
+ in `ROUNDED_STREAMS` are rounded to `float_decimals` (`None` keeps every digit)."""
236
+ streams: dict[str, Any] = {}
237
+ for name in RECORD_STREAMS:
238
+ values = getattr(self, name)
239
+ if values is None:
240
+ if not exclude_none:
241
+ streams[name] = None
242
+ elif name == "loss_weights":
243
+ streams[name] = {
244
+ key: _record_array(stream, None) for key, stream in values.items()
245
+ }
246
+ else:
247
+ decimals = float_decimals if name in ROUNDED_STREAMS else None
248
+ streams[name] = _record_array(values, decimals)
249
+ return streams
250
+
210
251
  @field_serializer("token_ids", "mask", "is_content", *ROUNDED_STREAMS)
211
252
  def serialize_token_stream(
212
253
  self, values: list | np.ndarray | None, info: FieldSerializationInfo
verifiers/v1/trace.py CHANGED
@@ -9,6 +9,7 @@ from collections.abc import Callable, Iterable, Iterator, Mapping
9
9
  from typing import TYPE_CHECKING, Any, Generic
10
10
 
11
11
  import numpy as np
12
+ import orjson
12
13
  from pydantic import BaseModel, Field, PrivateAttr, computed_field, field_serializer
13
14
  from typing_extensions import TypeVar
14
15
 
@@ -52,6 +53,42 @@ EXCLUDE_FIELDS: dict = {
52
53
  }
53
54
  """Raw tensor fields kept on the msgpack wire but excluded from disk serialization."""
54
55
 
56
+ RECORD_DUMP_EXCLUDE: dict = {
57
+ "nodes": {"__all__": EXCLUDE_FIELDS["nodes"]["__all__"] | set(graph.RECORD_STREAMS)}
58
+ }
59
+ """What `to_record` leaves out of its pydantic dump: the wire-only tensors, and the per-token
60
+ streams, which `add_record_streams` adds as numpy arrays. Pydantic's JSON mode cannot emit
61
+ numpy arrays, and building the streams as lists of Python numbers would be most of the cost
62
+ of a record."""
63
+
64
+
65
+ def merge_exclude(*excludes: dict | set | None) -> dict:
66
+ """Pydantic `exclude` specs combined into one. A field that any spec excludes whole
67
+ stays excluded whole."""
68
+ merged: dict = {}
69
+ for exclude in excludes:
70
+ if not exclude:
71
+ continue
72
+ items = dict.fromkeys(exclude, True) if isinstance(exclude, set) else exclude
73
+ for key, value in items.items():
74
+ current = merged.get(key)
75
+ if current is True or value is True or value is ...:
76
+ merged[key] = True
77
+ else:
78
+ merged[key] = merge_exclude(current, value)
79
+ return merged
80
+
81
+
82
+ def add_record_streams(
83
+ record: dict[str, Any],
84
+ trace: Trace,
85
+ float_decimals: int | None,
86
+ exclude_none: bool,
87
+ ) -> None:
88
+ """Join a trace's record (dumped with `RECORD_DUMP_EXCLUDE`) with its node streams."""
89
+ for node_record, node in zip(record["nodes"], trace.nodes, strict=True):
90
+ node_record.update(node.record_streams(float_decimals, exclude_none))
91
+
55
92
 
56
93
  class TimeSpan(BaseModel):
57
94
  """Wall-clock timestamps with a derived, non-serialized duration in seconds."""
@@ -796,14 +833,29 @@ class Trace(BaseModel, Generic[DataT, StateT, AgentConfigT]):
796
833
  self.stop(stop_condition(error))
797
834
 
798
835
  def to_record(
799
- self, float_decimals: int | None = RECORD_FLOAT_DECIMALS
836
+ self,
837
+ float_decimals: int | None = RECORD_FLOAT_DECIMALS,
838
+ exclude: dict | set | None = None,
800
839
  ) -> dict[str, Any]:
801
840
  """JSON record without raw tensors, which remain available on the msgpack wire.
802
- Per-token float streams are rounded to `float_decimals` (`None` keeps every digit)."""
803
- return self.model_dump(
804
- mode="json",
805
- exclude=EXCLUDE_FIELDS,
806
- context={"float_decimals": float_decimals},
841
+ Per-token node streams are numpy arrays (`graph.RECORD_STREAMS`): encode it with
842
+ `to_json`, or with orjson and `OPT_SERIALIZE_NUMPY`. Per-token float streams are
843
+ rounded to `float_decimals` (`None` keeps every digit). `exclude` is a pydantic
844
+ exclude spec for the other fields; the streams are always included."""
845
+ record = self.model_dump(
846
+ mode="json", exclude=merge_exclude(RECORD_DUMP_EXCLUDE, exclude)
847
+ )
848
+ add_record_streams(record, self, float_decimals, exclude_none=False)
849
+ return record
850
+
851
+ def to_json(
852
+ self,
853
+ float_decimals: int | None = RECORD_FLOAT_DECIMALS,
854
+ exclude: dict | set | None = None,
855
+ ) -> bytes:
856
+ """`to_record` as compact UTF-8 JSON. NaN and infinity become `null`."""
857
+ return orjson.dumps(
858
+ self.to_record(float_decimals, exclude), option=orjson.OPT_SERIALIZE_NUMPY
807
859
  )
808
860
 
809
861
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: verifiers
3
- Version: 0.4.1.dev96
3
+ Version: 0.4.1.dev97
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
@@ -34,6 +34,7 @@ Requires-Dist: mcp==2.2.0
34
34
  Requires-Dist: msgpack>=1.1.2
35
35
  Requires-Dist: numpy>=2.1.0
36
36
  Requires-Dist: openai<3.0.0,>=2.54.0
37
+ Requires-Dist: orjson>=3.10.0
37
38
  Requires-Dist: prime-pydantic-config[toml]>=0.4.3
38
39
  Requires-Dist: prime-runs>=0.1.4
39
40
  Requires-Dist: prime-sandboxes>=0.5.1
@@ -2,10 +2,10 @@ verifiers/__init__.py,sha256=F5IVMw6mhGaPBMCw7QKk0la_r5mMwydP2hdTTdQucik,352
2
2
  verifiers/v1/__init__.py,sha256=2nz8TJC-CifIXzChXHaNVg0rUgYrerd1w6vysODI6Gk,18901
3
3
  verifiers/v1/agent.py,sha256=_PBWiO3dmAGQvD4rCb5SIW6nLvYd7BBsPf1qxsQIXPw,47290
4
4
  verifiers/v1/env.py,sha256=fxXBjVyi0milYViHt6O0vBK3JdM2TYSOoQpXd0P0rFE,18110
5
- verifiers/v1/episode.py,sha256=UPtA02aGWA-fY8cJKEuYCMtQVnPN1C0BSN13LggNT8U,5986
5
+ verifiers/v1/episode.py,sha256=gl6wXCTicFabjnEbJ1S7zI_Gg9jgRS9pJG68d45KJEY,6931
6
6
  verifiers/v1/errors.py,sha256=nNabzi55J5aHmAmW9UHZVpI7kcBfy4Xcyt4cQthZbM8,5875
7
7
  verifiers/v1/grading.py,sha256=Z8J9-UiQA_P8MOMn1CAGsD_SgmrQd6-H_VPmD27ezss,9685
8
- verifiers/v1/graph.py,sha256=ZLuaEl2SxIvMTgws5XNfy-SNjapylLuYtVbcLI2-rMU,46274
8
+ verifiers/v1/graph.py,sha256=FoywN6AGOJh6MlFUFW1vBjcQRh_-4YHckyAcXAW-oF0,48143
9
9
  verifiers/v1/harness.py,sha256=Hvul6cbb9uWQl4GmHubvcRHqKdfeCY3n44r_ga0csfI,16806
10
10
  verifiers/v1/judge.py,sha256=T-TyYVcLGIoyUADYKy_pCBj2CTLhERlct5pmmWqPpTA,10507
11
11
  verifiers/v1/rollout.py,sha256=Rrliwo9i-a-wcbE9rJZZTYA4vkDlNJBJNKecoldreBw,45907
@@ -14,7 +14,7 @@ verifiers/v1/session.py,sha256=Wp_IZyYGC2D35OokpYlJcSBUR_OS38QPYrhODOgnV3U,29371
14
14
  verifiers/v1/state.py,sha256=EckF2bWp-vV4b1jYJ9sLI5xrfGuI5spIgYYwW926toI,595
15
15
  verifiers/v1/task.py,sha256=rH9ekXd33LN7oynppiogZgY5L6s_DEbTyNPZ4GQEBss,15471
16
16
  verifiers/v1/taskset.py,sha256=LE_3ogL7itU2Amk-N20cHkZ7Ev6MznJ0HpC8B1xb4w0,9482
17
- verifiers/v1/trace.py,sha256=kXqoKL4vmmJkEPAw3rczqqPkHXHFLKKMCV9CYZ7LB6M,33061
17
+ verifiers/v1/trace.py,sha256=l22hxgq41TQ8jLfqqgAsrWCHCObhkymWZX3I3xs2t3U,35229
18
18
  verifiers/v1/types.py,sha256=wU81MAjdzy8FO3LUPjMQVRkEFMcVBUTtdHc068UDKJY,14804
19
19
  verifiers/v1/acp/__init__.py,sha256=jY7nLAbB6uzSl-f6YCz05zBH5tarBLErNTkvV0vlaho,16613
20
20
  verifiers/v1/acp/runner.py,sha256=sFsg0UgWeDjpjihejUidIV2yTapVj1Ap0cDTaEktjkI,15484
@@ -70,11 +70,11 @@ verifiers/v1/dialects/chat.py,sha256=KZJYJzrbb9Nhyqzp6fjOB1K5pzHX-CLaP4Yuh6zShOM
70
70
  verifiers/v1/dialects/responses.py,sha256=jd8-xZ65MOtnHnnH295s4TCUgvDbfyYg0ialKo3HvgE,31259
71
71
  verifiers/v1/envs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
72
72
  verifiers/v1/envs/agentic_judge/__init__.py,sha256=6vwtMCQ_cuvuubCF5-nrE5W7gGgzE-LIPKorkM5DXdw,309
73
- verifiers/v1/envs/agentic_judge/env.py,sha256=WLvEvM7bgTieCvOtmOLb-2RmWOwpMAd3m0GZuitUCzc,14956
73
+ verifiers/v1/envs/agentic_judge/env.py,sha256=AkANEM5mSiGJ-udJWvHKeNMVq4wRcWpXX0yOJ2qqS78,14968
74
74
  verifiers/v1/envs/best_of_n/__init__.py,sha256=mubASiwXMNIhnQFDccNAc7yZ0OFsOVK8hH8WIx9b2A4,119
75
75
  verifiers/v1/envs/best_of_n/env.py,sha256=KEUJBCVqblnXP_lEwm3mjGdaikBMkecz8UjOFPBhxc0,1987
76
76
  verifiers/v1/envs/best_of_n_judge/__init__.py,sha256=xEe_uG3CHVa4psZOkbrQV8u9u63HK1iR-jvtuknUZOw,222
77
- verifiers/v1/envs/best_of_n_judge/env.py,sha256=2jb2wbiGQ9HWAOqBKDkdtkUnzdyfJWUxTqbTiYPMha8,14756
77
+ verifiers/v1/envs/best_of_n_judge/env.py,sha256=GgHriH6qq4okzjKqYeFGU-1q5FKM3oZW6Cal4T2_u5M,14631
78
78
  verifiers/v1/envs/single_agent/__init__.py,sha256=r0edAc_6gtHBhPzeBGVcdHZZqSdCPZnLMje6eVgyz5U,138
79
79
  verifiers/v1/envs/single_agent/env.py,sha256=iH-AnS5-5rDZM3MaYFxzaHSVqJAaw9mQJaaJvsDMMX4,854
80
80
  verifiers/v1/envs/user_sim/__init__.py,sha256=nnT695HdqjAEouYL5wtVu6MhIp2wf5yuK-EYgxOVx0s,118
@@ -208,8 +208,8 @@ verifiers/v1/utils/scope.py,sha256=bzUEiWDOVdbj7dXOwGOlzsQ_-Xu0j9NR5TalQB-8TS8,8
208
208
  verifiers/v1/utils/score.py,sha256=493yJVMw8teCu9JxapxMFPFzI0hNUqdo0Y2nGW4kckk,6200
209
209
  verifiers/v1/utils/trace_store.py,sha256=Qo9qvsJAl8PoRUavjQAfUB2VNxmUtYQtU2ejLKPzY9c,3382
210
210
  verifiers/v1/utils/version.py,sha256=-obEo_-l9-D8FLef4hYxncOe-uJpxrM1g2Hig_37Sgs,1607
211
- verifiers-0.4.1.dev96.dist-info/METADATA,sha256=lxB0TswMVHRJ6RA9wd9oKvKxnpbwyUAIr1j7A8OXrl4,5234
212
- verifiers-0.4.1.dev96.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
213
- verifiers-0.4.1.dev96.dist-info/entry_points.txt,sha256=O1bIO0gyJWuLfWtTGF0h-JkNz6FkyXP7Z9iMFYnjeMI,222
214
- verifiers-0.4.1.dev96.dist-info/licenses/LICENSE,sha256=v0RrUsdV3IDoZhrRce297IXS3xMHNJ-_LdLpFAUWb9k,1072
215
- verifiers-0.4.1.dev96.dist-info/RECORD,,
211
+ verifiers-0.4.1.dev97.dist-info/METADATA,sha256=HGNv10NUdocTQ1cc6mnjxoRzrzx8zRnUQiHjejZUMjM,5264
212
+ verifiers-0.4.1.dev97.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
213
+ verifiers-0.4.1.dev97.dist-info/entry_points.txt,sha256=O1bIO0gyJWuLfWtTGF0h-JkNz6FkyXP7Z9iMFYnjeMI,222
214
+ verifiers-0.4.1.dev97.dist-info/licenses/LICENSE,sha256=v0RrUsdV3IDoZhrRce297IXS3xMHNJ-_LdLpFAUWb9k,1072
215
+ verifiers-0.4.1.dev97.dist-info/RECORD,,