verifiers 0.4.2.dev24__py3-none-any.whl → 0.4.2.dev27__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/delta.py CHANGED
@@ -81,9 +81,12 @@ class DeltaStreamer:
81
81
  """Sends the current traces' changes as deltas, one flush per burst of changes.
82
82
 
83
83
  `watch` subscribes a trace; each `Trace.notify` schedules a flush, and changes landing in the
84
- same loop iteration share it. Use as an async context manager around the run: a clean exit
85
- flushes the final state, a failed one cancels pending sends. A cursor advances only once its
86
- delta is sent, so a failed send is diffed again at the next flush."""
84
+ same loop iteration share it. A flush diffs only the traces that notified since their last
85
+ delta was sent (and those never sent), so its cost follows what changed, not how many traces
86
+ are watched. Use as an async context manager around the run: a clean exit flushes the final
87
+ state of every trace, notified or not; a failed one cancels pending sends. A cursor advances
88
+ only once its delta is sent, so a failed send leaves its trace to be diffed again at the next
89
+ flush."""
87
90
 
88
91
  def __init__(
89
92
  self,
@@ -93,6 +96,10 @@ class DeltaStreamer:
93
96
  self.traces = traces
94
97
  self.send = send
95
98
  self.cursors: dict[str, TraceCursor] = {}
99
+ self._dirty: dict[str, int] = {}
100
+ """Trace id -> the change that last marked it. A sent delta clears the mark only if no
101
+ change came in while it was being sent."""
102
+ self._changes = 0
96
103
  self._scheduled: asyncio.Handle | None = None
97
104
  self._flushes: set[asyncio.Task] = set()
98
105
  self._lock = asyncio.Lock()
@@ -111,7 +118,7 @@ class DeltaStreamer:
111
118
  task.cancel()
112
119
  await asyncio.gather(*self._flushes, return_exceptions=True)
113
120
  if exc_type is None:
114
- await self.flush()
121
+ await self.flush(everything=True)
115
122
 
116
123
  def watch(self, trace: Trace) -> None:
117
124
  # A plain function, not the bound method: grading deep-copies traces mid-run, and a
@@ -120,6 +127,8 @@ class DeltaStreamer:
120
127
  self._changed(trace)
121
128
 
122
129
  def _changed(self, trace: Trace) -> None:
130
+ self._changes += 1
131
+ self._dirty[trace.id] = self._changes
123
132
  if self._scheduled is None and not self._closed:
124
133
  self._scheduled = asyncio.get_running_loop().call_soon(self._start_flush)
125
134
 
@@ -129,9 +138,12 @@ class DeltaStreamer:
129
138
  self._flushes.add(task)
130
139
  task.add_done_callback(self._flushes.discard)
131
140
 
132
- async def flush(self) -> None:
141
+ async def flush(self, everything: bool = False) -> None:
142
+ """Send the deltas of the traces that notified; `everything`: of every trace, for a
143
+ change no `notify` announced."""
133
144
  async with self._lock: # deltas must leave in diff order
134
- for trace_id, delta, cursor in self.diff():
145
+ marks = dict(self._dirty)
146
+ for trace_id, delta, cursor in self.diff(everything):
135
147
  # The cursor stays put on failure: the next flush resends it.
136
148
  try:
137
149
  await self.send(delta)
@@ -147,10 +159,15 @@ class DeltaStreamer:
147
159
  self.cursors.pop(trace_id, None)
148
160
  else:
149
161
  self.cursors[trace_id] = cursor
150
-
151
- def diff(self) -> list[tuple[str, dict, TraceCursor | None]]:
152
- """Each trace's delta, with its cursor as it stands once that delta is sent (None for a
153
- discard). Nothing is committed here: `flush` stores a cursor only after its send."""
162
+ if trace_id in marks and self._dirty.get(trace_id) == marks[trace_id]:
163
+ del self._dirty[trace_id]
164
+
165
+ def diff(
166
+ self, everything: bool = False
167
+ ) -> list[tuple[str, dict, TraceCursor | None]]:
168
+ """Each notified trace's delta (`everything`: each trace's), with its cursor as it stands
169
+ once that delta is sent (None for a discard). Nothing is committed here: `flush` stores
170
+ a cursor only after its send."""
154
171
  traces = list(self.traces())
155
172
  live = {trace.id for trace in traces}
156
173
  # A trace that left the live set (a retried attempt) is discarded on the other side too.
@@ -159,11 +176,16 @@ class DeltaStreamer:
159
176
  for gone in self.cursors
160
177
  if gone not in live
161
178
  ]
179
+ for gone in [gone for gone in self._dirty if gone not in live]:
180
+ if gone not in self.cursors: # never sent, or its discard already went
181
+ del self._dirty[gone]
162
182
  for trace in traces:
163
183
  delta: dict[str, Any] = {"trace": trace.id}
164
184
  sent = self.cursors.get(trace.id)
165
185
  if sent is not None and sent.attempt != trace.attempt:
166
186
  sent = None # a retry's fresh trace under the same id: reopen it from scratch
187
+ if sent is not None and not everything and trace.id not in self._dirty:
188
+ continue # nothing announced since its last delta
167
189
  cursor = sent.copy() if sent is not None else TraceCursor(trace.attempt)
168
190
  if sent is None:
169
191
  delta["open"] = dump(trace, include=set(HEADER_FIELDS))
@@ -211,6 +233,8 @@ class DeltaStreamer:
211
233
  cursor.pending = delta["pending"] = pending
212
234
  if len(delta) > 1:
213
235
  deltas.append((trace.id, delta, cursor))
236
+ else:
237
+ self._dirty.pop(trace.id, None)
214
238
  return deltas
215
239
 
216
240
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: verifiers
3
- Version: 0.4.2.dev24
3
+ Version: 0.4.2.dev27
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
@@ -1,7 +1,7 @@
1
1
  verifiers/__init__.py,sha256=F5IVMw6mhGaPBMCw7QKk0la_r5mMwydP2hdTTdQucik,352
2
2
  verifiers/v1/__init__.py,sha256=TB8TzPRiMc5kUlyWJNknoQ1GC-BpANsIyaeDk41ajUo,18542
3
3
  verifiers/v1/agent.py,sha256=3mRrubm2EwGIYexdJ9F0Lq5Uuta9-E_CC29Phh_9Vbw,48439
4
- verifiers/v1/delta.py,sha256=8skX50FyI9uwvMd2MZNuF4-s7XYOP0G9-OBv0aUyU4A,10836
4
+ verifiers/v1/delta.py,sha256=23USfU7G5L3TBnV3apyuOa0M_uQAgvTo6a4Ke4msRV0,12205
5
5
  verifiers/v1/env.py,sha256=UA1FdNd64XywIevJliNyL54afa2StN1ND6ro9HrjlVo,20566
6
6
  verifiers/v1/episode.py,sha256=ExeTkNEBsDuG40m6VogV6Gd4IHdO4SMPIzQSpt_V96U,6984
7
7
  verifiers/v1/errors.py,sha256=OieUBIOZ6FW7oKygbXIRoag6RrPxKYpMPfEYPcCnVVE,5863
@@ -193,8 +193,8 @@ verifiers/v1/utils/scope.py,sha256=zbs4pj6AVk4jywlAJ3AX0Q0_kzB9dBB02nY-9H4ELdQ,8
193
193
  verifiers/v1/utils/score.py,sha256=493yJVMw8teCu9JxapxMFPFzI0hNUqdo0Y2nGW4kckk,6200
194
194
  verifiers/v1/utils/trace_store.py,sha256=Qo9qvsJAl8PoRUavjQAfUB2VNxmUtYQtU2ejLKPzY9c,3382
195
195
  verifiers/v1/utils/version.py,sha256=-obEo_-l9-D8FLef4hYxncOe-uJpxrM1g2Hig_37Sgs,1607
196
- verifiers-0.4.2.dev24.dist-info/METADATA,sha256=5rhZUAdmgchfoISvjY_eBNkP7WaVBKByCmiJT0fZip8,5142
197
- verifiers-0.4.2.dev24.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
198
- verifiers-0.4.2.dev24.dist-info/entry_points.txt,sha256=3M8Wr0w1cUKiB-fJ6YHB6eK5WuKYg-Y3OC4wCuUje_c,174
199
- verifiers-0.4.2.dev24.dist-info/licenses/LICENSE,sha256=v0RrUsdV3IDoZhrRce297IXS3xMHNJ-_LdLpFAUWb9k,1072
200
- verifiers-0.4.2.dev24.dist-info/RECORD,,
196
+ verifiers-0.4.2.dev27.dist-info/METADATA,sha256=pgBuM14cyIFzsHteFfb5PDsaOBTp6cE7hD1oOuy_r3Y,5142
197
+ verifiers-0.4.2.dev27.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
198
+ verifiers-0.4.2.dev27.dist-info/entry_points.txt,sha256=3M8Wr0w1cUKiB-fJ6YHB6eK5WuKYg-Y3OC4wCuUje_c,174
199
+ verifiers-0.4.2.dev27.dist-info/licenses/LICENSE,sha256=v0RrUsdV3IDoZhrRce297IXS3xMHNJ-_LdLpFAUWb9k,1072
200
+ verifiers-0.4.2.dev27.dist-info/RECORD,,