Repository navigation
Conversation
Forward add_generation_prompt and continue_final_message to the independent V4.1 encoder. Preserve historical turn separators and EOS while honoring final assistant continuation, including partial reasoning. Add focused regression coverage to the existing tokenizer tests. Co-authored-by: OpenAI Codex <noreply@openai.com> Signed-off-by: ahmed xijiaat <52128022+xijiaat@users.noreply.github.com>
Contributor
Author
|
Hi @DarkLight1337 and @njhill, could you please review this V4.1-only tokenizer This is scoped to the independent V4.1 implementation; the related V4 work is Thank you for your time. |
6 tasks done
6 tasks done
5 of 6 tasks
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.
[Bugfix] Honor generation controls in the DeepSeek V4.1 tokenizer
Purpose
The independent
deepseek_v41tokenizer currently ignoresadd_generation_promptandcontinue_final_message. This produces identicalprompts with the generation prompt enabled or disabled, and leaves EOS at the
end of an assistant prefix even when continuation was requested.
This change forwards the controls to the V4.1 encoder and:
Continuation takes precedence over the generation prompt. This also handles
ChatCompletionRequest(continue_final_message=True)where the defaultadd_generation_prompt=Trueremains in the renderer kwargs. The request schemaalready rejects callers that explicitly set both fields to true.
The reference fixture files are unchanged. Both fixtures end in a completed
assistant message, so the test now checks their exact reference encoding with
add_generation_prompt=False, and separately checks the new generation cue.Related Work And Scope
Related: #46256 and #46257. The existing open PR #46257, by @fank, fixes the
older
deepseek_v4encoder; it does not modify the independentdeepseek_v41wrapper or encoder. This proposal is limited to V4.1 and follows the generation
control semantics discussed there. It does not claim to resolve the V4/V3.2
parts of #46256, and should not auto-close that issue.
Open-PR searches and the issue discussion were checked on 2026-09-21. This
follow-up changes only the independent V4.1 implementation, not the files in
#46257; its scope is also explained in the
issue discussion.
No NIXL, scheduling, DSpark, Triton, or CUDA code changes. This is not a claimed
fix for H20 worker deadlocks or production garbage output.
Test Plan
In a development environment installed according to the repository AGENTS.md:
Coverage includes thinking on/off, final user/developer/system/assistant roles,
system-only prompts, preservation of historical EOS, partial reasoning,
request-to-renderer kwargs, caller-message immutability, and existing reference
tool/image/effort fixtures.
Test Result
Base main:
8ec00ec2bc2d294b742f7814041d3a3043e0a90e.Tests executed in an isolated Linux container on an H20 host. Only the two
tokenizer modules from this main checkout were overlaid in the test process;
other dependencies came from nightly
0.29.1rc1.dev422+gd05da62e9. This is not aclaim of full-checkout integration testing.
generation/continuation string-to-ID consistency checks; ordinary user-ended
prompts retained identical token IDs before and after the patch.
git diff --check: passed.pre-commit run --filesfor the three changed files: passed (inapplicablehooks skipped), including mypy and the repository-specific checks.
The container regression runner loads the two checked-out tokenizer modules
process-locally and then invokes the existing test file with pytest. The
executed command was:
Model Smoke Evaluation
An isolated H20 TP8 server loaded the real DeepSeek-V4.1-Flash model using the
unmodified nightly above. Baseline and patched tokenizers rendered the same
five synthetic conversations to token IDs; those IDs were sent serially to
/v1/completions. No live tokenizer modules were replaced.Generation settings:
temperature=0,seed=2026,max_tokens=128,stream=false,skip_special_tokens=false. All 10 requests returned HTTP 200;all five patched cases contained the expected answer fragment.
323323(prompt IDs unchanged)The result is# 17 * 19 = 323.323.#sustainable agriculture#, then the answerThe capital of France is Paris.Reply exactly OK.OK17 * 19 = 17 * (20 - 1) =# Invalid Requesttext after a raw BOS marker340 - 17 = 323.</think>323The baseline "Invalid Request" was generated model text, not an HTTP error.
This is a narrow prompt-control smoke evaluation, not a broad accuracy
benchmark or full patched
/v1/chat/completionsintegration test. Nothroughput or production-output correctness claim is made from these samples.
AI Assistance And Human Accountability
OpenAI Codex assisted with source review, implementation, test construction,
and test execution. The human submitter reviewed the changes and personally
reran the relevant tests successfully before submission, and is responsible
for the contribution. AI-executed validation is reported separately above.