ds4 icon indicating copy to clipboard operation
ds4 copied to clipboard

DeepSeek-V4-Flash-0731: the -imatrix-0731 quants ARE 0731-calibrated, byte-exact reasoning-effort prefixes, and a max_tokens warning

Open rell666 opened this issue 4 months ago • 5 comments

Two corrections and one practical warning, all checkable from published artifacts.

1. antirez's 0731 quants ARE calibrated on 0731 — the .dat just wasn't uploaded

The "imatrix is missing" / "not yet recalibrated for 0731" caveat has been repeated a few times in this thread. It's wrong, and the files say so themselves. Read straight out of the GGUF headers over HTTP range requests (no download needed):

file quantize.imatrix.file chunks_count
…-chat-v2-imatrix.gguf (preview) …/DeepSeek-V4-Flash-chat-v2-routed-moe-ds4-1p5m-fixed.dat 90,042
…-chat-v2-imatrix-0731.gguf gguf/DeepSeek-V4-Flash-0731-chat-v2-routed-moe-ds4.dat 202,100

All three -imatrix-0731 builds (IQ2XXS, Q4K, Layers37-42) name the 0731 .dat, with entries_count = 129 = 43 layers × {gate, up, down}, i.e. full coverage. The MXFP4 build carries no quantize.imatrix.* keys at all, which is expected for a scale-block format.

Corroborating arithmetic: an imatrix build is exactly 288 bytes larger than its non-imatrix twin (the four extra KV entries). 86,720,111,488 − 86,720,111,200 = 288, and the same for the Q4K pair.

So antirez recollected at 2.24× the preview's calibration depth and simply didn't publish the .dat. The fair criticism is transparency, not calibration — worth knowing before anyone switches away assuming his upload is stale. Of the 0731 ds4-format quants I've checked, his has the deepest calibration:

repo chunks calibrated on
antirez -0731 (×3) 202,100 0731 (.dat unpublished)
ox-ox 117,777 0731 (.dat published)
Rednalreden 117,777 0731
jmilnz 2,752 0731
schlaflos, nazeshinjite 90,042 preview (documented)

This matters more than usual because at IQ2_XXS a calibration mismatch is roughly 18–21× costlier than at Q4_K_M, and IQ2_XXS has no no-imatrix fallback — llama.cpp refuses to quantize without one.

Separately: the undocumented -fixed suffix means a corrected imatrix collection pass (HF commit b0c3326275, "Replace imatrix GGUF with fixed routed-mid imatrix build"), not a model defect. That also only exists in the file metadata.

2. Byte-level confirmation of the reasoning-effort shift

Independently reproducing @kernelzeroday's and @sleepless's finding, with hashes in case they help anyone implementing the fix. Extracting the emitted prefix from ds4-server --trace and hashing the region between BOS and <|User|>:

tier bytes sha256
what ds4 emits for reasoning_effort: max 476 f7a24f3b3050d4a83781e9b755b316aae2ec1d9dc87562541d90bcb04d7350f7
official 0731 REASONING_EFFORT_PROMPTS["max"] 528 53fb31b8392ec5b4a926481943efc67636748f137c1a49d493a7af4d4fa55d2c

The 476-byte string is byte-identical to the official high prompt. Note the official max string contains an em dash (U+2014) at char 33 — worth checking it survives if you hard-code it in C.

One more thing: DS4_THINK_MAX_MIN_CONTEXT (393216) silently steps the top tier down below that context, so on a smaller --ctx every effort value except none renders an identical prompt. The comment above it cites the model card as recommending "at least a 384K context window", but the 0731 card says "For the high and max reasoning effort levels, we recommend a maximum output length of 384K tokens" — one number, covering both prefixed tiers, about output. That looks like an output-budget recommendation being enforced as an input-context gate.

3. Practical warning: 0731 generates substantially more on structured extraction

Everyone reporting on Q&A/agentic workloads is finding 0731 more concise (@Flor1an-B: −3.5% total tokens, −9.6% median turn time, plus a genuine agentic gain of 84 → 85 on tool-eval-bench). On structured JSON extraction at reasoning_effort: none I measured the opposite on a paired run — same prompts, same engine, same quant recipe, GGUF the only variable, 70 requests per arm:

  • mean completion tokens 2,383 → 3,359 (+41%)
  • mean extracted items per request 12.6 → 17.8 (+41%)

So it isn't verbosity — it's more extracted content per call. But if your max_tokens ceiling is sized for the preview, 0731 will hit it: at 8192 the truncation rate went from 1/70 to 9/70, all finish_reason: "length" producing invalid JSON. It first bites around 5k-token prompts, well before the extreme sizes. Both findings are probably consistent — 0731 seems to think less and emit more — so don't carry either result across task types.

Mean evidence-quote length also fell ~29% while quote-anchoring ambiguity roughly doubled: the headline anchor rate improved while quotes got shorter and less uniquely placeable. Worth checking if you depend on verbatim quoting.

rell666 avatar Aug 02 '26 05:08 rell666

Regarding reasoning-effort shift: I did implement it (not commited/pushed anywhere), but at this stage it would break the preview model. Also, I currently don't have GLM5.2 so that I didn't verify it against that and am also wondering if it the reasoning effort map was considered when implementing GLM5.2 support - anyone knows?

sleepless avatar Aug 02 '26 09:08 sleepless

@sleepless — I hit both of those. Here's what worked, in case it saves you time.


1. Breaking the preview model

You're right, and it can't be avoided with a single fixed map.

Preview's max is 0731's high string. So any map that makes max mean 0731's max necessarily sends preview users a "Beyond maximum…" prefix that checkpoint never saw.

What worked: don't choose.

--reasoning-effort-map {deepseek|legacy}     # default: deepseek

legacy reproduces the current table exactly. One flag to revert.

Two things worth doing alongside it:

  • assert both maps in test_reasoning_effort_mapping(), so the legacy path can't silently drift
  • keep unknown strings returning false in both, so the HTTP 400 is preserved

2. GLM 5.2 — you don't need it locally to answer this

GLM is independent of the DeepSeek prefix path. From chat_push_think_prefix(), ds4.c:36310-36322 on 54b36ed:

if (DS4_MODEL_FAMILY == DS4_MODEL_FAMILY_GLM_DSA) {
    const char *effort = ds4_glm_reasoning_effort_text(think_mode);
    if (effort) { token_vec_push(out, vocab->system_id); bpe_tokenize_text(vocab, effort, out); }
} else if (think_mode == DS4_THINK_MAX) {
    bpe_tokenize_text(vocab, DS4_REASONING_EFFORT_MAX_PREFIX, out);
}

GLM takes the branch first and renders effort as a system message ("Reasoning Effort: High" / "Max"). It never touches DS4_REASONING_EFFORT_MAX_PREFIX.

So the one-notch shift doesn't reach GLM — but adding a tier does, silently. See below.


3. Three landmines that produce no compiler error

where what happens if you miss it
ds4_glm_reasoning_effort_text() switch with no default: → a new enumerator falls through to return NULL, silently dropping GLM's effort system message for that tier. -Wswitch warns, but there's no -Werror, so it scrolls past.
ds4_think_mode_enabled() An explicit == list. Omit a tier and thinking is silently disabled for it at ~25 call sites — the <think> opener, all three streaming reasoning channels, tool-marker gating.
think_mode_from_enabled() (ds4_server.c) effort == MAX ? MAX : HIGH — collapses anything above MAX before the renderer sees it. Must become a pass-through.

I map the new tier to GLM's existing "Reasoning Effort: Max", so GLM behaviour is unchanged.


4. The remap is inert until you fix the context gate

DS4_THINK_MAX_MIN_CONTEXT (393216) silently steps the top tier down below that context. On a smaller --ctx, every effort value except none renders an identical prompt — so the remap does nothing until this is addressed too.

If you make the floor settable, one gotcha: parse_int_arg() rejects v <= 0, so 0 — the value that disables the gate — is the one value that won't parse. parse_nonneg_int_arg() is the one you want.


Happy to open a PR, or just hand over the diff if you'd rather land your own — you got there first and I don't want to cut across it.

rell666 avatar Aug 02 '26 19:08 rell666

Damn so I just spent 30 hours of GPU time running benchmarks that silently slipped to low reasoning effort? No wonder it only barely outperformed the preview. I was a little disappointed.

Just to verify, if I put context over 384k and reasoning effort: max, I will get high reasoning effort this time when I run the benchmarks? Do you mind sharing the fix you've come up with? I wasn't able to gather exactly what code I need to change from these descriptions.

nazeshinjite avatar Aug 02 '26 21:08 nazeshinjite

@nazeshinjite yes, correct. Context needs to be above the threshold AND reasoning must be set to max to get high effort with 0731.

@rell666 thank you, I could implement it tomorrow (or actually today at my time zone). As for the reasoning effort map I also was thinking about either passing an option or alternatively set it through an environment var. However, if you got it done already you surely can open your PR, I don't mind (I am glad to see it working regardless of who has done it). Otherwise I'll do it happily, but later.

sleepless avatar Aug 02 '26 23:08 sleepless

@sleepless — on the preview-breakage problem you raised, that is exactly the thing that stopped us shipping a naive fix too, and I think it is avoidable. Sharing the design and, more usefully, the traps, since you said you may implement it yourself.

Don't renumber the enum — append.

Preview's max is 0731's high string. So any single fixed remap that makes max mean 0731's max necessarily sends preview users a prefix that checkpoint never saw. That is real and it is why the renumbering variant in this thread breaks preview.

What worked for us: add a fourth tier rather than remapping the existing three. DS4_THINK_ULTRA carries 0731's real max prefix, the existing values keep their meaning, and preview is untouched. Then one flag to choose the table:

--reasoning-effort-map {deepseek|legacy}     # default: deepseek

legacy reproduces today's behaviour exactly, so it is a one-flag revert rather than a rebuild. An env var would work just as well — the shape matters more than the mechanism.

Byte-exact against the live model, if it helps you verify your own build:

wire value prefix emitted = DeepSeek tier
none — (thinking off) non-thinking
minimal / low / medium none low
high / xhigh 476 B, sha256 f7a24f3b… high
max (unpatched) same 476 B string still high
max (patched, ULTRA) 528 B, sha256 53fb31b8… max

Three things that bite silently — none produces a compiler warning. These are the reason I am posting the design rather than just a diff; they will catch any implementation, not just ours.

  1. ds4_think_mode_enabled() is an == list. Omit your new tier and thinking is silently disabled at ~25 call sites — no error, the model just stops thinking.
  2. think_mode_from_enabled() does effort == MAX ? MAX : HIGH, which destroys any tier above MAX. A new top tier collapses straight back down unless this is updated.
  3. The GLM path renders effort as a system message rather than a prefix, and its switch has no default: — so a new enum value silently drops its effort text there. Worth checking against GLM5.2 specifically, since you mentioned you could not verify that one.

On the practical question @nazeshinjite asked: yes — on unpatched ds4, ctx above the threshold plus max gets you DeepSeek's high, not max. The genuine max tier is not reachable in any configuration, at any context length, with any flag. So a re-run on unpatched code produces another set that is one notch below its label. Sorry — that is the answer to the 30 GPU-hours.

Offer, with the condition stated honestly: we have this working on a branch (effort-tiers-0731), but it is based on ~80ebbc39 and I have not re-tested it against current main — there has been a lot of CUDA work since, and our box is tied up on an unrelated benchmark for about another day. I am happy to rebase, re-run the suite and open a PR after that. If you would rather just write it now with the above, please do — genuinely no ownership wanted here, I would just like the tier labels to mean what they say.

rell666 avatar Aug 04 '26 13:08 rell666