---
title: "Chat Templates: An End to the Silent Performance Killer"
description: "Chat models are trained with incompatible formats for flattening role/content message lists into a single string, and feeding a model a different format than it was trained on causes severe but silent performance degradation."
url: "https://swe.quest/articles/chat-templates-an-end-to-the-silent-performance-killer-56e4408eee347f2d"
canonical: "https://huggingface.co/blog/chat-templates"
source: "Hugging Face"
published: "2023-10-03"
difficulty: "medium"
kind: "Announcement"
reading_minutes: 9
tags: ["llms","python","inference","model-training"]
---

# Chat Templates: An End to the Silent Performance Killer

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2023-10-03, 9 min read, Announcement. Original: [https://huggingface.co/blog/chat-templates](https://huggingface.co/blog/chat-templates)

## Summary

Chat models are trained with incompatible formats for flattening role/content message lists into a single string, and feeding a model a different format than it was trained on causes severe but silent performance degradation. Hugging Face tokenizers now carry a \`chat\_template\` attribute holding a Jinja template that renders conversations into the model's exact training format, applied via \`tokenizer.apply\_chat\_template()\`. Jinja was chosen over a simpler per-role prefix/suffix scheme because it can express every known format. ChatML with \`\<|im\_start|\>\`/\`\<|im\_end|\>\` tokens is recommended for new models, and model owners should set explicit templates rather than relying on fragile class-level defaults kept only for backward compatibility.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [LLMs](https://swe.quest/tags/llms.md) (AI & ML)
- [Python](https://swe.quest/tags/python.md) (Languages)
- [Inference & serving](https://swe.quest/tags/inference.md) (AI & ML)
- [Model training](https://swe.quest/tags/model-training.md) (AI & ML)

## Prerequisites

- Hugging Face Transformers tokenizers
- chat LLM fine-tuning or inference ([easy posts on LLMs](https://swe.quest/tags/llms.md?difficulty=easy))

## Keywords

Hugging Face Transformers, chat\_template, Jinja, ChatML, apply\_chat\_template, ConversationPipeline

## Related posts

- [Tool Use, Unified](https://swe.quest/articles/tool-use-unified-117f148d6f2c2374.md): Hugging Face · 2024-08-12 · Medium · 11 min read · LLMs, AI agents, Python, API design
  Hugging Face Transformers extends Jinja chat templates to cover tool use, giving a single portable API for passing tools to Mistral, Cohere, NousResearch and Llama models.
- [The 4 Things Qwen-3’s Chat Template Teaches Us](https://swe.quest/articles/the-4-things-qwen-3-s-chat-template-teaches-us-670fadf25c8ae311.md): Hugging Face · 2025-04-30 · Medium · 4 min read · LLMs, AI agents
  Qwen-3's Jinja chat template differs from Qwen-2.5 and QwQ in four ways.
- [From OpenAI to Open LLMs with Messages API on Hugging Face](https://swe.quest/articles/from-openai-to-open-llms-with-messages-api-on-hugging-face-98058f09a7d2acc1.md): Hugging Face · 2024-02-08 · Medium · 7 min read · Inference & serving, LLMs, API design, RAG & retrieval
  Text Generation Inference 1.4.0 adds a Messages API compatible with OpenAI's Chat Completion API, so open LLMs on Inference Endpoints can be called from existing OpenAI client code by changing the base URL and token.
- [Hosting your Models and Datasets on Hugging Face Spaces using Streamlit](https://swe.quest/articles/hosting-your-models-and-datasets-on-hugging-face-spaces-using-streamlit-a8983f0b0bfbdd51.md): Hugging Face · 2021-10-05 · Medium · 3 min read · Python, Machine learning, Deployment
  Streamlit apps can showcase Hugging Face models and datasets and be hosted on Hugging Face Spaces.
- [Hugging Face x LangChain : A new partner package](https://swe.quest/articles/hugging-face-x-langchain-a-new-partner-package-4a05b92542fbd2d8.md): Hugging Face · 2024-05-14 · Medium · 4 min read · LLMs, Python, Inference & serving, RAG & retrieval
  langchain-huggingface is a new Python partner package jointly maintained by Hugging Face and LangChain, replacing community-written integrations that had drifted out of date.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
