Skip to content

Kyojin: open-source engine that runs 100 GB-class open models (GLM-5.3, Qwen3.8, DeepSeek V4.1) on one desktop machine. AMD Strix Halo, NVIDIA RTX and Apple Mac. OpenAI API, built on ExLlamaV3.

Effort lines move to the tail of the prompt in the Qwen and GLM templates, so changing the reasoning effort keeps the cached prefix (live gate: GLM 30K medium->high recomputes 23 tokens, Qwen3.8 27B 1414 of 30086 with the chunk-aligned cache; 20/20 greedy answers identical to the head layout). effort_placement='head' restores the old layout.

YanissAmz9d3052fbcd45
diff --git a/tools/lanes/assets/glm53-template-medium.jinja b/tools/lanes/assets/glm53-template-medium.jinja
index 3771099..dd545c3 100644
--- a/tools/lanes/assets/glm53-template-medium.jinja
+++ b/tools/lanes/assets/glm53-template-medium.jinja
@@ -1,8 +1,12 @@
[gMASK]<sop>
{%- set glm_medium = (reasoning_effort is defined and reasoning_effort == 'medium') -%}
{%- set effective_reasoning_effort = 'high' if glm_medium else (reasoning_effort if reasoning_effort is defined and reasoning_effort in ['low', 'high'] else 'max') -%}
+{#- Effort lines go at the TAIL (just before <|assistant|>) so a change of effort never invalidates the cached prefix; effort_placement='head' restores the old layout. -#}
+{%- set effort_head = (effort_placement is defined and effort_placement == 'head') -%}
+{%- if effort_head -%}
{%- if effective_reasoning_effort is not none -%}<|system|>Reasoning Effort: {{ effective_reasoning_effort | capitalize }}{%- endif -%}
{%- if glm_medium -%}<|system|>Match the depth of your work to the difficulty of the task: spend it on the points that decide the answer, not on alternatives the task does not call for. Plan in your reasoning, but do not draft the answer there: write code and long text once, in the answer. When you have settled a point, keep it and move on.{%- endif -%}
+{%- endif -%}
{%- set clear_thinking = clear_thinking if clear_thinking is defined else false -%}
{%- if tools -%}
{%- macro tool_to_json(tool) -%}
@@ -259,5 +263,9 @@ For each function call, output the function name and arguments within the follow
{%- endif -%}
{%- endfor -%}
{%- if add_generation_prompt -%}
+{%- if not effort_head -%}
+{%- if effective_reasoning_effort is not none -%}<|system|>Reasoning Effort: {{ effective_reasoning_effort | capitalize }}{%- endif -%}
+{%- if glm_medium -%}<|system|>Match the depth of your work to the difficulty of the task: spend it on the points that decide the answer, not on alternatives the task does not call for. Plan in your reasoning, but do not draft the answer there: write code and long text once, in the answer. When you have settled a point, keep it and move on.{%- endif -%}
+{%- endif -%}
<|assistant|>{{- '<think>' -}}
{%- endif -%}
diff --git a/tools/qwen/chat_template.jinja b/tools/qwen/chat_template.jinja
index 7f4327c..40a58cb 100644
--- a/tools/qwen/chat_template.jinja
+++ b/tools/qwen/chat_template.jinja
@@ -56,6 +56,12 @@
{%- set reasoning_instructions = 'Reasoning effort is set to low. Keep your thinking brief and focused, moving directly to the conclusion without unnecessary elaboration.' %}
{%- endif %}
{%- endif %}
+{#- Effort text goes at the TAIL (just before the generation header) so that changing the effort never invalidates the cached prefix. effort_placement='head' restores the old layout. -#}
+{%- set effort_tail = '' %}
+{%- if reasoning_instructions and (effort_placement is not defined or effort_placement != 'head') %}
+ {%- set effort_tail = reasoning_instructions %}
+ {%- set reasoning_instructions = '' %}
+{%- endif %}
{%- if tools and tools is iterable and tools is not mapping %}
{{- '<|im_start|>system\n' }}
{%- if reasoning_instructions %}
@@ -163,6 +169,9 @@
{%- endif %}
{%- endfor %}
{%- if add_generation_prompt %}
+ {%- if effort_tail %}
+ {{- '<|im_start|>system\n' + effort_tail + '<|im_end|>\n' }}
+ {%- endif %}
{{- '<|im_start|>assistant\n' }}
{%- if enable_thinking is defined and enable_thinking is false %}
{{- '<think>\n\n</think>\n\n' }}