Skip to content

feat(tokenizers): support loading a chat template from a file#4899

Open
omri-manolo wants to merge 2 commits into
NVIDIA-NeMo:mainfrom
omri-manolo:omri/tokenizer-chat-template-path
Open

feat(tokenizers): support loading a chat template from a file#4899
omri-manolo wants to merge 2 commits into
NVIDIA-NeMo:mainfrom
omri-manolo:omri/tokenizer-chat-template-path

Conversation

@omri-manolo

Copy link
Copy Markdown

What does this PR do ?

Adds an optional chat_template_path to TokenizerConfig — a path to a jinja template file (local or fsspec-readable URI) applied to the built tokenizer — so CLI/Hydra callers can swap chat templates per run without editing tokenizer_config.json inside the model checkpoint or embedding multi-line jinja strings in overrides.

Changelog

  • TokenizerConfig.chat_template_path: new optional field; mutually exclusive with the inline chat_template (setting both raises a clear configuration error).
  • _resolve_chat_template() in training/tokenizers/tokenizer.py: resolves the inline template or reads the template file; supports msc:// URIs when the Multi-Storage Client feature is enabled.
  • build_hf_tokenizer() applies the resolved template to the built tokenizer.
  • Tests (TestChatTemplatePathOverride): local-file resolution, inline passthrough, unset → None, inline+path mutual-exclusion error, msc:// resolution, and end-to-end through build_hf_tokenizer.

GitHub Actions CI

See the CI section in the Contributing doc for how to trigger the CI. A Nvidia developer will need to approve and trigger the CI for external contributors.

Before your PR is "Ready for review"

Pre checks:

  • Make sure you read and followed Contributor guidelines
  • Did you write any new necessary tests?
  • Did you add or update any necessary documentation? — chat template configuration is currently undocumented; happy to add a section (e.g. in data-preparation.md) if reviewers want it
  • Does the PR affect components that are optional to install? (Ex: Numba, Pynini, Apex etc) — no new dependencies; the msc:// path is behind the existing Multi-Storage Client feature flag
    • Reviewer: Does the PR have correct import guards for all optional libraries?

If you haven't finished some of the above items you can still open "Draft" PR.

Additional Information

Add an optional chat_template_path to the tokenizer config: a path to a
jinja template file (local or fsspec-readable URI) applied to the built
tokenizer. This lets CLI/Hydra callers swap chat templates per run without
editing tokenizer_config.json inside the model checkpoint or embedding
multi-line jinja strings in overrides.

Signed-off-by: Omri Manor <omrim@ai21.com>
@copy-pr-bot

copy-pr-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@yaoyu-33 yaoyu-33 added area:training Training loop, callbacks, and runtime integration feature New capabilities, enhancements, or enablement work needs-review PR is ready for code review and waiting on a reviewer ready-to-merge PR is approved, current, and only waiting for CI to pass before merge and removed needs-review PR is ready for code review and waiting on a reviewer labels Jul 16, 2026
@yaoyu-33

Copy link
Copy Markdown
Contributor

/ok to test 678536c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:training Training loop, callbacks, and runtime integration community-request feature New capabilities, enhancements, or enablement work ready-to-merge PR is approved, current, and only waiting for CI to pass before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature] TokenizerConfig.chat_template_path: load a chat template from a file

3 participants