Senior · Core path · 7 chapters
Base vs instruct vs reasoning vs multimodal variants
Chat templates and special tokens
A model can appear healthy while the wrong serialization or variant quietly wastes tokens and destroys task quality.
What you will know
Run the same task through base, instruct, reasoning, and multimodal variants and compare the outputs and token usage
Base models may continue the prompt, reasoning variants may spend substantially more generation budget, and multimodal variants require the expected input path.
Render a multi-turn conversation with the model tokenizer's chat template and inspect the resulting text, token IDs, and generation prompt
BOS or EOS markers, role separators, and assistant-start tokens determine what the model treats as context versus a turn boundary.
Identify special tokens in a raw prompt string
A token that looks like ordinary markup can control role boundaries, stopping behavior, or loss masking.
Reproduce a quality failure by sending a conversation with the wrong or missing template, then patch it and verify the improvement on a fixed test set
The broken version often remains fluent but becomes off-task, so a small exact-match or task-success comparison is more revealing than subjective inspection.
Choose the right variant for a task and justify it
The decision should account for modality support, measured quality, latency, context and output-token budgets, and whether extra reasoning is worth its cost.
Chapters
- 1
Base, instruct, reasoning and multimodal variants
Base, instruct, reasoning and multimodal are four checkpoints published from one pretraining run and finished by different later stages of training. This chapter sends one structured-output task to all four, reads the outputs alongside the token counts, and explains why a base checkpoint continues the prompt, why a reasoning variant bills hundreds of tokens you never see, and why a multimodal one only reads an image that arrived through its content-part path.
- 2
Chat templates and the generation prompt
Every instruct checkpoint ships a chat template: executable Jinja, stored beside the tokenizer, that turns a list of message objects into one flat string of tokens. This chapter renders one, reads the token IDs it produces, explains what the BOS marker, the role headers, the end-of-turn token and the trailing generation prompt each do, and measures what a hand-rolled serialisation costs on a fixed set of support conversations.
- 3
Server-side and client-side templating
A chat endpoint applies the model's chat template server-side from the messages you post; a completion endpoint applies nothing and forwards your string as-is; and a client library or serving wrapper in between may apply it again on top of text that already carries markers. This chapter works out which layer owns the rendering on each path, shows what a doubly-templated request looks like token by token, and covers the three situations where taking ownership of the bytes is the right call.
- 4
Special tokens in untrusted input
A tokenizer matches its reserved marker strings anywhere in the text it is given, including inside a support ticket, a retrieved document or another model's output. This chapter dumps the real marker set for a checkpoint, shows the one keyword argument that separates a quotation from a control instruction, and builds an ingestion-boundary control that does not depend on enumerating literals.
- 5
Diffing token IDs across code paths
When one code path produces good output and another produces bad output from the same weights, the authoritative comparison is the integers each path sends the engine, not the prompt you think you sent. This chapter builds that diff against a serving stack's tokenize route, gives the fallbacks for stacks and hosted APIs that will not show you integers, maps the shape of a divergence onto its cause, and confirms the fix on a fixed labelled set.
- 6
Few-shot prompting for base models
A base checkpoint completes documents, so a prompt written for it has to be a document that is obviously unfinished where the answer goes. This chapter covers the few-shot completion form that makes a base model work, the stop sequences it needs, the break-even arithmetic between a cheap per-token rate and a fixed few-shot prefix, how many examples to use and which ones, and the capabilities that post-training supplies and few-shot prompting cannot.
- 7
Variant selection and tail latency
A reasoning variant generates its intermediate work before it emits anything visible, so latency is a disqualifier rather than an optimisation to defer, and its length is data-dependent with a long right tail. This chapter builds the eighty-line harness that measures quality, tail latency and output-token spend per candidate on your own task, lays out the six dimensions a variant decision has, and works out when routing between two variants can satisfy a p95 budget.
External resources
- Chat templates (Transformers docs)huggingface.co
The canonical spec for how messages become tokens per model family.
- Advanced Usage and Customizing Your Chat Templateshuggingface.co
Write and debug your own Jinja template and control tokens.
- Getting Started with Chat Templates for Text LLMshuggingface.co
Why base and instruct checkpoints need different prompt formats.
- LLaMA2 Tokenizer and Prompt TricksSam Witteveen
Shows the raw [INST] special-token format an instruct model expects.
- Llama 3.1 Conversational Chat Template for Finetuning using Unsloth & Deployment to Open WebUIAPC Mastery Path
Applying a chat template end to end for training and serving.