Skip to content

Commit 1045792

Browse files
justinchubyCopilot
andauthored
fix: copy chat_template.jinja to ORT GenAI export folder (#198)
The `--runtime ort-genai` export copies tokenizer files to the output directory but was missing `chat_template.jinja`. ORT GenAI uses this file for chat formatting when present. Added `chat_template.jinja` to the file list in both `_copy_tokenizer_files()` (HF Hub download) and `_copy_tokenizer_files_from_local()` (local copy). Both paths already silently skip missing files, so models without a chat template are unaffected. --------- Signed-off-by: Justin Chu <justinchu@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f27118b commit 1045792

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

src/mobius/integrations/ort_genai/auto_export.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def _copy_tokenizer_files(
8888
"added_tokens.json",
8989
"merges.txt", # BPE
9090
"vocab.json", # BPE
91+
"chat_template.jinja", # Chat template for ORT GenAI
9192
]
9293
copied: list[str] = []
9394
for filename in tokenizer_files:
@@ -127,6 +128,7 @@ def _copy_tokenizer_files_from_local(
127128
"added_tokens.json",
128129
"merges.txt", # BPE
129130
"vocab.json", # BPE
131+
"chat_template.jinja", # Chat template for ORT GenAI
130132
]
131133
copied: list[str] = []
132134
for filename in tokenizer_files:

src/mobius/integrations/ort_genai/auto_export_test.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def test_copies_available_files(self, tmp_path):
6363
fake_src = tmp_path / "src"
6464
fake_src.mkdir()
6565
(fake_src / "tokenizer.json").write_text('{"test": true}')
66+
(fake_src / "chat_template.jinja").write_text("{{ messages }}")
6667

6768
with mock.patch("huggingface_hub.hf_hub_download") as mock_dl:
6869
mock_dl.side_effect = lambda model_id, filename: (
@@ -77,6 +78,8 @@ def test_copies_available_files(self, tmp_path):
7778

7879
assert "tokenizer.json" in copied
7980
assert (dst / "tokenizer.json").exists()
81+
assert "chat_template.jinja" in copied
82+
assert (dst / "chat_template.jinja").exists()
8083

8184

8285
class TestCopyTokenizerFilesFromLocal:
@@ -88,14 +91,19 @@ def test_copies_present_files(self, tmp_path):
8891
src.mkdir()
8992
(src / "tokenizer.json").write_text('{"test": true}')
9093
(src / "tokenizer_config.json").write_text('{"model_type": "llama"}')
94+
(src / "chat_template.jinja").write_text("{{ messages }}")
9195

9296
dst = tmp_path / "output"
9397
dst.mkdir()
9498
copied = _copy_tokenizer_files_from_local(str(src), str(dst))
9599

96-
assert set(copied) == {"tokenizer.json", "tokenizer_config.json"}
100+
assert set(copied) == {
101+
"tokenizer.json",
102+
"tokenizer_config.json",
103+
"chat_template.jinja",
104+
}
97105
assert (dst / "tokenizer.json").read_text() == '{"test": true}'
98-
assert (dst / "tokenizer_config.json").read_text() == '{"model_type": "llama"}'
106+
assert (dst / "chat_template.jinja").read_text() == "{{ messages }}"
99107

100108
def test_skips_absent_files(self, tmp_path):
101109
"""Files not present in the source directory are silently skipped."""

0 commit comments

Comments
 (0)