verifiers 0.3.1.dev62__py3-none-any.whl → 0.3.1.dev63__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.
@@ -12,7 +12,7 @@ from typing import Any, ClassVar, TypeVar
12
12
  from openai import OpenAIError
13
13
  from renderers import OverlongPromptError as RendererOverlongPromptError
14
14
  from renderers import RenderedTokens, Renderer, RendererConfig
15
- from renderers.base import ToolCallParseStatus
15
+ from renderers.base import ToolCallParseStatus, is_multimodal
16
16
 
17
17
  from verifiers.v1.clients.base import build_async_openai
18
18
  from verifiers.v1.clients.client import SESSION_ID_HEADER, Client
@@ -97,7 +97,10 @@ def serialize_completion(response: Response, model: str) -> dict:
97
97
 
98
98
 
99
99
  def response_from_generate(
100
- result: dict, model: str, bridged_turn: PendingTurn | None = None
100
+ result: dict,
101
+ model: str,
102
+ bridged_turn: PendingTurn | None = None,
103
+ mm_token_type_id_map: dict[int, int] | None = None,
101
104
  ) -> Response:
102
105
  """Parse a `renderers.client.generate` result dict into a typed `Response`,
103
106
  mirroring the chat client's `response_from_wire` (plus the token encoding)."""
@@ -154,6 +157,7 @@ def response_from_generate(
154
157
  message_spans=message_spans,
155
158
  is_content=attribution.is_content if attribution is not None else None,
156
159
  multi_modal_data=result.get("multi_modal_data"),
160
+ mm_token_type_id_map=mm_token_type_id_map,
157
161
  routed_experts=result.get("routed_experts"),
158
162
  kept_tokens=KeptTokens(**kept)
159
163
  if (kept := result.get("kept_tokens"))
@@ -371,6 +375,9 @@ class TrainClient(Client):
371
375
 
372
376
  async with pool.acquire() as slot:
373
377
  renderer = slot.renderer
378
+ mm_token_type_id_map = (
379
+ renderer.mm_token_type_id_map if is_multimodal(renderer) else None
380
+ )
374
381
  # Only build the (O(context)) previous-turn token ids once the cheap guards pass — a
375
382
  # multimodal prompt or a tail that isn't a clean `[tool*, user?]` extension can't bridge.
376
383
  can_bridge = (
@@ -434,7 +441,9 @@ class TrainClient(Client):
434
441
  raise OverlongPromptError(str(e)) from e
435
442
  except OpenAIError as e:
436
443
  raise model_error(e) from e
437
- response = response_from_generate(result, model, bridged_turn)
444
+ response = response_from_generate(
445
+ result, model, bridged_turn, mm_token_type_id_map
446
+ )
438
447
  # No provider response to relay (we generated), so serialize one for the program; the
439
448
  # interception server hands `Response.raw` back regardless of client.
440
449
  response.raw = serialize_completion(response, model)
verifiers/v1/graph.py CHANGED
@@ -535,6 +535,9 @@ def _commit_turn(turn: PendingTurn, response: Response) -> int:
535
535
  prompt = turn.prompt
536
536
  tokens = response.tokens
537
537
  multi_modal_data = tokens.multi_modal_data if tokens else None
538
+ # Constant per renderer, so re-stamping every turn is idempotent.
539
+ if tokens is not None and tokens.mm_token_type_id_map:
540
+ trace.mm_token_type_id_map = tokens.mm_token_type_id_map
538
541
  prompt_ids = tokens.prompt_ids if tokens else []
539
542
  spans = tokens.message_spans if tokens else None
540
543
  is_content = tokens.is_content if tokens else None
verifiers/v1/trace.py CHANGED
@@ -7,7 +7,7 @@ from collections.abc import Callable, Iterable, Iterator, Mapping
7
7
  from typing import TYPE_CHECKING, Any, Generic
8
8
 
9
9
  import numpy as np
10
- from pydantic import BaseModel, Field, PrivateAttr
10
+ from pydantic import BaseModel, Field, PrivateAttr, field_serializer
11
11
  from renderers.base import MultiModalData
12
12
  from typing_extensions import TypeVar
13
13
 
@@ -193,6 +193,8 @@ class Branch(BaseModel):
193
193
  index: int
194
194
  nodes: list[MessageNode]
195
195
  calls: list[ModelCall] = Field(default_factory=list)
196
+ mm_token_type_id_map: dict[int, int] = Field(default_factory=dict)
197
+ """The trace's `mm_token_type_id_map`, carried so `mm_token_type_ids` is self-contained."""
196
198
 
197
199
  @property
198
200
  def messages(self) -> Messages:
@@ -299,6 +301,16 @@ class Branch(BaseModel):
299
301
  merged.mm_hashes.setdefault(modality, []).extend(hashes)
300
302
  return merged if found else None
301
303
 
304
+ @property
305
+ def mm_token_type_ids(self) -> list[int] | None:
306
+ """Per-token modality markers aligned to `token_ids` (0 = text, 1 = image
307
+ placeholder, 2 = video placeholder), driving the trainer's vision-encoder
308
+ slicing; None for branches carrying no multimodal data."""
309
+ if self.multi_modal_data is None:
310
+ return None
311
+ mapping = self.mm_token_type_id_map
312
+ return [mapping.get(t, 0) for t in self.token_ids]
313
+
302
314
  @property
303
315
  def routed_experts(self) -> np.ndarray | None:
304
316
  """uint8 `[tokens, layers, top_k]` routing; partial data returns None."""
@@ -378,6 +390,10 @@ class Trace(BaseModel, Generic[DataT, StateT, AgentConfigT]):
378
390
  """The message graph; branches are derived views and storage stays linear in turns."""
379
391
  calls: list[ModelCall] = Field(default_factory=list)
380
392
  """Every model call; automatically recorded at intercept time + linked into `nodes`."""
393
+ mm_token_type_id_map: dict[int, int] = Field(default_factory=dict)
394
+ """Special-token id -> modality marker (1 = image placeholder, 2 = video placeholder)
395
+ from the renderer that tokenized this trace, stamped at turn commit. Applied to a
396
+ branch's `token_ids` by `Branch.mm_token_type_ids`; empty for text-only renderers."""
381
397
  request_rewrites: list[InterceptRecord] = Field(default_factory=list)
382
398
  """Request changes made by `@intercept`, in execution order."""
383
399
  response_rewrites: list[InterceptRecord] = Field(default_factory=list)
@@ -409,6 +425,12 @@ class Trace(BaseModel, Generic[DataT, StateT, AgentConfigT]):
409
425
  _head_index: dict = PrivateAttr(default_factory=dict)
410
426
  """`(parent, msg_hash) -> node_id` for the graph builder."""
411
427
 
428
+ @field_serializer("mm_token_type_id_map")
429
+ def serialize_mm_token_type_id_map(self, mapping: dict[int, int]) -> dict[str, int]:
430
+ """The wire unpacks with msgpack's `strict_map_key`, which forbids int map keys —
431
+ dump str keys; validation coerces them back to int."""
432
+ return {str(k): v for k, v in mapping.items()}
433
+
412
434
  @property
413
435
  def reward(self) -> float:
414
436
  return sum(r.value for r in self.rewards.values() if r is not None)
@@ -464,6 +486,7 @@ class Trace(BaseModel, Generic[DataT, StateT, AgentConfigT]):
464
486
  index=i,
465
487
  nodes=[self.nodes[n] for n in path],
466
488
  calls=[by_node[n] for n in path if n in by_node],
489
+ mm_token_type_id_map=self.mm_token_type_id_map,
467
490
  )
468
491
  )
469
492
  return branches
verifiers/v1/types.py CHANGED
@@ -212,6 +212,10 @@ class TurnTokens(BaseModel):
212
212
  # Transient carrier (excluded): the renderer's multimodal sidecar (image tensors + offsets),
213
213
  # attributed per node by the turn's `commit`, then dropped — never persisted.
214
214
  multi_modal_data: MultiModalData | None = Field(default=None, exclude=True)
215
+ # Transient carrier (excluded): the renderer's special-token id -> modality marker map,
216
+ # stamped onto `Trace.mm_token_type_id_map` by the turn's `commit`. None unless the
217
+ # rendering renderer is multimodal.
218
+ mm_token_type_id_map: dict[int, int] | None = Field(default=None, exclude=True)
215
219
  # Transient carrier (excluded): the MoE expert-routing data from `generate` (expert ids
216
220
  # per token), attributed per node by the turn's `commit` into `MessageNode.routed_experts`,
217
221
  # then dropped. None unless the engine ran with `enable_return_routed_experts`.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: verifiers
3
- Version: 0.3.1.dev62
3
+ Version: 0.3.1.dev63
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
@@ -173,7 +173,7 @@ verifiers/v1/agent.py,sha256=cMRVKzg9Vs6DCLJ5vXj8xc3-PJ2S6fhoJctS7zHinKM,31393
173
173
  verifiers/v1/env.py,sha256=CEhzjojhg5jqbOYruUnc5U7TtgDHDSx8NiiFA0qfbt8,18234
174
174
  verifiers/v1/episode.py,sha256=uStvI4WqgJT50hmHIB55m5B-ASqqLz-fZ-ynBz9uzEY,5474
175
175
  verifiers/v1/errors.py,sha256=kQeEPX06TwAIuiz7MlWFYirrpKbx5STi6A5b_dtQQoA,6885
176
- verifiers/v1/graph.py,sha256=JxhP34q-lH70C7i04WHLoqWX1OHBc0dp2Qkqtj9deaA,30330
176
+ verifiers/v1/graph.py,sha256=BNeqMhlZ2W9NWG9p1_YIyAOBoCkCHtw6z2w1qAwxbfw,30524
177
177
  verifiers/v1/harness.py,sha256=ziECqEBWV34UWbLlxrkhY6MwkbVYkoXBOoaY7mZxwTs,14753
178
178
  verifiers/v1/judge.py,sha256=Pvr0C41ah1qkNSZ0WXdkDvBMfv5YSfY1REHncwlJ8cg,9346
179
179
  verifiers/v1/rollout.py,sha256=vpjvlxufnV-ko1X2JZrNW-7CL8OQWI3h3Z3BtOrKv6M,23796
@@ -181,8 +181,8 @@ verifiers/v1/session.py,sha256=wORmp_P9duD5HWupHRm8EQVkg98_69o6_9zedaMW3c8,18607
181
181
  verifiers/v1/state.py,sha256=EckF2bWp-vV4b1jYJ9sLI5xrfGuI5spIgYYwW926toI,595
182
182
  verifiers/v1/task.py,sha256=ZiAE5uGxgHWqz8UF5YJHs80RgSKhxGMGQo4lJusSRus,11375
183
183
  verifiers/v1/taskset.py,sha256=fp2E0IEhL_Ybj9cegZwljfTmW27p_30zTWHFKw_kXE4,4374
184
- verifiers/v1/trace.py,sha256=UJ2yyJg87c9N-XXPzUfFVsAI9utE8-p8CMkuzz1hizo,23504
185
- verifiers/v1/types.py,sha256=-ygDFVvoWlb-7tLc_bskqrVGVuWawbBPA-Ul2UUiQvs,8815
184
+ verifiers/v1/trace.py,sha256=GbuQVcPUFdBYSXqeO36UT6xKBQCtY656Tg8Icgut_xk,24908
185
+ verifiers/v1/types.py,sha256=-0MFoN-_94B2GhDDwFOcRp-nlTki53f-5bV-ZOOxCSY,9119
186
186
  verifiers/v1/acp/__init__.py,sha256=-QQh5ZT0o9j98CzqltsheccmM3Xqqyneu-vN1U0NJ38,10232
187
187
  verifiers/v1/acp/runner.py,sha256=aP7yyXMDp1nkU-L20BSqcwqRo9YEhNnpM8u_dWfFpCw,9528
188
188
  verifiers/v1/cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -207,7 +207,7 @@ verifiers/v1/clients/__init__.py,sha256=Ysig0tE_0E4Jsfgfes1XHN-fK1s_RCXdqZD6E7lK
207
207
  verifiers/v1/clients/base.py,sha256=PoDw4GMqrfuPTFVK6n2jDmlD0_lJ5zTrYcNio5yq6K8,1691
208
208
  verifiers/v1/clients/client.py,sha256=zqC_AkiD9pl0kxxIbupNiehbS-YnVdp3EMZ0LOHTd8U,3125
209
209
  verifiers/v1/clients/eval.py,sha256=-OcYUqlj8dBRjyuffMvymc1fMfZcjo-p5q8ZSMvDGzY,8106
210
- verifiers/v1/clients/train.py,sha256=l3BHdtRNnBGR8BUB_9aTi6BKOXkpGmngeAHYVH32J5Y,18371
210
+ verifiers/v1/clients/train.py,sha256=9zcZSRjFLJpFfbulc6hKFr2ITMA-WZx2P7gogy4Gh9M,18684
211
211
  verifiers/v1/configs/__init__.py,sha256=X7u6X7B3ieD1HZl79Tv1kg-yPHbT0QLvAebaGqxVtvA,317
212
212
  verifiers/v1/configs/agent.py,sha256=L5P6ombAi4U5wwsspMHAuM8111sB9AVdm8q6B5iV1lw,3251
213
213
  verifiers/v1/configs/client.py,sha256=E7ZxeWBFV_AP8MyfxXncTZs-Yn-QKdDS57HCAzqVTrQ,4437
@@ -348,8 +348,8 @@ verifiers/v1/utils/prime.py,sha256=UTYRjp9cbjNb6CVmBHda-1wWZAIIfxNOmTyNuT7_wL4,9
348
348
  verifiers/v1/utils/retries.py,sha256=Y2ZgrAjn-qNkRKZP_RVNL_7EK0iaRcZeCa404lpGYi4,5417
349
349
  verifiers/v1/utils/score.py,sha256=-R5Cog14r_tJ6Q_oOfGr5VPAm2CCUhofYZB6B9lm4wM,5787
350
350
  verifiers/v1/utils/version.py,sha256=-obEo_-l9-D8FLef4hYxncOe-uJpxrM1g2Hig_37Sgs,1607
351
- verifiers-0.3.1.dev62.dist-info/METADATA,sha256=ynj_RJthR0NxAj0xLQxoMdEWOlihvNvlfccwVNxL7Ow,4653
352
- verifiers-0.3.1.dev62.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
353
- verifiers-0.3.1.dev62.dist-info/entry_points.txt,sha256=hZ5wDc1T8y-EvOziw7kQqatBJ6PbdSu2ygP5rjANl7c,564
354
- verifiers-0.3.1.dev62.dist-info/licenses/LICENSE,sha256=v0RrUsdV3IDoZhrRce297IXS3xMHNJ-_LdLpFAUWb9k,1072
355
- verifiers-0.3.1.dev62.dist-info/RECORD,,
351
+ verifiers-0.3.1.dev63.dist-info/METADATA,sha256=r0XAAWNHMBxSr7MeEqNQ7wqBuX52A9OtIHe5SWuZ6Ds,4653
352
+ verifiers-0.3.1.dev63.dist-info/WHEEL,sha256=zOwg4jB6zX2kU910N-cMawjivD6tO8NEWvE12je1bVk,87
353
+ verifiers-0.3.1.dev63.dist-info/entry_points.txt,sha256=hZ5wDc1T8y-EvOziw7kQqatBJ6PbdSu2ygP5rjANl7c,564
354
+ verifiers-0.3.1.dev63.dist-info/licenses/LICENSE,sha256=v0RrUsdV3IDoZhrRce297IXS3xMHNJ-_LdLpFAUWb9k,1072
355
+ verifiers-0.3.1.dev63.dist-info/RECORD,,