From 3e159a0a83ece341af656da2bc055c396c418cd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CWzw=E2=80=9D?= <15700181042@163.com> Date: Mon, 12 Aug 2024 19:22:12 +0800 Subject: [PATCH] fix Llama-template's system prompt bug Former-commit-id: bcbbf4506300fc132e68a39a9a6dfa5e61497c8b --- src/llamafactory/data/template.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/llamafactory/data/template.py b/src/llamafactory/data/template.py index 5d4b3011..ae78a319 100644 --- a/src/llamafactory/data/template.py +++ b/src/llamafactory/data/template.py @@ -320,7 +320,7 @@ def _get_jinja_template(template: "Template", tokenizer: "PreTrainedTokenizer") jinja_template += "{% for message in messages %}" jinja_template += "{% set content = message['content'] %}" if isinstance(template, Llama2Template): - jinja_template += "{% if loop.index0 == 0 and system_message is defined %}" + jinja_template += "{% if system_message is defined and (loop.index0 == 0 and messages[0]['role'] != 'system' or loop.index0 == 1 and messages[0]['role'] == 'system') %}" jinja_template += "{% set content = " + system_message + " + message['content'] %}" jinja_template += "{% endif %}"