From cc78da97c0c7596dc821595f21b5644bbdc77df3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sigbj=C3=B8rn=20Skj=C3=A6ret?= Date: Thu, 5 Nov 2026 13:04:48 +0100 Subject: [PATCH] gguf-py : external chat templates have precedence over tokenizer_config (#31717) --- gguf-py/gguf/vocab.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/gguf-py/gguf/vocab.py b/gguf-py/gguf/vocab.py index d299cfd00..e49a357df 100644 --- a/gguf-py/gguf/vocab.py +++ b/gguf-py/gguf/vocab.py @@ -352,21 +352,20 @@ class SpecialVocab: continue if not tokenizer_config: return True - chat_template_alt = None + chat_template = tokenizer_config.get('chat_template') chat_template_json = path / 'chat_template.json' chat_template_jinja = path / 'chat_template.jinja' if chat_template_jinja.is_file(): with open(chat_template_jinja, encoding = 'utf-8') as f: - chat_template_alt = f.read() + chat_template = f.read() if additional_templates := list((path / 'additional_chat_templates').glob('*.jinja')): - chat_template_alt = [{'name': 'default', 'template': chat_template_alt}] + chat_template = [{'name': 'default', 'template': chat_template}] for template_path in additional_templates: with open(template_path, encoding = 'utf-8') as fp: - chat_template_alt.append({'name': template_path.stem, 'template': fp.read()}) + chat_template.append({'name': template_path.stem, 'template': fp.read()}) elif chat_template_json.is_file(): with open(chat_template_json, encoding = 'utf-8') as f: - chat_template_alt = json.load(f).get('chat_template') - chat_template = tokenizer_config.get('chat_template', chat_template_alt) + chat_template = json.load(f).get('chat_template') if chat_template is None or isinstance(chat_template, (str, list)): self.chat_template = chat_template else: