Repository navigation
feat: add Qwen3-8B template #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
82126f6
feat: add original Qwen3-8B template from HuggingFace
Neonkraft 3fa3ee1
feat: add generation markers
Neonkraft f48454b
feat: add Qwen3-8B template to registry
Neonkraft 6884b66
fix: exclude think-stripped history from Qwen3 loss mask
Neonkraft 877c600
test: assert which spans the qwen3 template puts in the loss
Neonkraft ec74b1d
fix: exclude think-stripped history from Qwen3 loss mask
Neonkraft 8d4e676
test: assert which spans the qwen3 template puts in the loss
Neonkraft 218858e
test: assert qwen3 template renders byte-identically to upstream
Neonkraft 81b2d5f
Merge branch 'feat/qwen3-loss-mask' into feat/qwen3-sft-template
Neonkraft e31a860
refactor: rename qwen3 jinja file
Neonkraft db4f5e8
feat: filter out rows with all zero assistant loss mask
Neonkraft 189bb7b
tests: add tests for row filters
Neonkraft 604e731
fix: warn when max_length cuts a supervised span part-way (#49)
KonstiNik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| {%- if tools %} | ||
| {{- '<|im_start|>system\n' }} | ||
| {%- if messages[0].role == 'system' %} | ||
| {{- messages[0].content + '\n\n' }} | ||
| {%- endif %} | ||
| {{- "# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }} | ||
| {%- for tool in tools %} | ||
| {{- "\n" }} | ||
| {{- tool | tojson }} | ||
| {%- endfor %} | ||
| {{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }} | ||
| {%- else %} | ||
| {%- if messages[0].role == 'system' %} | ||
| {{- '<|im_start|>system\n' + messages[0].content + '<|im_end|>\n' }} | ||
| {%- endif %} | ||
| {%- endif %} | ||
| {%- set ns = namespace(multi_step_tool=true, last_query_index=messages|length - 1) %} | ||
| {%- for message in messages[::-1] %} | ||
| {%- set index = (messages|length - 1) - loop.index0 %} | ||
| {%- if ns.multi_step_tool and message.role == "user" and message.content is string and not(message.content.startswith('<tool_response>') and message.content.endswith('</tool_response>')) %} | ||
| {%- set ns.multi_step_tool = false %} | ||
| {%- set ns.last_query_index = index %} | ||
| {%- endif %} | ||
| {%- endfor %} | ||
| {%- for message in messages %} | ||
| {%- if message.content is string %} | ||
| {%- set content = message.content %} | ||
| {%- else %} | ||
| {%- set content = '' %} | ||
| {%- endif %} | ||
| {%- if (message.role == "user") or (message.role == "system" and not loop.first) %} | ||
| {{- '<|im_start|>' + message.role + '\n' + content + '<|im_end|>' + '\n' }} | ||
| {%- elif message.role == "assistant" %} | ||
| {%- set reasoning_content = '' %} | ||
| {%- if message.reasoning_content is string %} | ||
| {%- set reasoning_content = message.reasoning_content %} | ||
| {%- else %} | ||
| {%- if '</think>' in content %} | ||
| {%- set reasoning_content = content.split('</think>')[0].rstrip('\n').split('<think>')[-1].lstrip('\n') %} | ||
| {%- set content = content.split('</think>')[-1].lstrip('\n') %} | ||
| {%- endif %} | ||
| {%- endif %} | ||
| {%- set assistant_body %} | ||
| {%- if loop.index0 > ns.last_query_index %} | ||
| {%- if loop.last or (not loop.last and reasoning_content) %} | ||
| {{- '<think>\n' + reasoning_content.strip('\n') + '\n</think>\n\n' + content.lstrip('\n') }} | ||
| {%- else %} | ||
| {{- content }} | ||
| {%- endif %} | ||
| {%- else %} | ||
| {{- content }} | ||
| {%- endif %} | ||
| {%- if message.tool_calls %} | ||
| {%- for tool_call in message.tool_calls %} | ||
| {%- if (loop.first and content) or (not loop.first) %} | ||
| {{- '\n' }} | ||
| {%- endif %} | ||
| {%- if tool_call.function %} | ||
| {%- set tool_call = tool_call.function %} | ||
| {%- endif %} | ||
| {{- '<tool_call>\n{"name": "' }} | ||
| {{- tool_call.name }} | ||
| {{- '", "arguments": ' }} | ||
| {%- if tool_call.arguments is string %} | ||
| {{- tool_call.arguments }} | ||
| {%- else %} | ||
| {{- tool_call.arguments | tojson }} | ||
| {%- endif %} | ||
| {{- '}\n</tool_call>' }} | ||
| {%- endfor %} | ||
| {%- endif %} | ||
| {{- '<|im_end|>' }} | ||
| {%- endset %} | ||
| {{- '<|im_start|>' + message.role + '\n' }} | ||
| {%- if loop.index0 > ns.last_query_index %} | ||
| {%- generation %}{{- assistant_body -}}{%- endgeneration %} | ||
| {%- else %} | ||
| {{- assistant_body }} | ||
| {%- endif %} | ||
| {{- '\n' }} | ||
| {%- elif message.role == "tool" %} | ||
| {%- if loop.first or (messages[loop.index0 - 1].role != "tool") %} | ||
| {{- '<|im_start|>user' }} | ||
| {%- endif %} | ||
| {{- '\n<tool_response>\n' }} | ||
| {{- content }} | ||
| {{- '\n</tool_response>' }} | ||
| {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %} | ||
| {{- '<|im_end|>\n' }} | ||
| {%- endif %} | ||
| {%- endif %} | ||
| {%- endfor %} | ||
| {%- if add_generation_prompt %} | ||
| {{- '<|im_start|>assistant\n' }} | ||
| {%- if enable_thinking is defined and enable_thinking is false %} | ||
| {{- '<think>\n\n</think>\n\n' }} | ||
| {%- endif %} | ||
| {%- endif %} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.