Skip to content
Merged
Show file tree
Hide file tree
Changes from 78 commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
dbee699
feat: add renderers package and RendererClient
hallerite Mar 25, 2026
c559760
feat: barrage test suite + fix tool_call_no_content + DefaultRenderer…
hallerite Mar 25, 2026
1704066
feat: add INTELLECT-3.1 support + Kimi K2.5 assessment
hallerite Mar 25, 2026
1ad4ee2
feat: add KimiRenderer + clean up auto-detection
hallerite Mar 25, 2026
3494ef1
chore: remove IntellectRenderer (needs full-string encoding approach)
hallerite Mar 25, 2026
75e5d7a
refactor: shared parsing module mirroring vLLM's tool/reasoning parsers
hallerite Mar 25, 2026
e4c4541
refactor: Tinker-style token-level parsing — scan token IDs, not deco…
hallerite Mar 25, 2026
3ef054a
fix: stop token stripping + <think> cleanup in token-level parsing
hallerite Mar 25, 2026
815c397
run ruff
hallerite Mar 25, 2026
ef8cd2a
chore: remove KimiRenderer + dead messages.py module
hallerite Mar 25, 2026
cfc9ac2
style: ruff format + check
hallerite Mar 25, 2026
3855444
feat: update proxy to use /v1/generate with VLM image support
hallerite Apr 7, 2026
77c0373
feat: switch training clients to renderers
hallerite Apr 8, 2026
49e1e5f
fix: harden renderer proxy routing
hallerite Apr 8, 2026
070c5da
refactor: simplify renderer transport
hallerite Apr 9, 2026
5fc53aa
feat: add renderers for DeepSeek V3, Kimi K2/K2.5, Nemotron 3, GPT-OS…
hallerite Apr 14, 2026
e42b025
style: ruff check + format
hallerite Apr 14, 2026
57db953
fix: resolve ty type errors at renderer/OpenAI boundary
hallerite Apr 14, 2026
cc3217d
refactor: RendererClient inherits from Client directly, not OpenAICha…
hallerite Apr 14, 2026
74df920
Merge remote-tracking branch 'origin/main' into renderers
hallerite Apr 14, 2026
fa5f015
merge: origin/main into renderers
hallerite Apr 14, 2026
b5f804e
feat: thread-pooled tokenization for parallel rollouts
hallerite Apr 14, 2026
5f292ae
Add stateful renderer prompt stitching
hallerite Apr 15, 2026
acd7f53
Enable stateful renderer stitching for VLM prompts
hallerite Apr 15, 2026
ca41eca
Add extension-break observability and end-to-end renderer tests
hallerite Apr 21, 2026
c4e50e4
fix(qwen3-vl): emit un-expanded image placeholders for vLLM
hallerite Apr 21, 2026
2d8cc29
fix(renderer-client): surface vLLM's server-expanded prompt_token_ids
hallerite Apr 21, 2026
7f44237
Revert "fix(renderer-client): surface vLLM's server-expanded prompt_t…
hallerite Apr 21, 2026
84079aa
perf(renderer-pool): parallelize tokenizer init, drop default size to 16
hallerite Apr 21, 2026
d420651
perf(renderer-pool): default pool size 1
hallerite Apr 21, 2026
c3eaea3
feat(renderers): warn on DefaultRenderer auto-detect fallback
hallerite Apr 22, 2026
939a633
refactor(renderers-client): drop unused image-extraction path
hallerite Apr 22, 2026
1d308d2
feat(renderers): pluggable tool_parser / reasoning_parser for Default…
hallerite Apr 22, 2026
0e95edf
feat(renderer-client): expose pool size via ClientConfig
hallerite Apr 22, 2026
9c5ad2b
fix(bridge): synthesize close token when prev completion was truncated
hallerite Apr 22, 2026
f47ba32
feat(bridge): gate synthesize-close on per-renderer opt-in
hallerite Apr 22, 2026
fb6ecb9
fix(bridge): let truncated steps anchor the bridge when synth is opte…
hallerite Apr 22, 2026
d3771a5
test(renderer-client): cover bridge-over-truncated-anchor across all …
hallerite Apr 22, 2026
10c6a05
feat(bridge): per-renderer bridge_to_next_turn hook + Qwen3.5 bridge fix
hallerite Apr 22, 2026
4a4f4b0
feat(bridge): GLM bridge_to_next_turn (handles next-turn-marker templ…
hallerite Apr 22, 2026
891da50
feat(bridge): chatml_bridge helper + per-renderer bridge_to_next_turn…
hallerite Apr 22, 2026
3f46828
fix(nemotron3): support tokenizers without <|endoftext|>
hallerite Apr 22, 2026
338f6b7
feat(bridge): harmony-aware bridge_to_next_turn for GptOssRenderer
hallerite Apr 22, 2026
02fe986
test(renderers): render → parse round-trip parity + fix string-arg to…
hallerite Apr 22, 2026
9020f70
test(renderers): expand round-trip matrix + fix Kimi/GPT-OSS parsing …
hallerite Apr 22, 2026
7ae1f59
feat(renderers): GLM-5.1 + Kimi K2 + Nemotron-3 parity against apply_…
hallerite Apr 23, 2026
7d2f7f7
feat(renderers): full parity wave 2 — Nemotron3/MiniMax tool BPE + in…
hallerite Apr 23, 2026
6f89c38
refactor(bridge): hand-coded bridge_to_next_turn per renderer; kill d…
hallerite Apr 23, 2026
c499099
fix(renderer-client): forward cache_salt from extra_body to /v1/generate
hallerite Apr 23, 2026
fafea87
refactor(model-map): exact-name match instead of longest-prefix
hallerite Apr 23, 2026
bcd44c9
fix(client): promote finish_reason stop->tool_calls when tool_calls p…
hallerite Apr 23, 2026
3e6b7c4
fix(default): decode tool_call arguments strings before chat template
hallerite Apr 23, 2026
2e30fd0
fix(parser): preserve whitespace at <think>/</think> boundary
hallerite Apr 23, 2026
8ab276e
fix(client): normalize tool_call.arguments as JSON in incremental match
hallerite Apr 23, 2026
4cf8d49
chore(client): add WARN-level trace in _get_incremental_prompt_ids
hallerite Apr 23, 2026
7435307
chore(client): split no_tokens trace into sub-cases
hallerite Apr 23, 2026
14fb3c9
fix(client): fall back to raw response tokens when step.tokens was tr…
hallerite Apr 23, 2026
dba2e97
fix(parse_qwen3): fall back to raw content when tool_call JSON malformed
hallerite Apr 24, 2026
5d65e3f
feat(client): categorize extension breaks in _get_incremental_prompt_ids
hallerite Apr 24, 2026
c58da4a
docs(renderers): expand README for external audience
hallerite Apr 24, 2026
7136de5
feat(renderers): add Qwen3.6 renderer
hallerite Apr 24, 2026
7b86d14
Merge remote-tracking branch 'origin/main' into renderers
hallerite Apr 24, 2026
3d2b16c
fix(client): catch vLLM overlong-prompt 400s and add /generate diagno…
hallerite Apr 27, 2026
d519870
fix(client): recover tool function name on tool-result render
hallerite Apr 28, 2026
e6c9367
feat(client): broaden vLLM /generate kwargs allowlist + extra_headers…
hallerite Apr 28, 2026
cd2d991
fix(renderers): bugbot-flagged edge cases on gpt_oss bridge, kimi_k2 …
hallerite Apr 28, 2026
623b9e6
test(renderers): assert message_indices invariants + Kimi K2 regression
hallerite Apr 28, 2026
bccc488
fix(renderers): K2.5/K2.6 token-for-token parity + drop dead minimax …
hallerite Apr 28, 2026
d2dcfe9
chore(tests): drop stale GLM-5.1 caveat from conftest comment
hallerite Apr 28, 2026
b11b9ca
fix(renderers/kimi_k25): tools encoder accepts flat ToolSpec format
hallerite Apr 28, 2026
5588f71
feat(renderers/gpt_oss): rewrite as openai-harmony adapter
hallerite Apr 28, 2026
748d03e
chore(clients): restore TITO path alongside renderer client
hallerite Apr 28, 2026
8e632d8
fix(renderers/kimi_k2): drop unused locals flagged by ruff F841
hallerite Apr 28, 2026
95a2336
chore(renderer-client): hoist imports above module helpers (ruff E402)
hallerite Apr 28, 2026
75c8ec3
fix(tests): align stale fixtures + xfail two unimplemented features
hallerite Apr 28, 2026
56063cb
style: apply ruff format across renderers package and renderer-client…
hallerite Apr 28, 2026
5e199dc
docs: re-add OpenAIChatCompletionsTokenClient (TITO) alongside Render…
hallerite Apr 28, 2026
17358ee
refactor(renderers): rename build_supervised_sample → build_training_…
hallerite Apr 28, 2026
b14033e
fix: cleanup-review small fixes
hallerite Apr 28, 2026
9afd448
refactor(renderer-client): drop extension-break diagnostic path
hallerite Apr 28, 2026
69c2b4c
refactor(renderers): drop synth-close flag and strip multimodal
hallerite Apr 28, 2026
5648765
chore: address Mika's cheap review comments
hallerite Apr 28, 2026
ebb2658
docs: explain renderer client type in training docs and FAQs
hallerite Apr 28, 2026
1ac41b4
docs: mark renderer client experimental, recommend TITO for production
hallerite Apr 28, 2026
1d991b6
refactor(renderer-client): move helpers above class to match other cl…
hallerite Apr 28, 2026
aa2ac32
style: ruff format trailing newlines in test_renderer_e2e
hallerite Apr 29, 2026
e2ede3f
fix(kimi_k25): emit tool_declare messages from content + drop dead arg
hallerite Apr 29, 2026
547b5e6
fix(kimi_k2): render assistant content verbatim, including inline <th…
hallerite Apr 29, 2026
ee6cdb5
fix(renderer-client): propagate id, model, created from /generate
hallerite Apr 29, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/evaluation.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ env.set_concurrency(256)
| `--model` | `-m` | `openai/gpt-4.1-mini` | Model name or endpoint alias |
| `--api-base-url` | `-b` | `https://api.pinference.ai/api/v1` | API base URL |
| `--api-key-var` | `-k` | `PRIME_API_KEY` | Environment variable containing API key |
| `--api-client-type` | — | `openai_chat_completions` | Client type: `openai_chat_completions`, `openai_completions`, `openai_chat_completions_token`, or `anthropic_messages` |
| `--api-client-type` | — | `openai_chat_completions` | Client type: `openai_chat_completions`, `openai_completions`, `openai_chat_completions_token`, `renderer`, or `anthropic_messages` |
Comment thread
hallerite marked this conversation as resolved.
Resolved
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
| `--endpoints-path` | `-e` | `./configs/endpoints.toml` | Path to TOML endpoints registry |
| `--header` | — | — | Extra HTTP header (`Name: Value`), repeatable |
| `--header-from-state` | — | `X-Session-ID: example_id` | Per-request header whose value is read from rollout state (`Name: state_key`), repeatable |
Expand Down
4 changes: 3 additions & 1 deletion docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ ClientType = Literal[
"openai_completions",
"openai_chat_completions",
"openai_chat_completions_token",
"renderer",
Comment thread
hallerite marked this conversation as resolved.
Resolved
"anthropic_messages",
]
```
Expand Down Expand Up @@ -654,7 +655,8 @@ Abstract base class for all model clients. Wraps a provider-specific SDK client
|-------|---------------|------------|-------------|
| `OpenAIChatCompletionsClient` | `"openai_chat_completions"` | `AsyncOpenAI` | Chat Completions API (default) |
| `OpenAICompletionsClient` | `"openai_completions"` | `AsyncOpenAI` | Legacy Completions API |
| `OpenAIChatCompletionsTokenClient` | `"openai_chat_completions_token"` | `AsyncOpenAI` | Custom vLLM token route |
| `OpenAIChatCompletionsTokenClient` | `"openai_chat_completions_token"` | `AsyncOpenAI` | Custom vLLM token route (`/v1/chat/completions/tokens`) — server-side templating + token IDs returned alongside content |
| `RendererClient` | `"renderer"` | `AsyncOpenAI` | Renderer-backed token-in generate client (client-side tokenization via the `renderers` package) |
| `AnthropicMessagesClient` | `"anthropic_messages"` | `AsyncAnthropic` | Anthropic Messages API |

All built-in clients are available as `vf.OpenAIChatCompletionsClient`, `vf.AnthropicMessagesClient`, etc.
Expand Down
212 changes: 212 additions & 0 deletions packages/renderers/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
# renderers

A per-model, Python-native chat-template layer that moves prompt assembly, tool-call parsing, and reasoning parsing out of vLLM and into our own code. Lives in `packages/renderers/` in the verifiers repo; consumed by `verifiers.clients.renderer_client`. Replaces the old TITO client.

---

## 1. Why renderers?

Previously, most of "what the prompt actually looks like" was delegated to vLLM: its chat-template application, its tool-call parser, its reasoning parser. That is a fruitful source of bugs, but the reason we need something like renderers is more fundamental.

For RL we need **Token-In, Token-Out (TITO)**: the trainer must see the exact token ids the sampler saw, with an exact loss mask. This is essential for keeping train-inference KL mismatch low and keeping the trainer stepping fast — rollouts whose per-turn prefixes drift under re-tokenization cannot be stitched into a single training sample and fragment into many partial ones.

Renderers turn vLLM into a dumb TITO inference engine. Every prompt manipulation happens client-side:

- **Chat template application** — we render `messages → token ids` ourselves, either with a hand-coded Python renderer that mirrors the Jinja template or with `DefaultRenderer`, which wraps `tokenizer.apply_chat_template` but still owns the tokenization boundary.
- **Tool-call parsing** — `ToolParser` implementations scan token ids for the model's special delimiter tokens (e.g. token id `151657` for `<tool_call>` on Qwen3). A regex-on-decoded-text parser can mistake a literal `"<tool_call>"` inside user content for a real tool-call opener; matching by id can't, because regular text never tokenizes to the special-token id.
- **Reasoning parsing** — `ReasoningParser` implementations split `<think>…</think>` with a tested whitespace-preservation contract (bit-exact newline handling around the closing tag — a spot where we had a real bug that silently broke the extension property at the think boundary).

### What we gain

- **RL correctness.** A prompt/completion split we control, which is exactly what `bridge_to_next_turn` relies on to keep rollouts from fragmenting under truncation or re-tokenization.
- **Testable parity.** Per-model renderers are plain Python. We can render the same conversation through the renderer and through HF's `apply_chat_template` and assert token-level parity. Every edge case (empty thinking, multiple tool calls, truncated turns) becomes a unit test instead of undefined behavior buried inside Jinja.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LFGGG

- **Escape hatch.** Anything without a hand-coded renderer falls back to `DefaultRenderer` (a generic `apply_chat_template` wrapper), which mirrors the previous TITO path.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what sort of guarantees, if any, can we give for this fallback? what are the pros and cons compare to fallback to mito?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, let me be more clear about this


---

## 2. API

### Renderer protocol

Every renderer implements this (`renderers.base.Renderer`):

```python
render(messages, *, tools=None, add_generation_prompt=False) -> RenderedTokens
render_ids(messages, *, tools=None, add_generation_prompt=False) -> list[int]
parse_response(token_ids) -> ParsedResponse
get_stop_token_ids() -> list[int]
bridge_to_next_turn(prev_prompt_ids, prev_completion_ids, new_messages, *, tools=None) -> list[int] | None
```

`RenderedTokens` carries `token_ids` **and** `message_indices` — one entry per token attributing each token to its source message, so the loss mask can be built from message roles. This lets `build_supervised_sample` assemble samples in O(1) renders instead of O(n).

`ParsedResponse` is `(content, reasoning_content, tool_calls)`.

Round-trip invariant: rendering `[user, assistant(content=X, reasoning=Y, tool_calls=[T])]` to token ids, slicing out the assistant completion, and feeding it through `parse_response` returns an equivalent structured assistant message (modulo field formatting). Tested per-renderer in `tests/test_roundtrip.py`.

### Picking a renderer

```python
from transformers import AutoTokenizer
from renderers.base import create_renderer
Comment thread
hallerite marked this conversation as resolved.
Resolved

tok = AutoTokenizer.from_pretrained("Qwen/Qwen3-8B")
r = create_renderer(tok, renderer="auto") # → Qwen3Renderer
```

`renderer="auto"` matches `tokenizer.name_or_path` against `MODEL_RENDERER_MAP` by **exact match**. Prefix matching is intentionally off: two models with the same architecture can ship different chat templates (base vs instruct, fine-tune renames), and prefix routing would silently pick a renderer that doesn't produce template-parity output. Fine-tunes must pass `renderer=<name>` explicitly; unknown names fall back to `DefaultRenderer`.

Available hand-coded renderers: `qwen3`, `qwen3_vl`, `qwen3.5`, `glm5`, `glm4.5`, `minimax-m2`, `deepseek_v3`, `kimi_k2`, `kimi_k25`, `nemotron3`, `gpt_oss`, `default`.
Comment thread
hallerite marked this conversation as resolved.
Resolved

### Pools

For multi-threaded pre-tokenization, use `RendererPool`:

```python
from renderers.base import create_renderer_pool

pool = create_renderer_pool("Qwen/Qwen3-8B", renderer="auto", size=16)
with pool.checkout() as r:
ids = r.render_ids(messages)
```

Each slot owns its own tokenizer copy. Construction fans out across a thread pool.

---

## 3. The bridge (the core contract)

After rollout step *N* the agent has produced `prompt_ids_N` and `completion_ids_N`. Call their concatenation *stream_N* — the exact bytes vLLM saw at sampling time plus what it emitted. For step *N+1* we require: **`prompt_ids_{N+1}` starts with *stream_N* token-for-token**, then continues with new tokens for the incoming tool result / user message / generation-prompt opener. This is the **extension property**.

```
stream_N = [t0, t1, t2, …, tK] # prompt_N + completion_N, length K+1
prompt_ids_N+1 = [t0, t1, t2, …, tK, tK+1, tK+2, …] # identical prefix, then new turn bytes
```

The next turn's prompt must **extend** the previous turn's tokens; it must never re-tokenize them.

If it holds, `interleave_rollout` merges the two steps into one training sample with one clean `completion_mask`. If it doesn't, the rollout fragments into multiple samples and `samples_per_rollout` drifts above 1.0 — significantly slowing the trainer without adding signal.

The bridge is what produces the tokens needed to uphold the extension property in accordance with the chat template the model was trained on.

### Per-renderer bridges

Each hand-coded renderer implements `bridge_to_next_turn` directly for its model's chat template — no shared generic helper, just Python that knows what tokens the template would insert between turns. Qwen3's bridge knows about `<|im_start|>role\n … <|im_end|>\n`; GLM's bridge knows that turns end when the next role marker appears; DeepSeek V3, Kimi K2/K2.5, Nemotron-3, GPT-OSS, MiniMax each have their own. On a clean stop, vLLM's `completion_ids` already includes the template's close token; on truncation, the renderer synthesizes the canonical close (`<|im_end|>`, `<|endoftext|>`, or the equivalent for that model) so the extension invariant still holds, and the synthetic close is masked out of the loss because the model didn't produce it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

legendary


`DefaultRenderer.bridge_to_next_turn` returns `None` by default (forcing a full `apply_chat_template` re-render, which is where modes a–e in §4 strike). Hand-coded bridges are what actually close the gap.

### Turn truncation

When a turn hits `max_tokens`, its `completion_ids` have no end-of-turn marker. A hand-coded renderer's bridge appends the template's canonical turn-close (`<|im_end|>`, `<|endoftext|>`, or equivalent) to the truncated completion and emits new messages on top. The synthetic close lands in `prompt_ids` of the merged sample with `prompt_mask=False`, so loss and KL never see it, and the extension invariant still holds.

---

## 4. Breaking behaviors you might not expect

Everything in this section has been observed in production RL runs on Qwen3, Qwen3.5, GLM-4.5, and opencode-scaffolded environments. Each is a concrete reason why the "render full history through `apply_chat_template` every turn" pattern breaks the extension property. Hand-coded renderers sidestep all of them because `bridge_to_next_turn` never re-renders prior turns.

### a. Boolean type round-trip

vLLM emits a literal `false` inside a parameter block; the client parses `<parameter=dry_run>false</parameter>` into a Python `bool(False)`; `apply_chat_template` re-renders via `str(False)` → `"False"`. Capital F. Every rollout with a boolean parameter breaks on re-render.

```
prev stream: '<parameter=dry_run>\nfalse\n</parameter>'
re-rendered: '<parameter=dry_run>\nFalse\n</parameter>'
```

Reproducible on Qwen3.5-35B-A3B + mini-swe-agent-plus: roughly 50% break rate per rollout (32 of 64 rollouts in a single step).

### b. BPE retokenization drift

The BPE tokenizer is context-sensitive. The same substring tokenizes differently depending on neighboring bytes, which can shift by one whitespace or boundary character between the raw completion and the re-rendered history. Example around `jsonp` inside a Python snippet:

```
prev ids: [..., 2164, 79, 50586, ...] # 'json' + 'p' + 'enderer' (3 tokens)
cur ids: [..., 55137, 50586, ...] # 'jsonp' + 'enderer' (2 tokens)
```

Same text, different token ids, different token count — from that point on every subsequent token id is shifted. Same class of bug we hit when `json.dumps` (Python, `{"k": "v"}` with spaces) vs. `JSON.stringify` (JS, `{"k":"v"}` compact) produced different raw arg bytes in an opencode scaffold and cascaded BPE drift through thousands of tokens of Python code.

### c. Tool-call XML structure drift

vLLM emits a no-arg tool call with a stylistic empty `</parameter>`; the Jinja template re-renders the reconstructed dict without it:

```
prev stream: '<function=echo ...>\n</parameter>\n</function>\n</tool_call>'
re-rendered: '<function=echo ...>\n</function>\n</tool_call>'
```

The `</parameter>\n` vanishes on re-render. Extension property broken at the close of every such call.

### d. Thinking stripped from non-latest assistant turns

Some chat templates strip `<think>…</think>` blocks out of prior assistant turns when re-rendering history. The rollout's recorded stream has the thinking content; the next turn's re-rendered prompt does not. Applies across the Qwen3-series under certain message shapes.

### e. Max-seq-len truncation zeroing the anchor

This one is client-side. When `parse_response_tokens` enforces the trainer's `max_seq_len`, it zeros out `completion_ids` whenever `prompt_len > max_seq_len`. On the next turn, the bridge's anchor (`prev_prompt_ids + prev_completion_ids`) is empty, so the bridge returns `None` and the caller falls back to full re-render — triggering modes a–d for every rollout that truncated. `_step_token_ids` now prefers populated `step.tokens` and falls back to the raw, un-truncated `step.response.message.tokens` specifically to defend against this.

### f. Scaffold-level history rewriting

Some agent scaffolds (e.g. opencode's AI-SDK `experimental_repairToolCall` hook) rewrite tool calls on the client before sending them back as history. If the model emits `Bash` (capital B), the hook rewrites it to a synthetic `{name: "invalid", input: {tool: "Bash", error: "Model tried to call unavailable tool Bash"}}`. The next turn's prompt now contains a tool call that the model never actually emitted — an unfixable extension break as long as the scaffold is in the loop. Renderers' bridge cannot help here because the drift is not in rendering; it's in the history the scaffold handed us.

### How renderers avoids the client-side ones

`bridge_to_next_turn(prev_prompt_ids, prev_completion_ids, new_messages, ...)` constructs the next-turn prompt as `prev_prompt_ids + prev_completion_ids + render_only_new_messages(...)`. It never re-parses prior tool call arguments, never re-tokenizes prior turns, never re-serializes prior tool-call XML. Modes a–e disappear by construction. Mode f is structural and outside the renderer's reach.

On Qwen3.5-35B-A3B + mini-swe-agent-plus step 0, the delta with renderers-v2 vs. `apply_chat_template`-based TITO:

| client path | breaks per step 0 | samples from 64 rollouts |
|--------------------------------------------|-------------------|---------------------------|
| `apply_chat_template` (full re-render) | 32 | 77 |
| renderers `bridge_to_next_turn` | 0 | 64 |

---

## 5. `DefaultRenderer`

Fallback for anything without a hand-coded renderer. Wraps `apply_chat_template` and accepts optional `tool_parser` / `reasoning_parser` kwargs (mirroring vLLM's convention) — it does its best to keep the Renderer contract even without model-specific knowledge.

That said, **prefer a hand-coded renderer** for any model you actually train on. Hand-coded renderers are the only path that closes all the extension-property gaps in §4 by construction. `DefaultRenderer` is there so an unknown model doesn't block you from running — not as the recommended steady state. If your model doesn't have one yet, implementing a renderer for it is a few hundred lines of Python (`render_ids` + `parse_response` + `bridge_to_next_turn`).

---

## 6. VLM support

Renderers currently do not support the VLM (image) path. `Qwen3VLRenderer` exists and works for text-only conversations against Qwen3-VL checkpoints, but `ImagePart` is not plumbed through render / parse / bridge or the client. Adding real VLM support requires (a) carrying image payloads through the content-part model end-to-end and (b) deciding how image tokens interact with the extension invariant across multi-turn steps. Out of scope for this iteration.

---

## 7. Patched vs. "correct" chat templates

Many chat templates are poorly suited to RL — they re-tokenize history on every turn, or normalize boolean/JSON values, or auto-strip thinking content from past turns, each of which breaks the extension property.

There is a balance to strike between exact parity with the shipped template — which some downstream consumers expect — and giving users faster, more correct training.

Roadmap: add a `use_patched` flag on renderers whose shipped template is sub-optimal for RL. The patched variant would render the same surface form but avoid the known extension-breaking patterns.

### Training-inference parity in production

Downstream customers typically host the trained model on vLLM. Training with renderers (client-side TITO) and then serving through vLLM's default `/v1/chat/completions` path is a source of subtle drift.

Approach: train with renderers (Renderer client), but run evals during training through the normal `/v1/chat/completions` endpoint — that is the most prod-like setting and surfaces any train-to-serve mismatch before it ships.

---

## 8. Validation surface

Environments used to validate renderer parity and break behavior end-to-end:

- Reverse-Text — single-turn, no tools
- Wordle — multi-turn, deterministic feedback
- OpenCode-Math — multi-turn tool-calling scaffold with invalid-tool rewrites
- RLM-SWE — multi-turn SWE tool-calling against remote sandbox

Renderer-by-renderer: round-trip parity tests (`render` → `parse_response` returns the original messages) and token-level parity against `apply_chat_template` live in `packages/renderers/tests/`.

---

## 9. Resources

- **verifiers PR** — Renderers package + replace TITO client with Renderer client: [PrimeIntellect-ai/verifiers#1068](https://github.com/PrimeIntellect-ai/verifiers/pull/1068)
- **prime-rl PR** — switch RL trainer to renderers: [PrimeIntellect-ai/prime-rl#2278](https://github.com/PrimeIntellect-ai/prime-rl/pull/2278)
20 changes: 20 additions & 0 deletions packages/renderers/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "renderers"
version = "0.1.0"
description = "Chat template renderers — deterministic message-to-token conversion for LLM training"
readme = "README.md"
requires-python = ">=3.10,<3.14"
dependencies = [
"transformers>=4.50.0",
# Used by GptOssRenderer to render and parse harmony tokens. Vendoring
# OpenAI's reference implementation keeps us byte-identical with vLLM
# (which also uses it) and saves us mirroring a 330-line Jinja template.
"openai-harmony>=0.0.8",
]

[tool.hatch.build.targets.wheel]
packages = ["renderers"]
Loading
Loading