A drop-in replacement for one shard of deepseek-ai/DeepSeek-V4.1-Flash
that targets the model's Hmm, hmm — hmm: hmm, hmm… degeneration loops in its thinking, and replaces most
Let me … sentence openers with I'll ….
Only the LM head (head.weight) was fine-tuned. The backbone, the DSpark/MTP draft layers, the tokenizer and the
chat template are untouched, so it runs on stock vLLM with the official recipe.
The E head alone did not recover reliably from polluted conversations containing repeated HEAD 401,
quotes, Markdown stars, or repeated thinking-end tokens. This release adds
runtime/decode_recovery.py and a
pinned cold-start script for 2×MI350X. The E and D weight files are unchanged.
Install this runtime alongside the E head when resuming these polluted conversations. It uses the native
vLLM V2 runner and keeps DSpark enabled; the tested configuration is documented in
runtime/README.md.
The middleware removes dominant cyclic passages from assistant history while preserving user/tool messages and complete JSON data. The logits processor checks each DSpark draft prefix independently; rejected draft tokens do not update committed history or persistent recovery state. It closes cyclic thinking when allowed and suppresses the next cyclic answer token only on requests marked for recovery, respecting grammar masks.
Validated on 2×MI350X, UNCENSORED FP8 revision d61c59ea5e514e25d305b5850e8a432f7a9969f2, the original E head,
and the pinned ROCm vLLM build in runtime/manifest.json:
| Test | Runtime recovery result |
|---|---|
| Native processor/middleware regressions | 31/31 |
| Short seeded recovery | 60/60 usable, no sustained cycles |
| 44 synthetic multi-turn sessions, 132 continuations, output budgets 16,384 and 32,768 tokens | 0 sustained cycles, 0 blank answers, 0 truncations, 0 API errors |
| Strict task completion across those continuations | 90/132; 38 generated-test expectation errors and 4 incorrect numeric JSON results remain |
| Independent tests for generated cache implementations | 44/44 code files passed |
| Three failed polluted coding sessions given actual pytest feedback | 3/3 repaired in one follow-up |
| Same 50 tool tasks, E baseline versus E + recovery | 32/50 versus 32/50 completed |
| Native coding / exact copy at 289,731 input tokens / tool round-trip | 6/8 · 12/12 · 4/4 |
| Single-stream warm code / code with thinking / essay, after deployment | 374.9–385.9 / 272.0 / 166.4 tok/s |
These are synthetic polluted-session tests, not a replay of the deleted original session. Eliminating loops does not guarantee correct answers or unchanged capability: strict completion still failed in 42 of 132 continuations. The speed measurements are small samples, and this runtime has not been validated on other vLLM builds or GPU configurations. The older head-only results below are separate experiments.
V4.1 Flash occasionally collapses into a token-level attractor inside <think>: a run of Hmm, hmm. Hmm — hmm! that it almost never leaves again, typically deep in long agent sessions. Lowering temperature, clearing
thinking history or setting repetition_penalty does not fix it reliably. With a long context the penalty is
diluted and stops working.
When the thinking is pre-filled with such a passage, the original model continues the loop in 30 of 30 samples. This head recovers in 29–30 of 30.
This also holds in real use. A real agent session had already degenerated into the loop. Continuing that same session with DeepSeek's official API, or with the original weights, fell back into the loop again. With this head, it did not recur.
# 1. official weights, pinned to the revision this head was trained against
hf download deepseek-ai/DeepSeek-V4.1-Flash --revision dba1be0a40aa45a94ad051997016db3960a90277 \
--local-dir DeepSeek-V4.1-Flash
# 2. replace the single shard that holds head.weight
hf download leonice2/DeepSeek-V4.1-Flash-nohmm model-00043-of-00048.safetensors --local-dir nohmm
cp nohmm/model-00043-of-00048.safetensors DeepSeek-V4.1-Flash/
sha256sum DeepSeek-V4.1-Flash/model-00043-of-00048.safetensors # c2285696…cc3b5, see below
Then serve DeepSeek-V4.1-Flash/ exactly as before. The shard has the same size and tensor layout as the
original, so checkpoint size checks still pass. Re-running step 1 into the same directory restores the official
shard, so run step 2 again after it.
Use the official sampling settings (temperature 1.0, top_p 0.95). Do not set repetition_penalty. It is
not needed with this head, and it actively hurts agents. On the same agent tasks, repetition_penalty 1.1 made
about 30% of file:line citations wrong (about 70% backed by a tool result, vs 98.7% without it). The cause is
that it shifts digits of numbers the answer repeats, e.g. line 386 cited correctly once and then as 486. It also
cost 3–18% decode speed.
| File | What | SHA-256 |
|---|---|---|
model-00043-of-00048.safetensors |
Recommended (E). Drop-in shard: removes hmm loops and most Let me openers |
c228569637336676d44c77edbf00eeb9454bcfeffe1d040dc633cf99975cc3b5 |
head_lowrank.safetensors |
E as low-rank factors u (129280×256) and v (256×5120), FP32 |
43fd02a55109d81df3219be7c2a8034ec27e2c61222476e793f9351e5be2fe02 |
head-d/model-00043-of-00048.safetensors |
Conservative variant (D): removes hmm only, keeps Let me |
02c3464f1f7d255bad2b49d6bd6ac685ca6c63fb8494dc74e183864ce30a3016 |
head-d/head_lowrank.safetensors |
D as low-rank factors | f70fce172a31a49091ae8b93bc9f8dd808174800d9e1360ce70c5f7be777adbe |
The shard equals the official shard with head.weight = bf16(fp32(W0) + u @ v), and norm.weight unchanged.
Computing this on CPU from the official shard and the factors reproduces the shard bit for bit, so you can fetch
the 138 MB factors instead of the 1.3 GB shard:
import torch
from safetensors import safe_open
from safetensors.torch import load_file, save_file
shard = "DeepSeek-V4.1-Flash/model-00043-of-00048.safetensors"
with safe_open(shard, "pt") as f:
tensors = {k: f.get_tensor(k) for k in f.keys()}
lr = load_file("head_lowrank.safetensors")
tensors["head.weight"] = (tensors["head.weight"].float() + lr["u"] @ lr["v"]).to(torch.bfloat16)
save_file(tensors, shard)
Same evaluation suite for all three models: vLLM nightly, 8×H200, temperature 1.0, top_p 0.95, no
repetition penalty.
| Test | Original | D (hmm only) | E (hmm + Let me → I'll) |
|---|---|---|---|
| Recovery from a seeded hmm loop, short prompt, T1.0 / p0.95 | 0/30 | 30/30 | 29/30 |
| Recovery from a seeded hmm loop, short prompt, T0.8 / p0.9 | 0/30 | 30/30 | 30/30 |
| Recovery from a seeded hmm loop, ~141K-token context | 2/15 | 15/15 | 15/15 |
| 300 multi-turn code-exploration agent tasks completed | 175 (58%) | 201 (67%) | 242 (81%) |
| └ turn over 6000 tokens / still unfinished after 14 rounds | 16 / 109 | 10 / 89 | 14 / 44 |
| └ median tool calls on the 146 tasks all three finished | 19 | 18 | 14 |
└ file:line citations in answers backed by an actual tool result |
98.4% | 98.6% | 98.8% |
Thinking sentences starting with Hmm (per 1000) |
26.0 | 2.4 | 4.9 |
Thinking sentences starting with Let (per 1000) |
297 | 320 | 63 |
| Filler words in thinking on ordinary tasks (per 1000 words) | 3.71 | 3.46 | 1.05 |
| Generated LRU cache passes its own pytest suite | 4/8 | 8/8 | 6/8 |
| Exact copy of 12 codes hidden in a 290K-token context | 12/12 | 12/12 | 12/12 |
| Tool call + continuation | 4/4 | 4/4 | 4/4 |
| Single-stream decode tok/s (code / with thinking / essay) | ~500 / ~415 / 224 | ~509 / ~446 / 233 | ~513 / ~393 / 218 |
In the seeded-loop tests, the thinking block is pre-filled with a degenerate hmm passage of the kind seen in
production, and the model writes 300 more tokens. A sample counts as recovered when at least 60% of those words
are real words. The agent tasks use the same 300 seeded questions for every model, with read-only grep /
read_file tools over open-source Python packages. The pytest and speed rows use only 8 and 1–2 runs, so
differences there are within noise.
E also runs on vLLM ROCm nightly, 4×MI350X, TP4 with DSpark, sampling temperature 1.0, top_p 0.95.
| Test | E on MI350X |
|---|---|
| Recovery from a seeded hmm loop: short T1.0 / short T0.8 / ~141K context | 29/30 · 30/30 · 15/15 |
| First 100 of the same agent tasks completed | 82/100 (85/100 in a repeat run) |
file:line citations backed by a tool result |
98.7% |
Thinking sentences starting with Hmm / Let / I'll (per 1000) |
4.1 / 57 / 211 |
| Filler words in thinking on ordinary tasks (per 1000 words) | 0.77 |
| Generated LRU cache passes its own pytest suite / exact copy at 290K / tool call | 6/8 · 12/12 · 4/4 |
| Single-stream decode tok/s (code / with thinking / essay) | ~430 / ~337 / 206 |
Let me X was rewritten to I'll X. 238 extra sequences had a synthetic hmm run
spliced into the thinking, with the clean continuation as the target. Total: 938 sequences, 15.6M tokens,
3.9M supervised.W = W0 + u @ v to the LM head was trained.Let for E)). Recovery sequences are weighted ×3.head.weight is 8.4%
(E) and 7.1% (D).A lesson from a failed variant: rewriting Let me X into terse imperatives (X.) looked great on the hmm
tests but dropped agent completion to 47% and created new short-sentence loops. With a frozen backbone, the
rewritten style has to be something the model already writes. I'll X is.
dba1be0a40aa45a94ad051997016db3960a90277. If DeepSeek updates the base weights,
this head no longer applies.DeepSeek-V4.1-Flash 的思考过程偶尔会陷入 Hmm, hmm — hmm… 的无限循环。调温度、清思考历史、加
repetition_penalty 都修不好,长上下文里尤其明显。这里只微调了输出层(head.weight),主干、投机解码层、分词器
都没动。用法是下载官方权重后,替换 model-00043-of-00048.safetensors 这一个分片。
在同一套测试中,推荐的 E 版:
采样参数用官方的 temperature 1.0、top_p 0.95,不要设 repetition_penalty:设成 1.1 时,Agent 回答里约 30% 的行号引用会出错。NVIDIA H200 和 AMD MI350X(ROCm)上都验证过,效果一致。训练数据全部由模型在开源代码仓库上自己生成,不包含任何用户数据。
2026-10-10 运行时更新: 原 E 权重单独使用时,污染会话仍可能出现 HEAD 401、引号、星号和思考结束符循环。
现新增 runtime/ 恢复代码及双 MI350X 固定启动脚本,保留 DSpark、原 E 权重和原生 V2。
44 个模拟多轮会话、132 次长续写使用 16K/32K 输出预算,持续循环、空答、截断和 API 错误均为 0;严格任务完成为
90/132,仍有测试预期与数值错误。热机代码约 375–386 token/s。这次是推理运行时修复,不是新的微调权重;
不会保证所有任务正确。 使用方法、固定镜像、源码哈希和完整验证摘要见 runtime/。
head-d/model-00043-of-00048.safetensors 1.2 GiBmodel-00043-of-00048.safetensors 1.2 GiBhead-d/head_lowrank.safetensors 131 MiBhead_lowrank.safetensors 131 MiBdeepseek-ai/DeepSeek-V4.1-Flash