Skip to content

Require transformers>=5.8.0 to fix DeepSeek-R1-Distill-Qwen tokenization - #411

Merged
gregorybchris merged 2 commits into
mainfrom
chrisg/fix-deepseek-distill-tokenizer
Sep 25, 2026
Merged

gregorybchris merged 2 commits into
mainfrom
chrisg/fix-deepseek-distill-tokenizer

Conversation

@gregorybchris

@gregorybchris gregorybchris commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #241.

DeepSeek-R1-Distill-Qwen models produce output full of byte-level markers (Ġ for space, Ċ for newline) because we lock transformers 5.7.0. This PR requires transformers 5.8.0, which fixes the bug upstream, and locks 5.8.1.

Cause

deepseek-ai/DeepSeek-R1-Distill-Qwen-* checkpoints have a qwen2 model config, but their tokenizer_config.json names LlamaTokenizerFast. transformers 5.6 and 5.7 trust that class name and load LlamaTokenizer, which drops the checkpoint's byte-level pre-tokenizer and decoder:

  • Decoded output keeps the markers: 'ĊOkay,ĠsoĠIĠhaveĠthisĠquestion.'
  • Prompts lose all whitespace on encode: 'Okay,soIhavethisquestion.', so these evals were also scoring garbled prompts.

transformers 5.8.0 fixed the class mapping for qwen2 (huggingface/transformers#45741).

transformers Tokenizer class decode of "\nOkay, so I have this question."
4.57.1 – 5.5.0 correct correct
5.6.0 – 5.7.0 LlamaTokenizer 'ĊOkay,ĠsoĠIĠhaveĠthisĠquestion.'
5.8.0 – 5.17.0 Qwen2Tokenizer correct

The lock has held 5.7.0 since the transformers 5 bump in April. The bug reached Beaker runs on 2026-06-15, when the isolated vLLM venv started installing against uv.lock (81f6a7d). Before that, it resolved the latest transformers, which already had the fix. This matches the report of correct output around June 5 and broken output by June 17.

Changes

  • pyproject.toml: raise the transformers floor to >=5.8.0 in the hf and vllm extras. The <5.13 cap for vLLM 0.19.1 stays.
  • uv.lock: transformers 5.7.0 → 5.8.1. No other package versions change. uv also rewrote some resolution markers for pandas and rich; main's lock was up to date before this change.
  • tests/inference/test_tokenizer_loading.py: builds a small offline checkpoint with the same mismatch (qwen2 config, LlamaTokenizerFast tokenizer class) and checks that encode and decode round-trip. It fails on 5.7.0 and passes on 5.8.1. It needs no network.

Testing

  • The new test fails on transformers 5.7.0 with the issue's symptom and passes on 5.8.1.

  • Unit suite as CI runs it: 2711 passed, 32 skipped.

  • I compared tokenizers on 5.7.0 and 5.8.1 for the HF models in our presets plus a few common ones: OLMo-2-1124-7B, Olmo-3-1025-7B, Olmo-3-7B-Instruct, Molmo2-4B, DeepSeek-R1-Distill-Llama-8B, Mistral-7B-v0.3, Qwen2.5-7B, Qwen3-8B, Qwen3-Coder-30B-A3B-Instruct, and phi-4. Tokenizer class, encode ids, decode, per-token decode, special tokens, and chat template output are identical. Only DeepSeek-R1-Distill-Qwen-1.5B and -7B change, and they now decode correctly. The Llama 3.1 and Gemma repos are gated and were not checked. DeepSeek-R1-Distill-Llama-8B uses the Llama 3 tokenizer and is unchanged.

  • End to end on Beaker with the command from [BUG] Deepseek Model Output Processing #241 (vllm_server, DeepSeek-R1-Distill-Qwen-1.5B, ifeval_ood, --inspect): https://beaker.org/ex/01M3B7F3JK32DWW8MDNF4Y9CRW. The job exited 0 with 300/300 predictions, and none of the 300 rows in predictions.jsonl contain Ġ or Ċ. Output text has normal spaces and newlines and answers the prompts, so prompts are also reaching the model intact. The job logs show the isolated vLLM venv installed transformers 5.8.1 from the lock.

    Sample output (doc 0): "\n\nThe world is a kaleidoscope of complexity, where patterns emerge from chaos, and the unknown begins to surface. ..."

🤖 Generated with Claude Code

transformers 5.6 and 5.7 load deepseek-ai/DeepSeek-R1-Distill-Qwen-* with
LlamaTokenizer because the checkpoint's tokenizer_config.json names
LlamaTokenizerFast. That tokenizer drops the byte-level pre-tokenizer and
decoder. Prompts lose all whitespace on encode, and decoded output keeps
the byte-level markers (Ġ for space, Ċ for newline). transformers 5.8.0
fixes the class mapping (huggingface/transformers#45741).

The lock has held 5.7.0 since the transformers 5 bump. Beaker jobs began
using it for vLLM on 2026-06-15, when the isolated vLLM venv started
following uv.lock (81f6a7d), which matches when the bug appeared.

Raise the floor to 5.8.0 in the hf and vllm extras and move the lock to
5.8.1. Tokenizer output for the other preset models is unchanged between
5.7.0 and 5.8.1. The new test builds an offline checkpoint with the same
qwen2 plus LlamaTokenizerFast mismatch and fails on 5.7.0.

Fixes #241.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

@mgmorgan23 mgmorgan23 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm!

@gregorybchris
gregorybchris enabled auto-merge (squash) September 25, 2026 17:30
@gregorybchris
gregorybchris merged commit 4294cc7 into main Sep 25, 2026
8 checks passed
@gregorybchris
gregorybchris deleted the chrisg/fix-deepseek-distill-tokenizer branch September 25, 2026 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Deepseek Model Output Processing

2 participants