Sponsored byOutsenseAI that finds your next clients
SponsorGROUOutbound, LinkedIn content and leads for B2B teamsSponsorOutsenseAI that finds your next clientsAd+Your tool hereSeen by people installing AI tools@Weekly picksThe best new tools, one email a week

add-chat-template

Skill by InternLM

Adds or audits an XTuner chat-template implementation and its loss mask for a Hugging Face or local model. Built for developers supporting new models in XTuner's message and tokenizer code.

  • Score 85
  • 5.2k stars
  • Apache-2.0
  • Updated
Works withClaude CodeClaude apps Antigravity CLI

Install add-chat-template

Built from the published package, never by AI.

git clone --depth 1 https://github.com/InternLM/xtuner /tmp/xtuner && mkdir -p ~/.claude/skills && cp -r /tmp/xtuner/.claude/skills/add-chat-template ~/.claude/skills/add-chat-template

Run in your terminal. Claude Code loads skills from ~/.claude/skills automatically.

Step-by-step: install add-chat-template in Claude Code

Skills can run scripts on your machine. Some need an API key: check the README.

About

The add-chat-template skill guides work on XTuner chat-template implementations and their loss masks. It treats the official Hugging Face tokenizer or processor as the rendering oracle. The assistant is told to inventory the model's artifacts, run a bundled audit script, and write a stop contract before implementing. The workflow covers rendering parity, loss on assistant output and stop tokens, regression tests, and checks against vLLM and SGLang.

It is aimed at developers who add a new model under xtuner/v1/data_proto/messages or check an existing implementation against apply_chat_template. The skill says not to infer a template or stop contract from another model in the same family. It also says to pin the reference revision of the model repository in tests or CI.

Written from the project's SKILL.md and checked against it.

What it can do

  • Reference inventoryRecords the official repo or local directory, revision, tokenizer class, and template kwargs before coding.
  • Chat template auditRuns a bundled script that inventories a model's tokenizer-side chat template.
  • Stop contract tableLists configured stops, template boundaries, and engine stops for each transition.
  • Loss mask designSets which assistant output, reasoning, tool calls, and stop tokens receive loss.
  • Integration guidanceShows which XTuner seams to update when registering a new chat template.
  • Regression test matrixLists test cases for turns, tools, reasoning, system input, and Unicode alignment.
  • Engine validationCompares vLLM and SGLang rendering and stop behavior with the official renderer.

What you need

  • Access to the official Hugging Face model repository or a local model directory
  • Python to run the bundled audit script
  • The XTuner repository with its tests and message code
  • Transformers and the tokenizer or processor for the target model
  • vLLM and SGLang at the target versions for engine validation

Try asking

  • Add a chat template for this new Hugging Face model in XTuner with the right loss mask.
  • Audit our existing XTuner chat template against the official apply_chat_template output.
  • Write a stop contract table for this model's assistant, user, and tool transitions.

Good to know

  • Does not infer a template or stop contract from another model in the same family.
  • Validation against vLLM and SGLang depends on installing those engines at the target versions.
  • Focused on XTuner's message and tokenizer code rather than general chat template work.

Security check

A

No download-and-run commands, hidden instructions or signs of sending keys out were found.

Checked automatically: .claude/skills/add-chat-template/SKILL.md, .claude/skills/add-chat-template/scripts/audit_hf_chat_template.py. This looks for known risky patterns and is not a full audit. How grades work

Inside the skill

  • SKILL.md13 KB
  • agents/openai.yaml272 B
  • scripts/audit_hf_chat_template.py8 KB

Alternatives to add-chat-template

All alternatives →

Compare with agent-reproduce-align, google_contacts or m06-error-handling

add-chat-template: common questions

What does the add-chat-template skill do?

It helps add or audit an XTuner chat-template implementation and its loss mask. It uses the official Hugging Face tokenizer or processor as the reference for rendering.

How does it decide which tokens get loss?

It inventories configured generation stops, template boundaries, and engine stops before writing the mask. Assistant output receives loss by default, while user, tool, system, and generation prompt content stays masked.

Who is this skill for?

It is for developers supporting a new model in XTuner or checking an existing implementation. The source describes it for work under xtuner/v1/data_proto/messages and related tests.

How do I install add-chat-template?

Run the command above to copy the skill into ~/.claude/skills/. Claude Code picks it up automatically.

Is add-chat-template free?

The code is published under the Apache-2.0 licence. The service it connects to may have its own pricing.

Is add-chat-template safe to use?

It scores 85 of 100. Grades: maintenance A, licence A, quality A. Security check: grade A, no risky patterns found in the files checked. Review the code before you install. How grades work.

What are alternatives to add-chat-template?

Similar skills: agent-reproduce-align, google_contacts, m06-error-handling, caveman.

add-chat-template Install

Add to stack

Loading.