[fix] Align DeepSeek-V4.1 prompt and tool-call encoding - #10236
Merged
tastelikefeet merged 5 commits intoSep 25, 2026
Merged
tastelikefeet merged 5 commits into
tastelikefeet merged 5 commits into
Conversation
Collaborator
|
Hi, thanks for pointing out the problem! Can you help to add some tests to keep it right? for example, agent template/reasoning efforts and history thinking/multi-turn chats/tool call parsing |
| messages = [] | ||
| for is_assistant, group in groupby(inputs.messages, key=lambda m: m['role'] == 'assistant'): | ||
| queries = list(group) | ||
| if is_assistant or not any(m['role'] == 'system' for m in queries): |
Collaborator
There was a problem hiding this comment.
Why not just find the first assistant? groupby maybe too heavy.
tastelikefeet
approved these changes
Sep 25, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
PR type
PR information
DeepSeek-V4.1 currently selects the V4 agent, so training formats tool calls with V4 tags and inference fails to parse official V4.1 calls. Its inherited reasoning settings also emit V4 effort prompts instead of the V4.1 numeric budget.
Align the DeepSeek templates with the official V4.1 encoder:
calls,invoke, andparametertags consistently for tool instructions, history formatting and parsing. V4 keeps its existing tags and output.The final diff contains three production files: the DeepSeek agent, its registry entry, and the DeepSeek model template. Shared template bases, input conversion, dataset processing, inference engine and response dataclasses are identical to the base revision. Native provider-field conversion, general mixed-role/content-block compatibility and separate tool-namespace response fields are outside this PR's scope.
Experiment results
Using real tokenizer/config snapshots and official encoder revision
dba1be0a40aa45a94ad051997016db3960a90277:<think>...</think>representation.git diff --checkpassed. The diff was checked to contain only the three files above.Tests and audit artifacts are kept outside the production-only PR. Live model generation and GPU training were not run.