You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 2500ee9
Browse filesBrowse the repository at this point in the historyBrowse files
Add DeepSeek-V4 chat encoding to SFT preprocessing
DeepSeek-V4 ships no Jinja chat_template, so apply_chat_template fails during SFT preprocessing. The official encoder was only vendored under benchmarks/api_server, which src/maxtext cannot import, and that copy had lost the blank lines in TOOLS_TEMPLATE and several docstrings, so its tool-calling prompts no longer matched the official encoder goldens.
- Move benchmarks/api_server/encoding/encoding_dsv4.py to src/maxtext/input_pipeline/encoding_dsv4.py, restore the stripped blank lines, and import it from benchmarks/api_server/{maxtext_server,server_utils}.py.
- input_pipeline_utils.apply_chat_template: when chat_template is None and the model or tokenizer is DeepSeek-V4, encode with encode_messages and split each assistant turn into prompt and completion; reject encoded text left after the final assistant turn.
- grain_data_processing and hf_data_processing: forward model_name to apply_chat_template.
- tests: golden parity with the 4 official encoder fixtures, Grain and HF SFT loss-mask checks (packed and unpacked), DeepSeek-V4 detection including unk_token_id fallbacks, and model_name forwarding in hf_data_processing.preprocessing_pipeline.
Copy file name to clipboardExpand all lines: src/maxtext/input_pipeline/encoding_dsv4.py
+34Lines changed: 34 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -81,7 +81,9 @@
81
81
)
82
82
83
83
TOOLS_TEMPLATE="""## Tools
84
+
84
85
You have access to a set of tools to help answer the user's question. You can invoke tools by writing a "<{dsml_token}tool_calls>" block like the following:
String parameters should be specified as is and set `string="true"`. For all other types (numbers, booleans, arrays, objects), pass the value in JSON format and set `string="false"`.
98
+
95
99
If thinking_mode is enabled (triggered by {thinking_start_token}), you MUST output your complete reasoning inside {thinking_start_token}...{thinking_end_token} BEFORE any tool calls or final response.
100
+
96
101
Otherwise, output directly after {thinking_end_token} with tool calls or final response.
102
+
97
103
### Available Tool Schemas
104
+
98
105
{tool_schemas}
106
+
99
107
You MUST strictly follow the above defined tool name and parameter schemas to invoke tool calls.
0 commit comments