--- id: renderers version: "0.1.9" license: Apache-2.0 license_treatment: permissive maintenance: active --- # renderers — Chat template renderers — deterministic message-to-token conversion for LLM training License: permissive · Maintenance: active · Downloads: 477.6K/mo ## 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 above — 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 pip install renderers uv add renderers 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_current - Install friction: low - Maintenance: active - Downloads: 477.6K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags chat template renderer, message to token conversion, llm chat formatting, token-preserving conversation bridge, deterministic prompt encoding, model-agnostic chat template, rl training token alignment, llm-training, token-alignment, chat-templates [View on SkillFed](https://skillfed.io/packages/renderers) · [View on PyPI](https://pypi.org/project/renderers/)