Upload chat_template.jinja with huggingface_hub
Browse files- chat_template.jinja +45 -0
chat_template.jinja
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{#- Penny chat template: the exact format Penny's SFT stages train on (penny.data_mix.encode_chat).
|
| 2 |
+
|
| 3 |
+
<|end▁of▁sentence|>{system}<|User|>{user}<|Assistant|><think>…</think>{reply}<|end▁of▁sentence|>
|
| 4 |
+
|
| 5 |
+
* The conversation starts with bos_token (= <|end▁of▁sentence|>, the token Penny saw before every
|
| 6 |
+
pretraining document).
|
| 7 |
+
* An assistant turn without reasoning gets an empty-think marker "</think>" in front of its reply.
|
| 8 |
+
Reasoning can come inside the content ("<think>…</think>reply") or in `reasoning_content`.
|
| 9 |
+
* Any role other than system / user / assistant (tool, function, ...) is shown as a user turn
|
| 10 |
+
"[role] content".
|
| 11 |
+
* add_generation_prompt opens an assistant turn with "<think>" (thinking mode, the default), so
|
| 12 |
+
the model always reasons first. enable_thinking=false opens it with "</think>" instead, for a
|
| 13 |
+
direct answer. Both are single tokens, so the prompt is token-for-token what SFT trained on.
|
| 14 |
+
-#}
|
| 15 |
+
{%- macro text(c) -%}
|
| 16 |
+
{%- if c is string -%}{{ c }}
|
| 17 |
+
{%- elif c is iterable -%}{%- for p in c -%}{%- if p is mapping and p.get('type', 'text') == 'text' -%}{{ p.get('text', '') }}{%- elif p is string -%}{{ p }}{%- endif -%}{%- endfor -%}
|
| 18 |
+
{%- endif -%}
|
| 19 |
+
{%- endmacro -%}
|
| 20 |
+
{{- bos_token -}}
|
| 21 |
+
{%- for m in messages -%}
|
| 22 |
+
{%- set content = text(m['content']) if m.get('content') is not none else '' -%}
|
| 23 |
+
{%- if m['role'] == 'system' -%}
|
| 24 |
+
{{- content -}}
|
| 25 |
+
{%- elif m['role'] == 'user' -%}
|
| 26 |
+
{{- '<|User|>' + content -}}
|
| 27 |
+
{%- elif m['role'] == 'assistant' -%}
|
| 28 |
+
{%- if m.get('reasoning_content') -%}
|
| 29 |
+
{{- '<|Assistant|><think>' + m['reasoning_content'] + '</think>' + content + '<|end▁of▁sentence|>' -}}
|
| 30 |
+
{%- elif (content | trim).startswith('<think>') -%}
|
| 31 |
+
{{- '<|Assistant|>' + content + '<|end▁of▁sentence|>' -}}
|
| 32 |
+
{%- else -%}
|
| 33 |
+
{{- '<|Assistant|></think>' + content + '<|end▁of▁sentence|>' -}}
|
| 34 |
+
{%- endif -%}
|
| 35 |
+
{%- else -%}
|
| 36 |
+
{{- '<|User|>[' + m['role'] + '] ' + content -}}
|
| 37 |
+
{%- endif -%}
|
| 38 |
+
{%- endfor -%}
|
| 39 |
+
{%- if add_generation_prompt -%}
|
| 40 |
+
{%- if enable_thinking is defined and not enable_thinking -%}
|
| 41 |
+
{{- '<|Assistant|></think>' -}}
|
| 42 |
+
{%- else -%}
|
| 43 |
+
{{- '<|Assistant|><think>' -}}
|
| 44 |
+
{%- endif -%}
|
| 45 |
+
{%- endif -%}
|