You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Explain the temperature 0 flip between plain and block-built KV history #2778
area:coremlxcel-core: MLX FFI, primitives, KV cache, layerspriority:mediumMedium prioritystatus:readyReady to be worked ontype:bugBug fixes, error corrections, or issue resolutions
Found while reviewing PR #2768 (full-model drafter, #2757). Temperature 0 runs with a block verification path can leave the plain-decode stream. On the two prompts checked, --prompt-lookup with no draft model emits the same divergent stream as the drafter (Qwen3 copy at 3 widths, Llama prose at 2), and a target-only replay with block-built KV history reproduces the flip. So draft-cache misalignment is not the cause, and the behavior exists without a drafter.
Two distinct cases
Llama prose at position 137 is a true near-tie (gap 0.016).
Qwen3 copy at position 197 is not: plain decode prefers its token by 2.0, while most block histories prefer the other by about 35, and the plain stream is the one that leaves the copied text. The Qwen3 swing is unexplained.
Measured on M1 Ultra Metal. Other backends not checked. The root cause is unknown.
Acceptance Criteria
A target-only reproducer for the Qwen3 position 197 swing, comparing the logits and KV contents of plain and block-built histories.
The cause named with evidence, using the teacher-forced logit trace method in docs/benchmarks.md (section "Judging a change that moves the numbers").
Either a fix with its reverted arm failing, or a documented reason it is expected.
A decision on whether this blocks 0.8.0, stated in this issue.
Decision: this does not block 0.8.0. It stays open as a post-release follow-up, and the root cause is still unknown. The 0.8.0 release notes should list it as a known limitation and should not claim that temperature 0 speculative output matches plain decode.
State so far:
Plain decode is not affected. The flip appears only with a block verification path (prompt lookup or a draft model).
Llama prose at position 137 is a near-tie (gap 0.016), which rounding could explain. This has not been confirmed.
Qwen3 copy at position 197 is unexplained. Plain decode prefers its token by 2.0, while most block histories prefer the other by about 35. That is too large to attribute to rounding, so a real difference in KV history is still possible. The plain stream is the one that leaves the copied text, so which side is wrong is also open.
Limits of this evidence: two prompts, M1 Ultra Metal only. How often it happens, how it behaves on other backends, and whether it predates #2768 have not been measured.
Revisit this decision if a release is going to promise that output match, or if a reproducer shows corrupted KV contents.
Next step: the target-only Qwen3 position 197 reproducer in the acceptance criteria, comparing logits and KV contents of plain and block-built histories.
Documentation artifact opened as PR #2868 (docs/temperature-0-block-history-flip.md).
Status against the acceptance criteria:
Target-only reproducer for the pos 197 swing — left open. Not reproduced: the prompt text and KV mode of the original runs are not in the issue, and the runs here are on M1 Pro, not M1 Ultra. The document's "Limits of this evidence" section keeps the reopening trigger (a reproducer that shows corrupted KV contents).
Cause named with evidence — done (PR docs(spec): record the temperature 0 block-history argmax flip (#2778) #2868). Argmax decidedness flip: teacher-forced traces show a verify block moves the reference's own top-1 logit at rounding scale at equal context (Qwen3-0.6B-4bit, fp16 KV, 336 matched positions: 195 nonzero, p50 0.125, max 0.75), flips only exact ties (1 disagreement, reference top-two gap 0.0), and row 0 — which sees only sequentially built context — matches on all 48 positions. Unmatched-context comparisons overstate the disagreement (309 of 336 nonzero, p50 0.375) — a measured context-length confound, with a fresh-cache-vs-history control arm at 63.28% top-1 disagreement. The single-token decode split is harmless (0/512).
No code fix, documented as expected behavior — done. Bit-equality across M is not a property any quantized kernel set provides; docs/benchmarks.md says byte-identity is spent once the arithmetic path differs.
Does not block 0.8.0 (unchanged from the earlier decision). CHANGELOG Unreleased now carries a Known limitations entry; release notes must not claim temp-0 speculative output matches plain decode.
Updated: the spec/analysis is now in #2879 (single commit replayed onto current upstream/main; diff is 4 files / +446 — docs/temperature-0-block-history-flip.md plus two read-only analysis scripts). #2868 was closed as superseded because it carried unrelated commits from a stale fork base.
Status of the acceptance criteria is unchanged: the temperature-0 block-built-vs-plain KV history flip is characterized and reproducible, but criterion 1 (a code-level fix) remains open.
Correction on the acceptance-criteria framing, and current status.
The Nov 7 comment above and the PR #2879 body both describe criterion 1 as "a code-level fix". That is not what the issue asks for. Criterion 1 reads: a target-only reproducer for the Qwen3 position 197 swing, comparing the logits and KV contents of plain and block-built histories. It is a reproducer, and it covers KV contents as well as logits. Reading it as a fix changes what "done" means for the whole issue.
Related: #2879's body now reads Refs #2778 rather than Closes #2778. It was Closes, which would have auto-closed this issue on merge while criterion 1 is unmet. I updated the PR body to state criterion 1 as still open, so merging the docs change no longer closes this issue.
Status against the four criteria, stated plainly:
Target-only reproducer for pos 197, comparing logits and KV contents — open. Not delivered. The reporter's Nov 1 comment is the blocker and it is accurate: the original report names the prompt only as Qwen3 copy, with no token ids, no text and no length, and the only stated measurement condition is M1 Ultra Metal, with other backends unchecked. A byte-for-byte KV comparison cannot be reconstructed from that without the prompt, so the logits half is reproducible from the issue text and the KV half is not. The reproduction attempts so far are on M1 Pro, not M1 Ultra.
Cause named with evidence via the teacher-forced logit trace method — done, in docs/temperature-0-block-history-flip.md.
Fix with reverted arm failing, or documented reason it is expected — done: documented as expected temperature-0 behavior.
Whether this blocks 0.8.0 — recorded: it does not.
Two further findings from reading the cache and serialization paths while specifying the criterion 1 harness, both independently of the pos 197 question:
extract_rotating_cache_entry (src/distributed/kv_cache_serde/serialize.rs:120-137) passes cache.keys and cache.values straight through with no slice call, so it returns the whole pre-allocated ring buffer, unsliced, including unwritten slots. Its own test (tests.rs:543-544) asserts shape[2] >= 3 against a RotatingKVCache::new(4) after writing 3 tokens, with the comment "seq_len may be up to max_size (4)" — that lenient assertion is only satisfiable because the returned buffer is the full ring, not the 3 live tokens. The ring origin is not externally observable, so any consumer comparing KV bytes has to map the live window via logical_start() / visible_len() itself. As a transfer path this is fine, since the receiver restores with offset = live_len, live_start = 0; as a comparison surface it silently includes padding.
SerializableCacheEntry (types.rs:207-212) has no mode field, and ChunkedKVCache exposes neither a mode field nor a mode method. So an extracted entry cannot be checked against the mode that produced it on that path.
Neither of those is a claim about the pos 197 cause. They are things that will have to be handled by whoever builds the criterion 1 harness, and they are worth knowing before someone assumes the existing extractor gives a directly comparable slice.
Criterion 1 (target-only reproducer, logits and KV contents) — measurement
Ran a target-only reproducer that builds the same history two ways and compares
both the logits and the KV contents at every position. Posting the result
because it is a negative result for the reported flip, with a positive result
for the underlying KV divergence, and because the "how do we explain the
swing" question now has a measured answer rather than a hypothesis.
Setup
examples/kv_history_divergence.rs, built with --features metal,accelerate.
Qwen3-0.6B-4bit, M1 Pro, # device Apple GPU (Metal), 64-token context. # arm_repeats_identical true — the harness re-runs the incremental arm
in-process at every traced position and requires the logits to match exactly,
otherwise it bails with "negative control failed". Note what that control does
and does not cover: it compares logits, not KV bytes, and it proves only
that one arm reproduces itself, not that both arms wrote the same tokens into
the same slots.
The harness takes <model> <corpus> <WIDTH> <CONTEXT> <MAX_N>: the plain arm
appends one token at a time and the block arm appends WIDTH at a time, both
building the same history. It only traces positions whose KV actually differs,
so positions_traced counts diverging positions, not the whole span.
Negative control passes
Holding context = 64, max_n = 64 and the corpus fixed, widths 1, 2, 4 and 8
all report zero differing KV bytes (kv_diff_bytes = 0, no traced position
with any difference). The harness does not manufacture divergence.
W
differing KV bytes
kv_max_abs
kv_rms_rel max
max logit delta
1 / 2 / 4 / 8
0
0
0
0
16
7946151
3.801758
0.028196
0.343750
32
4778963
3.801758
0.028196
0.343750
64
3201507
3.750000
0.027346
0.218750
The jump from W = 8 to W = 16 is a discontinuity, not a trend — what a
kernel-selection threshold looks like. W = 64 is measurably distinct from W = 32, so W = 32 is not saturation. (Caveat: each arm traces max_n / W
positions, so the columns maximise over different position sets; the table shows
the discontinuity and width-dependence, not an ordered sweep.)
The divergence is real and large
At a 448-token span with W = 16: 28 positions carry differing KV bytes, kv_rms_rel up to 0.0455, up to 73.97% of KV elements perturbed, and a
whole-vocabulary logit delta up to 2.757812 (pos 352).
That is the same order as the 2.0 plain-side preference in the report, so magnitude was never the missing piece — and yet positions_with_flip is 0.
Why there is no flip: measured margin, not magnitude
An argmax only changes when the perturbation exceeds the top-1/top-2 gap. I
added a d_top1 column — the shift at the incremental arm's own winning logit,
rather than the max over all 151936 of them:
pos
d_top1
margin_inc
d_top1 / margin
max_abs_delta
352
0.500
12.000
4.17%
2.757812
448
0.375
6.875
5.45%
0.437500
Across the 28 diverging positions the top-1 perturbation consumes at most 5.455% of the margin (pos 448). Because d_top1 is signed, the honest
summary uses its magnitude: mean 1.53% of margin over all 28 positions, 2.38% over the 18 where it is non-zero. margin_consumed_positions = 0. At
pos 352 the entire 2.76 of whole-vocabulary motion misses the top-1 logit,
which moves 0.5 against a 12.0 lead.
Conclusion
On this corpus, not flipping is the correct expected outcome, not an
unexplained anomaly. The reported 2.0-versus-35 preference reversal therefore
cannot be an argmax contest at this margin scale; it needs something this
harness does not exercise — a restructured upper vocabulary, the original
prompt, or a different KV mode.
Two limits that must travel with this result:
The original prompt is unpublished. The report names it only as Qwen3 copy — no text, no token ids, no length — and states only "M1 Ultra Metal".
Position 197's original swing is not reproduced, and everything here is
M1 Pro with a substitute corpus.
The int8-KV hypothesis is untestable on Qwen3 through this path. It does
not own its KV caches (examples/logit_trace/kv_mode.rs:66-68 raises "this
model does not own its KV caches"), so the dump reads harness-owned make_caches() caches and no storage mode can be installed.
Methodological note
The first version of this column compared the whole-vocabulary maximum against
the top-1 gap and reported margin_consumed = true at pos 64 (delta 0.21875 vs
a 0.125 gap) while flip stayed false — a false positive from comparing
quantities on different supports. The exact test uses |log_blk[ai] - log_inc[ai]| > margin_inc, which drops the count from 1 to 0.
If anyone reuses the harness, note the layout is now 17 columns (d_top1 is
field 11, flip is field 17); the TSV carries a # columns self-description
that matches the emitted fields.
area:coremlxcel-core: MLX FFI, primitives, KV cache, layerspriority:mediumMedium prioritystatus:readyReady to be worked ontype:bugBug fixes, error corrections, or issue resolutions
Activity
inureyes commentedon Nov 1, 2026
Decision: this does not block 0.8.0. It stays open as a post-release follow-up, and the root cause is still unknown. The 0.8.0 release notes should list it as a known limitation and should not claim that temperature 0 speculative output matches plain decode.
State so far:
--prompt-lookupwithout a draft model and a target-only replay with block-built KV history both reproduce it.proseat position 137 is a near-tie (gap 0.016), which rounding could explain. This has not been confirmed.copyat position 197 is unexplained. Plain decode prefers its token by 2.0, while most block histories prefer the other by about 35. That is too large to attribute to rounding, so a real difference in KV history is still possible. The plain stream is the one that leaves the copied text, so which side is wrong is also open.Limits of this evidence: two prompts, M1 Ultra Metal only. How often it happens, how it behaves on other backends, and whether it predates #2768 have not been measured.
Revisit this decision if a release is going to promise that output match, or if a reproducer shows corrupted KV contents.
Next step: the target-only Qwen3 position 197 reproducer in the acceptance criteria, comparing logits and KV contents of plain and block-built histories.
hephaex commentedon Nov 6, 2026
Documentation artifact opened as PR #2868 (
docs/temperature-0-block-history-flip.md).Status against the acceptance criteria:
Mis not a property any quantized kernel set provides;docs/benchmarks.mdsays byte-identity is spent once the arithmetic path differs.hephaex commentedon Nov 7, 2026
Updated: the spec/analysis is now in #2879 (single commit replayed onto current
upstream/main; diff is 4 files / +446 —docs/temperature-0-block-history-flip.mdplus two read-only analysis scripts). #2868 was closed as superseded because it carried unrelated commits from a stale fork base.Status of the acceptance criteria is unchanged: the temperature-0 block-built-vs-plain KV history flip is characterized and reproducible, but criterion 1 (a code-level fix) remains open.
chore(scripts): make compare_matched_width.py executable (lablup#2778)
docs(changelog): record the lablup#2778 caveat under Unreleased
hephaex commentedon Nov 7, 2026
Correction on the acceptance-criteria framing, and current status.
The Nov 7 comment above and the PR #2879 body both describe criterion 1 as "a code-level fix". That is not what the issue asks for. Criterion 1 reads: a target-only reproducer for the Qwen3 position 197 swing, comparing the logits and KV contents of plain and block-built histories. It is a reproducer, and it covers KV contents as well as logits. Reading it as a fix changes what "done" means for the whole issue.
Related: #2879's body now reads
Refs #2778rather thanCloses #2778. It wasCloses, which would have auto-closed this issue on merge while criterion 1 is unmet. I updated the PR body to state criterion 1 as still open, so merging the docs change no longer closes this issue.Status against the four criteria, stated plainly:
Qwen3 copy, with no token ids, no text and no length, and the only stated measurement condition is M1 Ultra Metal, with other backends unchecked. A byte-for-byte KV comparison cannot be reconstructed from that without the prompt, so the logits half is reproducible from the issue text and the KV half is not. The reproduction attempts so far are on M1 Pro, not M1 Ultra.docs/temperature-0-block-history-flip.md.Two further findings from reading the cache and serialization paths while specifying the criterion 1 harness, both independently of the pos 197 question:
extract_rotating_cache_entry(src/distributed/kv_cache_serde/serialize.rs:120-137) passescache.keysandcache.valuesstraight through with noslicecall, so it returns the whole pre-allocated ring buffer, unsliced, including unwritten slots. Its own test (tests.rs:543-544) assertsshape[2] >= 3against aRotatingKVCache::new(4)after writing 3 tokens, with the comment "seq_len may be up to max_size (4)" — that lenient assertion is only satisfiable because the returned buffer is the full ring, not the 3 live tokens. The ring origin is not externally observable, so any consumer comparing KV bytes has to map the live window vialogical_start()/visible_len()itself. As a transfer path this is fine, since the receiver restores withoffset = live_len, live_start = 0; as a comparison surface it silently includes padding.SerializableCacheEntry(types.rs:207-212) has nomodefield, andChunkedKVCacheexposes neither amodefield nor a mode method. So an extracted entry cannot be checked against the mode that produced it on that path.Neither of those is a claim about the pos 197 cause. They are things that will have to be handled by whoever builds the criterion 1 harness, and they are worth knowing before someone assumes the existing extractor gives a directly comparable slice.
hephaex commentedon Nov 7, 2026
Criterion 1 (target-only reproducer, logits and KV contents) — measurement
Ran a target-only reproducer that builds the same history two ways and compares
both the logits and the KV contents at every position. Posting the result
because it is a negative result for the reported flip, with a positive result
for the underlying KV divergence, and because the "how do we explain the
swing" question now has a measured answer rather than a hypothesis.
Setup
examples/kv_history_divergence.rs, built with--features metal,accelerate.Qwen3-0.6B-4bit, M1 Pro,
# device Apple GPU (Metal), 64-token context.# arm_repeats_identical true— the harness re-runs the incremental armin-process at every traced position and requires the logits to match exactly,
otherwise it bails with "negative control failed". Note what that control does
and does not cover: it compares logits, not KV bytes, and it proves only
that one arm reproduces itself, not that both arms wrote the same tokens into
the same slots.
The harness takes
<model> <corpus> <WIDTH> <CONTEXT> <MAX_N>: the plain armappends one token at a time and the block arm appends
WIDTHat a time, bothbuilding the same history. It only traces positions whose KV actually differs,
so
positions_tracedcounts diverging positions, not the whole span.Negative control passes
Holding
context = 64,max_n = 64and the corpus fixed, widths 1, 2, 4 and 8all report zero differing KV bytes (
kv_diff_bytes = 0, no traced positionwith any difference). The harness does not manufacture divergence.
Wkv_max_abskv_rms_relmaxThe jump from
W = 8toW = 16is a discontinuity, not a trend — what akernel-selection threshold looks like.
W = 64is measurably distinct fromW = 32, soW = 32is not saturation. (Caveat: each arm tracesmax_n / Wpositions, so the columns maximise over different position sets; the table shows
the discontinuity and width-dependence, not an ordered sweep.)
The divergence is real and large
At a 448-token span with
W = 16: 28 positions carry differing KV bytes,kv_rms_relup to 0.0455, up to 73.97% of KV elements perturbed, and awhole-vocabulary logit delta up to 2.757812 (pos 352).
That is the same order as the 2.0 plain-side preference in the report, so
magnitude was never the missing piece — and yet
positions_with_flipis0.Why there is no flip: measured margin, not magnitude
An argmax only changes when the perturbation exceeds the top-1/top-2 gap. I
added a
d_top1column — the shift at the incremental arm's own winning logit,rather than the max over all 151936 of them:
d_top1margin_incd_top1/ marginmax_abs_deltaAcross the 28 diverging positions the top-1 perturbation consumes at most
5.455% of the margin (pos 448). Because
d_top1is signed, the honestsummary uses its magnitude: mean 1.53% of margin over all 28 positions,
2.38% over the 18 where it is non-zero.
margin_consumed_positions = 0. Atpos 352 the entire 2.76 of whole-vocabulary motion misses the top-1 logit,
which moves 0.5 against a 12.0 lead.
Conclusion
On this corpus, not flipping is the correct expected outcome, not an
unexplained anomaly. The reported 2.0-versus-35 preference reversal therefore
cannot be an argmax contest at this margin scale; it needs something this
harness does not exercise — a restructured upper vocabulary, the original
prompt, or a different KV mode.
Two limits that must travel with this result:
Qwen3 copy— no text, no token ids, no length — and states only "M1 Ultra Metal".Position 197's original swing is not reproduced, and everything here is
M1 Pro with a substitute corpus.
not own its KV caches (
examples/logit_trace/kv_mode.rs:66-68raises "thismodel does not own its KV caches"), so the dump reads harness-owned
make_caches()caches and no storage mode can be installed.Methodological note
The first version of this column compared the whole-vocabulary maximum against
the top-1 gap and reported
margin_consumed = trueat pos 64 (delta 0.21875 vsa 0.125 gap) while
flipstayedfalse— a false positive from comparingquantities on different supports. The exact test uses
|log_blk[ai] - log_inc[ai]| > margin_inc, which drops the count from 1 to 0.If anyone reuses the harness, note the layout is now 17 columns (
d_top1isfield 11,
flipis field 17); the TSV carries a# columnsself-descriptionthat matches the emitted fields.
docs: scope the lablup#2778 flip analysis to what was measured
docs(spec): record the temperature 0 block-history argmax flip (#2879)
fix(examples): decode KV by dtype and fail loudly in kv_history_diver…
docs(2778): land the KV-contents reproducer and its spec (#3077)