skillfed

renderers

Chat template renderers — deterministic message-to-token conversion for LLM training

renderers v0.1.9 477.6K downloads/30d#6,442 on PyPI
Permissive license Apache-2.0 Active released

What it is and what it does

Renderers is a library for deterministic conversion between chat messages and token IDs, designed to preserve token identity across multi-turn LLM conversations. It wraps model-specific chat templates as Python objects that can render messages to token IDs, parse model-generated token sequences back into structured responses (including tool calls and reasoning content), and extend conversations without re-rendering prior history. The core problem it solves is token drift—when inference engines apply templates, parse outputs, and re-render full history each turn, subtle differences in whitespace, BPE boundaries, and boolean formatting accumulate, causing training samples to diverge from what the model actually saw.

The library ships hand-coded renderers for popular models (Qwen, GLM, DeepSeek, Llama, Nemotron, and others) and falls back to a generic wrapper for unknown architectures. Its key contract is `bridge_to_next_turn`, which extends a conversation by appending new messages to the previous prompt and completion token streams without re-rendering, proving byte-for-byte identity. This is critical for RL training, where the trainer must see exact token sequences the sampler produced. Dependencies include jinja2, numpy, openai, tiktoken, transformers, and two proprietary packages (openai-harmony, prime-pydantic-config).

Use it for:

  • RL training pipelines where token identity between sampler and trainer must be preserved across multi-turn rollouts
  • Building deterministic chat interfaces that parse tool calls and reasoning tokens without re-rendering history
  • Extending conversations in inference systems (transformers, vLLM, SGLang) while maintaining token alignment with training
  • Testing and debugging chat template behavior by inspecting token-to-message attribution and round-trip consistency
  • Pooling tokenizer instances across concurrent rendering tasks to amortize model loading overhead

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Converts chat messages to token IDs for LLM inference and training, with deterministic parsing of model responses and multi-turn conversation extension that preserves token identity across turns.

Yes, if you are building RL training systems or multi-turn inference pipelines where token identity matters. The library solves a real problem—token drift from re-rendering—with empirical evidence (64 vs 77 training samples from 64 rollouts on a benchmark). Install friction is low. The main caveat is dependency on two proprietary packages (openai-harmony, prime-pydantic-config) whose availability and licensing should be verified before committing to the stack.

Install

renderers on PyPI

pip

pip install renderers

uv

uv add renderers

poetry

poetry add renderers

Installing renderers

Before you install

Low friction: pure Python wheel with no compiled dependencies. Active maintenance—released 7 days ago. Depends on jinja2, numpy, openai, tiktoken, transformers, and two proprietary packages (openai-harmony, prime-pydantic-config), which may add friction if those are unavailable or require authentication.

License in practice

Apache-2.0 permissive license allows commercial and private use with minimal restrictions, making it suitable for both open-source and proprietary LLM training pipelines.

Quickstart

from transformers import AutoTokenizer
from renderers import create_renderer

tok = AutoTokenizer.from_pretrained("Qwen/Qwen3-8B")
r = create_renderer(tok)
prompt_ids = r.render_ids([{"role": "user", "content": "hi"}], add_generation_prompt=True)
parsed = r.parse_response(completion_ids)

Requires Python 3.10 or later. Tokenizer model must be available locally or via HuggingFace; transformers will attempt to download it on first use.

Verify before relying

  • Whether openai-harmony and prime-pydantic-config are publicly available on PyPI or require internal/proprietary access
  • Performance overhead of renderer instantiation and token-id conversion on typical batch sizes
  • Compatibility with inference engines beyond transformers (vLLM, SGLang, Tinker) in practice

Package facts

License Apache-2.0 (permissive)
Python support supports the current Python release (<3.14,>=3.10)
Install friction low — pure-Python wheel
Runtime dependencies 7 — jinja2, numpy, openai-harmony, openai, prime-pydantic-config, tiktoken, transformers
Maintenance actively maintained — 7 days since the last release
First released
Downloads 477,643/month — #6,442 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: renderers-0.1.9-py3-none-any.whl

Tags

chat template renderermessage to token conversionllm chat formattingtoken-preserving conversation bridgedeterministic prompt encodingmodel-agnostic chat templaterl training token alignment
llm-trainingtoken-alignmentchat-templates

More Artificial Intelligence packages

Further reading