From c2137eacc319932933420a92a13dd4660396282e Mon Sep 17 00:00:00 2001 From: lishanhao Date: Thu, 28 May 2026 18:33:43 +0800 Subject: [PATCH] [bugfix] Gemma4 suffix: drop trailing newline so assistant doesn't learn it The base template's `_add_dynamic_eos` reopens supervision on tokens matching `suffix_tokens_id` after each response. With `suffix = ['\n']`, both `` (106) and `\n` (107) get supervised, but `\n` belongs to the next user turn's prompt and the official IT model is never trained to predict it. Keep `chat_sep = ['\n']` so the multi-turn wire format is unchanged; only `suffix` is shortened to `['']`. Co-Authored-By: Claude Opus 4.6 --- swift/template/templates/gemma.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/swift/template/templates/gemma.py b/swift/template/templates/gemma.py index 8e4e8a10eb..f73ca8463a 100644 --- a/swift/template/templates/gemma.py +++ b/swift/template/templates/gemma.py @@ -341,7 +341,7 @@ class Gemma4TemplateMeta(TemplateMeta): prefix: Prompt = field(default_factory=lambda: ['']) prompt: Prompt = field(default_factory=lambda: ['<|turn>user\n{{QUERY}}\n<|turn>model\n']) chat_sep: Optional[Prompt] = field(default_factory=lambda: ['\n']) - suffix: Prompt = field(default_factory=lambda: ['\n']) + suffix: Prompt = field(default_factory=lambda: ['']) system_prefix: Optional[Prompt] = field(default_factory=lambda: ['<|turn>system\n{{SYSTEM}}\n'])