From: Sigbjørn Skjæret Date: Sat, 21 Jun 2025 05:33:21 +0000 (+0200) Subject: gguf-py : fix TemplateProcessing pair when bos/eos is missing (#14312) X-Git-Tag: upstream/0.0.5760~30 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=58cba76a9aab728717509d62b67c13afd8dc227a;p=pkg%2Fggml%2Fsources%2Fllama.cpp gguf-py : fix TemplateProcessing pair when bos/eos is missing (#14312) --- diff --git a/gguf-py/gguf/vocab.py b/gguf-py/gguf/vocab.py index 6c4d3a42..a792d56f 100644 --- a/gguf-py/gguf/vocab.py +++ b/gguf-py/gguf/vocab.py @@ -201,9 +201,9 @@ class SpecialVocab: if special_last != special_eos: logger.warning(f'Unknown trailing special token {special_last!r} in TemplateProcessing') if tmpl_pair: - seq_start = 1 if tmpl_pair[0].get('SpecialToken', {}).get('id') == special_first else 0 - seq_stop = -1 if tmpl_pair[-1].get('SpecialToken', {}).get('id') == special_last else None - if seq_start == 0 or seq_stop is None: + seq_start = 1 if special_first and tmpl_pair[0].get('SpecialToken', {}).get('id') == special_first else 0 + seq_stop = -1 if special_last and tmpl_pair[-1].get('SpecialToken', {}).get('id') == special_last else None + if (special_first and seq_start == 0) or (special_last and seq_stop is None): logger.warning('TemplateProcessing leading/trailing special tokens do not match TemplateProcessing') if tmpl_pair := tmpl_pair[slice(seq_start, seq_stop)]: tmpl_a = tmpl_pair[0].get('Sequence', {}).get('id')