[model] support GLM-4.7-Flash SFT (#10173)

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Shanay Mehta
2026-02-09 08:10:44 +05:30
committed by GitHub
parent 92fa3df4c4
commit ea644d04ec
3 changed files with 45 additions and 0 deletions

View File

@@ -459,6 +459,18 @@ class ReasoningTemplate(Template):
return [(encoded_messages[i], encoded_messages[i + 1]) for i in range(0, len(encoded_messages), 2)]
@dataclass
class Glm47ReasoningTemplate(ReasoningTemplate):
r"""GLM-4.7 uses only the closing </think> tag for empty thinking blocks."""
@override
def add_thought(self, content: str = "") -> str:
if not content:
return self.thought_words[1]
return self.thought_words[0] + content + self.thought_words[1]
TEMPLATES: dict[str, "Template"] = {}
@@ -1049,6 +1061,23 @@ register_template(
)
# copied from glm4_moe template
register_template(
name="glm4_7",
format_user=StringFormatter(slots=["<|user|>\n{{content}}<|assistant|>"]),
format_assistant=StringFormatter(slots=["\n{{content}}"]),
format_system=StringFormatter(slots=["<|system|>\n{{content}}"]),
format_function=FunctionFormatter(slots=["{{content}}"], tool_format="glm4_moe"),
format_observation=StringFormatter(slots=["<|observation|>\n{{content}}<|assistant|>"]),
format_tools=ToolFormatter(tool_format="glm4_moe"),
format_prefix=EmptyFormatter(slots=["[gMASK]<sop>"]),
stop_words=["<|user|>", "<|observation|>"],
thought_words=("<think>", "</think>"),
efficient_eos=True,
template_class=Glm47ReasoningTemplate,
)
# copied from glm4 template
register_template(
name="glmz1",