EvSys

templates

Chat-template helpers - thin wrappers over tokenizer.apply_chat_template.

We deliberately do NOT reproduce tinker_cookbook's Renderer class hierarchy

  • Hugging Face's tokenizers already implement the template via apply_chat_template, and the cookbook's Renderer subclasses just wrap that call with per-model defaults (enable_thinking=False for Qwen3.5-disable variants, etc.). We forward the kwarg directly when set, which keeps every HF chat-template-aware tokenizer working uniformly.

The functions here return tinker.ModelInput so they're drop-in for any sampling / forward call.

attributeMessage
= dict[str, Any]

Role-tagged chat message - \{"role": "system" | "user" | "assistant", "content": "..."\}. Matches the HF apply_chat_template input shape.

attribute__all__
= ['Message', 'apply_template', 'messages_to_model_input', 'text_to_model_input']
funcapply_template(tokenizer, messages, *, add_generation_prompt, enable_thinking=None) -> str

Call apply_chat_template with enable_thinking forwarded only when explicitly set.

Why the gate: Qwen3.5 tokenizers accept enable_thinking, but most others do NOT and raise on the unknown kwarg. Forwarding only when set keeps the helper tokenizer-agnostic - same approach already in ChatTemplatedInference (inference/chat_templated.py).

paramtokenizerAny
parammessagesSequence[Message]
paramadd_generation_promptbool
paramenable_thinkingbool | None
= None

Returns

str
funcmessages_to_model_input(tokenizer, messages, *, add_generation_prompt=True, enable_thinking=None) -> tinker.ModelInput

Apply chat template → encode → build tinker.ModelInput.

Use add_generation_prompt=True for sampling prompts (the assistant turn isn't included yet; the model writes it). False when building a completed sequence (e.g. SFT teacher-forcing).

paramtokenizerAny
parammessagesSequence[Message]
paramadd_generation_promptbool
= True
paramenable_thinkingbool | None
= None

Returns

tinker.tinker.ModelInput
functext_to_model_input(tokenizer, text) -> tinker.ModelInput

Bypass chat-templating; tokenize text verbatim. For callers that already have a fully rendered prompt string.

paramtokenizerAny
paramtextstr

Returns

tinker.tinker.ModelInput