Skip to content

[Bugfix][Frontend] Match DeepSeek-V4.1 encoder to the 1017 reference encoding - #62199

Merged
robertgshaw2-redhat merged 7 commits into
vllm-project:mainfrom
robertgshaw2-redhat:dsv41-1017-encoder-parity
Oct 19, 2026
Merged

robertgshaw2-redhat merged 7 commits into
vllm-project:mainfrom
robertgshaw2-redhat:dsv41-1017-encoder-parity

Conversation

@robertgshaw2-redhat

@robertgshaw2-redhat robertgshaw2-redhat commented Oct 17, 2026 •

Copy link
Copy Markdown
Collaborator

Overview

Match the Python DeepSeek V4.1 encoder to the updated reference encoding/. Rust counterpart: #62200.

Affects both V4.1-Flash checkpoints (launch and 1017). DeepSeek fixed the turn handling in both repos (launch 314113f, 1017 release); their encoding/ is now identical. The image-token check has been in the reference since launch.

Claims

  • Tool results alone no longer start a new user turn, so reasoning before a tool call is kept.
  • Literal <|deepseek_image|> in message text or reasoning returns 400.
  • All five reference golden prompts match. V4 is unchanged.

Examples

1. Tool call in thinking mode, with no tools field in the request

[{"role": "user", "content": "What's the weather in Paris? Answer in Fahrenheit."},
 {"role": "assistant", "content": "", "reasoning": "Tool returns Celsius; convert to Fahrenheit.",
  "tool_calls": [{"id": "c1", "type": "function", "function": {"name": "get_weather", "arguments": "{\"city\": \"Paris\"}"}}]},
 {"role": "tool", "tool_call_id": "c1", "content": "{\"temp_c\": 20}"}]

Before (reasoning dropped):

<|User|>What's the weather in Paris? Answer in Fahrenheit.<|Assistant|></think>

<|DSML| calls>...

After (reasoning kept, same as the reference encoder):

<|User|>What's the weather in Paris? Answer in Fahrenheit.<|Assistant|><think>Tool returns Celsius; convert to Fahrenheit.</think>

<|DSML| calls>...

2. Literal image token in text

[{"role": "user", "content": "hi <|deepseek_image|>"}]

Before: accepted, so the prompt has an image placeholder with no image. After: 400.

Validation

  • pytest tests/tokenizers_/test_deepseek_v41.py tests/tokenizers_/test_deepseek_v4.py: 84 passed. The new tests fail on main.
  • E2E on 8x H100 (TP8, recipe H100 flags, DeepSeek-V4.1-Flash-1017): the prompt keeps the tool-call reasoning and matches the reference encoder; the literal image token returns 400.
  • GSM8K (chat, thinking off, 1319 questions): 0.970.

Details

Not a duplicate: #60792 (image order) and other open V4.1 tokenizer PRs don't change turn boundaries or placeholder validation. Fixtures are copied from the 1017 repo (MIT).


Pull Request Checklist
  • I used vLLM's /pr-checklist skill. (Mandatory for agents, optional for humans).

  • AI assistance was used during the creation of this PR.

  • Design Fit: Minimizes impact on core components, reuses existing functionality, and justifies added complexity.

  • Testing and Validation: Validates the change and ensures any added tests are meaningful and reliable, with CI coverage or documented CI resource constraints and validation performed outside CI.

  • Code Quality and Style: Keeps code and comments clear and concise, and updates relevant documentation and examples.

  • Pull Request Contents: Includes a brief summary and relevant links, supports claims with evidence, explains root causes and implementation trade-offs, and follows the contributing guide.

🤖 Generated with Claude Code

…encoding

Tool-result-only user turns no longer end the current turn, so drop_thinking
keeps the reasoning that led to a tool call. Reject literal image placeholder
tokens in message text and reasoning. Vendor the reference encoder's golden
fixtures from DeepSeek-V4.1-Flash-1017; DeepSeek-V4.1-Flash carries the same
encoding/ since 2026-10-16.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Robert Shaw <robertgshaw2@gmail.com>

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@mergify mergify Bot added deepseek Related to DeepSeek models DSv4.1 Related to DeepSeek-V4.1 models bug Something isn't working labels Oct 17, 2026
robertgshaw2-redhat and others added 2 commits October 17, 2026 12:00
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Robert Shaw <robertgshaw2@gmail.com>

@sfeng33 sfeng33 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the work, LGTM!

@robertgshaw2-redhat robertgshaw2-redhat added the ready ONLY add when PR is ready to merge/full CI is needed label Oct 17, 2026
@robertgshaw2-redhat
robertgshaw2-redhat enabled auto-merge (squash) October 17, 2026 22:08
@robertgshaw2-redhat

Copy link
Copy Markdown
Collaborator Author

/ci run

@github-actions

Copy link
Copy Markdown

✅ Triggered Buildkite CI #95627 for commit 739d1573cfd7.

@mergify

mergify Bot commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @robertgshaw2-redhat.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify Bot removed the needs-rebase label Oct 19, 2026
@robertgshaw2-redhat

Copy link
Copy Markdown
Collaborator Author

/ci retry

@github-actions

Copy link
Copy Markdown

✅ Triggered Buildkite CI #95915 for commit 2a20d84234a2, running 1 failed step(s) from Buildkite CI #95627.

@robertgshaw2-redhat
robertgshaw2-redhat merged commit ddefe40 into vllm-project:main Oct 19, 2026
16 checks passed
reputationly added a commit to reputationly/vllm-backport that referenced this pull request Oct 21, 2026
上游来源:vllm-project/vllm#62199 (ddefe40e16)、#60792 (3c8245b73d)、
#62200 (2cea893821),适配点:
- tokenizer 路径沿用本仓 deepseek_v41 / deepseek_v4_1 命名,手工逐 hunk 合入;
- FakeHfTokenizer 测试工装保留,fixture 从 1017 reference 整体替换;
- effort 别名按 deepseek-recipe 补齐 minimal/medium/xhigh/ultra;
- Rust renderer 同步 starts_user_turn / 图片占位符拒绝(测试用 new() 适配本仓)。

Co-authored-by: DSH Agent <dsh-agent@local>
Signed-off-by: DSH Agent <dsh-agent@local>
Signed-off-by: reputationly <197039020@qq.com>
Morrowmake pushed a commit to Morrowmake/vllm-cmp170hx that referenced this pull request Oct 24, 2026
A user message that holds only tool results no longer counts as the last
user turn, as in the 1017 reference encoder. With drop_thinking on (a
request that declares no tools) the old rule dropped the reasoning of
every earlier tool round of the current turn and closed the thinking block
right after each of those tool results.

This is the find_last_user_index change of upstream vllm-project#62199; it goes away
when the base includes that commit.
Morrowmake pushed a commit to Morrowmake/vllm-cmp170hx that referenced this pull request Oct 26, 2026
Upstream vLLM vllm-project#61455 tags draft groups on the global KV cache groups and
keeps is_eagle_group when it projects them onto a worker that owns none
of a group's layers, so every worker's config already carries the flag
merge_eagle_group_flags restored. Remove it, its call, its test and its
seam pin. The DeepSeek-V4.1 encoder fix for tool results (upstream
vLLM vllm-project#62199) is now upstream's own text: drop the stale modification
notice from that file.
bantianyue pushed a commit to bantianyue/vllm that referenced this pull request Oct 28, 2026
…encoding (vllm-project#62199)

Signed-off-by: Robert Shaw <robertgshaw2@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working deepseek Related to DeepSeek models DSv4.1 Related to DeepSeek-V4.1 models ready ONLY add when PR is ready to merge/full CI is needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants