From ecd16d6bf9f680ba5b25eb837bf61569dde81886 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Tue, 5 Aug 2025 12:57:49 -0700 Subject: [PATCH] Automatically set skip_special_tokens to False for channel-based templates --- modules/chat.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/modules/chat.py b/modules/chat.py index f929f653..46d24a6f 100644 --- a/modules/chat.py +++ b/modules/chat.py @@ -770,6 +770,16 @@ def chatbot_wrapper(text, state, regenerate=False, _continue=False, loading_mess output = apply_extensions('history', output) state = apply_extensions('state', state) + # Automatically set skip_special_tokens to False for channel-based templates + if state['mode'] in ['instruct', 'chat-instruct']: + template_str = state['instruction_template_str'] + else: # chat mode + template_str = state['chat_template_str'] + + handler = create_template_handler(template_str) + if isinstance(handler, ChannelTemplateHandler): + state['skip_special_tokens'] = False + # Let the jinja2 template handle the BOS token if state['mode'] in ['instruct', 'chat-instruct']: state['add_bos_token'] = False