glm53_reasoning_always_parsed.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env python3
  2. """Always split reasoning from content, whatever the thinking kwargs say.
  3. GLM-5.3-Flash was trained to think on every turn; its official template has no
  4. non-thinking mode. Our template therefore maps `thinking: false` /
  5. `enable_thinking: false` to `Reasoning Effort: Low` and still opens `<think>`
  6. (the empty `<think></think>` we used before is out of distribution and breaks
  7. long structured output). The model now always emits a short reasoning block.
  8. Stock glm47_moe drops its <think> terminals and starts in CONTENT when either
  9. kwarg is false, so that reasoning would land in `content`. This makes the
  10. parser track <think> on every request: thinking off returns a short `reasoning`
  11. and a clean `content`.
  12. Same contract as the other patchers: one anchor, exactly once, or the build
  13. fails.
  14. """
  15. from pathlib import Path
  16. PATH = Path("/usr/local/lib/python3.12/dist-packages/vllm/parser/glm47_moe.py")
  17. OLD = """ self.thinking_enabled = (
  18. True
  19. if thinking is None and enable_thinking is None
  20. else bool(thinking) or bool(enable_thinking)
  21. )
  22. """
  23. NEW = """ # GLM53-REASONING-ALWAYS: the template always opens <think> (thinking
  24. # off means low effort), so the parser must always track it.
  25. del thinking, enable_thinking
  26. self.thinking_enabled = True
  27. """
  28. text = PATH.read_text()
  29. if text.count(NEW) == 1 and text.count(OLD) == 0:
  30. print("[reasoning-always] already patched")
  31. else:
  32. assert text.count(OLD) == 1, f"[reasoning-always] anchor matched {text.count(OLD)} times; stock tree changed"
  33. PATH.write_text(text.replace(OLD, NEW))
  34. print("[reasoning-always] glm47_moe always parses <think>")