Repository navigation
Add optional C++ rendering for HF chat templates - #222
Open
eoinjordan wants to merge 1 commit into
Open
eoinjordan wants to merge 1 commit into
eoinjordan wants to merge 1 commit into
Conversation
eoinjordan
marked this pull request as ready for review
October 2, 2026 21:15
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I've been using Kotlin for the application logic in some Android examples, and had a go at #131 while working on a small VLM example.
This is a first pass at loading the model's HF chat template in C++, so runners can build the prompt from the model files. It handles
add_generation_promptand kwargs likeenable_thinking.I used a pinned Minja dependency behind
TOKENIZERS_BUILD_CHAT_TEMPLATE, which is off by default. It loads standalone Jinja, legacy tokenizer/processor config and explicitly selected named templates. There's a small command-line example and an exportedtokenizers::chat_templatetarget. The CI test builds enable the option so the new tests run.I checked 30 cases against Transformers using pinned Qwen3 and SmolVLM templates, including Unicode, conversation history, image blocks, generation prompts and thinking options. All 16 Ubuntu test targets passed, including 14 renderer tests. A separate installed-library consumer passed the same 30 cases. The Android arm64 build passed with NDK r26c, and I ran the validation script on my Razr 50 Ultra: all 30 exact prompt comparisons passed there too.
Runner and Java/JNI integration would be the next step. Minja supports a subset of Jinja, and the added
capitalizefilter handles ASCII roles; unsupported Unicode case conversion returns an error. The example documents those limits.Also checked the default-off build configuration, repository formatting/CMake/newline lint and
git diff --check.Related to #131.