A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 15, 02:15 UTC
Fix DeepSeek-R1-0528 chat template (#20717)
Signed-off-by: Benjamin Merkel <benjamin.merkel@tngtech.com> Co-authored-by: Benjamin Merkel <benjamin.merkel@tngtech.com>
sfbemerk committed
Jul 10, 2025 at 19:47 UTC
251595368f90622eec4b4df8f81e1b9923bf11d1
1 file changed
+16
-16
examples/tool_chat_template_deepseekr1.jinja
+16
-16
@@ -11,7 +11,7 @@
11
{% set ns.system_prompt = ns.system_prompt + '\n\n' + message['content'] %}
12
{%- endif %}
13
{%- endif %}
14
-{%- endfor %}
14
+{%- endfor -%}
15
16
{#- Adapted from https://github.com/sgl-project/sglang/blob/main/examples/chat_template/tool_chat_template_deepseekr1.jinja #}
17
{% if tools is defined and tools is not none %}
@@ -27,8 +27,8 @@
27
{% set ns.system_prompt = ns.system_prompt + '\n\n' + tool_ns.text %}
28
{% endif %}
29
30
-{{ bos_token }}
31
-{{ ns.system_prompt }}
30
+{{- bos_token }}
31
+{{- ns.system_prompt }}
32
{%- for message in messages %}
33
{% set content = message['content'] %}
34
{%- if message['role'] == 'user' %}
@@ -45,7 +45,7 @@
45
{%- if message['role'] == 'assistant' and message['tool_calls'] is defined and message['tool_calls'] is not none %}
46
{%- set ns.is_last_user = false -%}
47
{%- if ns.is_tool %}
48
- {{'<|tool▁outputs▁end|>'}}
48
+ {{- '<|tool▁outputs▁end|>'}}
49
{%- endif %}
50
{%- set ns.is_first = false %}
51
{%- set ns.is_tool = false -%}
@@ -53,40 +53,40 @@
53
{%- for tool in message['tool_calls'] %}
54
{%- if not ns.is_first %}
55
{%- if content is none %}
56
- {{'<|tool▁calls▁begin|><|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\n' + '```json' + '\n' + tool['function']['arguments']|tojson + '\n' + '```' + '<|tool▁call▁end|>'}}
56
+ {{- '<|tool▁calls▁begin|><|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\n' + '```json' + '\n' + tool['function']['arguments']|tojson + '\n' + '```' + '<|tool▁call▁end|>'}}
57
{%- else %}
58
- {{content + '<|tool▁calls▁begin|><|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\n' + '```json' + '\n' + tool['function']['arguments']|tojson + '\n' + '```' + '<|tool▁call▁end|>'}}
58
+ {{- content + '<|tool▁calls▁begin|><|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\n' + '```json' + '\n' + tool['function']['arguments']|tojson + '\n' + '```' + '<|tool▁call▁end|>'}}
59
{%- endif %}
60
{%- set ns.is_first = true -%}
61
{%- else %}
62
- {{'\n' + '<|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\n' + '```json' + '\n' + tool['function']['arguments']|tojson + '\n' + '```' + '<|tool▁call▁end|>'}}
62
+ {{- '\n' + '<|tool▁call▁begin|>' + tool['type'] + '<|tool▁sep|>' + tool['function']['name'] + '\n' + '```json' + '\n' + tool['function']['arguments']|tojson + '\n' + '```' + '<|tool▁call▁end|>'}}
63
{%- endif %}
64
{%- endfor %}
65
- {{'<|tool▁calls▁end|><|end▁of▁sentence|>'}}
65
+ {{- '<|tool▁calls▁end|><|end▁of▁sentence|>'}}
66
{%- endif %}
67
{%- if message['role'] == 'assistant' and (message['tool_calls'] is not defined or message['tool_calls'] is none)%}
68
{%- set ns.is_last_user = false -%}
69
{%- if ns.is_tool %}
70
- {{'<|tool▁outputs▁end|>' + content + '<|end▁of▁sentence|>'}}
70
+ {{- '<|tool▁outputs▁end|>' + content + '<|end▁of▁sentence|>'}}
71
{%- set ns.is_tool = false -%}
72
{%- else %}
73
- {{content + '<|end▁of▁sentence|>'}}
73
+ {{- content + '<|end▁of▁sentence|>'}}
74
{%- endif %}
75
{%- endif %}
76
{%- if message['role'] == 'tool' %}
77
{%- set ns.is_last_user = false -%}
78
{%- set ns.is_tool = true -%}
79
{%- if ns.is_output_first %}
80
- {{'<|tool▁outputs▁begin|><|tool▁output▁begin|>' + content + '<|tool▁output▁end|>'}}
80
+ {{- '<|tool▁outputs▁begin|><|tool▁output▁begin|>' + content + '<|tool▁output▁end|>'}}
81
{%- set ns.is_output_first = false %}
82
{%- else %}
83
- {{'\n<|tool▁output▁begin|>' + content + '<|tool▁output▁end|>'}}
83
+ {{- '\n<|tool▁output▁begin|>' + content + '<|tool▁output▁end|>'}}
84
{%- endif %}
85
{%- endif %}
86
{%- endfor -%}
87
{% if ns.is_tool %}
88
- {{'<|tool▁outputs▁end|>'}}
89
-{% endif %}
88
+ {{- '<|tool▁outputs▁end|>'}}
89
+{%- endif %}
90
{% if add_generation_prompt and not ns.is_last_user and not ns.is_tool %}
91
- {{'<|Assistant|>'}}
92
-{% endif %}
91
+ {{- '<|Assistant|>'}}
92
+{%- endif %}
\ No newline at end of file