From 6c514ab0257e9d153b5795bfa341f64c89584d32 Mon Sep 17 00:00:00 2001 From: Mohammad Miadh Angkad <176301910+mmangkad@users.noreply.github.com> Date: Tue, 15 Sep 2026 13:16:26 +0800 Subject: [PATCH] Force reasoning mode for GLM-5.3 chat templates (#39227) Co-authored-by: Brayden Zhong Co-authored-by: Mohammad Angkad Co-authored-by: Xinyuan Tong Co-authored-by: Xinyuan Tong <115166877+JustinTong0323@users.noreply.github.com> --- python/sglang/srt/parser/template_detection.py | 7 +++++++ test/registered/unit/parser/test_template_manager.py | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/python/sglang/srt/parser/template_detection.py b/python/sglang/srt/parser/template_detection.py index 9dda09563..a662492f0 100644 --- a/python/sglang/srt/parser/template_detection.py +++ b/python/sglang/srt/parser/template_detection.py @@ -168,6 +168,13 @@ REASONING_MODE_RULES = ( and not ctx.has_text("thinking") ), ), + DetectionRule( + name="glm53_always_think", + value=ReasoningToggleConfig(special_case="always"), + # GLM-5.3's generation prompt opens , so the output carries no + # opening tag; lambda because _is_glm53 is defined below. + predicate=lambda ctx: _is_glm53(ctx), + ), DetectionRule( name="mistral_reasoning_effort", value=ReasoningToggleConfig(special_case="mistral"), diff --git a/test/registered/unit/parser/test_template_manager.py b/test/registered/unit/parser/test_template_manager.py index 39d844e41..1d1da64fa 100644 --- a/test/registered/unit/parser/test_template_manager.py +++ b/test/registered/unit/parser/test_template_manager.py @@ -116,6 +116,13 @@ class TestTemplateManagerReasoningDetection(unittest.TestCase): "glm47", ) + def test_glm53_effort_template_forces_reasoning(self): + vocab = ["", "", "", "<|user|>", "<|endoftext|>"] + force, config, _ = self._detect(_glm53_template("+"), vocab) + + self.assertTrue(force) + self.assertEqual(config, ReasoningToggleConfig(special_case="always")) + def test_interns1_detects_enable_thinking_default_true(self): template = """ {% set default_thinking_sys %}......{% endset %}