Skip to content

docs(spec): record the temperature 0 block-history argmax flip (#2778) - #2868

Closed
hephaex wants to merge 6 commits into
lablup:mainfrom
hephaex:docs/2778-temperature-0-block-history-flip
Closed

hephaex wants to merge 6 commits into
lablup:mainfrom
hephaex:docs/2778-temperature-0-block-history-flip

Conversation

@hephaex

@hephaex hephaex commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

Closes #2778 (documentation deliverable; the issue's reproducer criterion stays open).

What this adds

  • docs/temperature-0-block-history-flip.md — the Explain the temperature 0 flip between plain and block-built KV history #2778 investigation recorded as a maintainer-reverifiable documentation artifact, following the docs/benchmarks.md "Judging a change that moves the numbers" method (byte-identity says only yes or no, so the comparisons are teacher-forced and gated on how decided the reference was).
  • scripts/matched_width_trace.sh + scripts/compare_matched_width.py — the matched-context trace harness (WIDTH=8, PREFILL=128, BLOCKS=48; width-1 references traced at PREFILL = 128 + j) and comparator that redo every Evidence 1 number.
  • CHANGELOG.md — a ### Known limitations entry under Unreleased.

Cause named, and why no code fix

Argmax decidedness flip. A block verification path builds the K/V of every row after the first with a different arithmetic path than a one-token decode step (the quantized projections run at M = block width, and MLX picks a kernel per M), so the logits differ at rounding scale; the argmax flips only where the reference's top two logits are tied or nearly tied, and the rest of the stream follows from that one token. This is the temperature 0 contract — every emitted token is the argmax of the logits the path computed — not a defect, so no code change is made. The conclusion is kept tentative: it covers the flips reproduced in the document, and it does not explain the issue's original 35-logit swing at position 197 (prompt text and KV mode of the original runs are not in the issue; those runs were on M1 Ultra, these on M1 Pro).

How issue #2778's acceptance criteria stand

  1. Target-only reproducer for the Qwen3 pos 197 swing — left open. The original report is not reproduced (see "Limits of this evidence" in the document).
  2. Cause named with evidence — done. Teacher-forced logit traces isolate the effect: at equal context a verify block moves the reference's own top-1 logit at rounding scale (Qwen3-0.6B-4bit, fp16 KV: 336 matched-context positions, 195 nonzero, p50 0.125, max 0.75), flips only exact ties (1 disagreement, reference top-two gap 0.0), and leaves row 0 — which sees only sequentially built context — matched on all 48 positions. Comparing blocks against width-1 runs at unmatched context lengths overstates the disagreement (309 of 336 nonzero, p50 0.375), which is a context-length confound, measured separately as a control arm (fresh cache vs 256-token history: 63.28% top-1 disagreement, largest gap 3.875). The one-token decode split itself is harmless (0/512 with and without it). Repeating a trace is bit-equal.
  3. Fix with reverted arm failing, or documented expected-behavior reason — done (the latter). "Why there is no code fix": bit-equality across M is not a property any quantized kernel set provides; chasing it gives up verify throughput for a guarantee docs/benchmarks.md already says is spent once the arithmetic path differs.
  4. Decision whether this blocks 0.8.0 — carried from the issue comment: does not block 0.8.0. Plain decode is unaffected; the release must list it as a known limitation and must not claim temp-0 speculative output matches plain decode. The CHANGELOG entry records that.

Repro anchors

  • Teacher-forced: cargo build --release --features metal,accelerate --example logit_trace, then logit_trace MODEL corpus_long.txt 8 48 8 128 plus the matched width-1 arms; scripts/matched_width_trace.sh + scripts/compare_matched_width.py in the repo.
  • End-to-end KV arms: mlxcel generate -m MODEL -p PROMPT -n 160 --temp 0 --seed 42 --kv-cache-mode {fp16,int8,fp16+turbo3,fp16+turbo4} --show-reasoning [--prompt-lookup] (documented in the document's Evidence 3 section with its normalization script).

Evidence for each number is a command recorded in the document.

hephaex and others added 6 commits October 20, 2026 15:58
Add `src/imagegen/` with the model-independent pieces shared by every
text-to-image and image-editing family: request and result types, the
checkpoint family probe, the flow-match Euler scheduler (dynamic and
static shift), latent patching and packing, the FLUX.2 VAE, the Z-Image
DiT blocks, the Qwen3 hidden-state conditioner, PNG output, and the
family registry (empty until a model issue registers a row).

Surfaces:
- `mlxcel generate-image` (generate and edit, -n, --seed, --gen-kwargs)
- `mlxcel-server --image-model` with `POST /v1/images/generations` and
  `POST /v1/images/edits`, served by a dedicated worker; without the flag
  both routes answer 501 naming it
- `Runtime::ImageGenerate` and `OutputKind::Image` in the registry
- `generate`/`serve` on an image checkpoint now point at
  `mlxcel generate-image` instead of failing with `model_type not found`

`Qwen3Model` gains `forward_all_hidden`, one added method that reuses the
existing blocks. Teacher-forced logit traces on Qwen3-0.6B-4bit before and
after are byte-identical.

Tests compare against the upstream Python (Blaizzy/mlx-vlm) through
committed fixtures; `tests/fixtures/generate_imagegen_fixtures.py`
regenerates them exactly. The real ERNIE-Image-Turbo VAE matches upstream
f32 to a relative RMS of 3e-6 (decode), 1.2e-6 (packed decode) and 3e-6
(encode). Upstream's `_match_conv_layout` leaves the encoder's RGB
`conv_in` in PyTorch layout, which breaks its encoder; this port decides
the layout once per checkpoint.

Refs lablup#2341
Add docs/image-generation.md (CLI, server routes, probe, shared building
blocks, precision decision, family registration, verification) and point to
it from the README and the environment variable reference.

Refs lablup#2341
Discard expired queued requests before GPU execution, cap output pixel counts and explicit diffusion steps, and replace the predictable output probe with atomic exclusive creation. Add regression coverage for deadline handling, request limits, existing files and symlinks.

Declare the four reproducible numerical fixtures with individual size ceilings and an explicit aggregate binary budget. Document the limits and the remaining inability to interrupt an already-running generation.

Refs lablup#2341

Refs lablup#2497
Document the test-only checkpoint directory, default lookup path, skip behavior and ignored-test invocation. Validate the current main merge tree with the environment-variable documentation guard and all 15 guard tests.

Refs lablup#2341

Refs lablup#2497
gelu_approx is the exact erf form, not the tanh-approximate GELU, and
gelu_sigmoid's doc pointed at a helper whose name does not exist in this
tree. Drop the stale reference and restate both docs.
…p#2778)

A temperature 0 run through a block verification path (--prompt-lookup or a
draft model) can leave the plain-decode stream near a logit tie: the verify
block builds post-first-row K/V at M = block width, a different quantized
kernel path than the one-token decode step, so the logits differ at rounding
scale and the argmax can flip where the reference's top two logits are tied
or nearly tied. This is the temperature 0 contract, not a defect; no code
change is made.

- docs/temperature-0-block-history-flip.md: the investigation, teacher-forced
  and end-to-end measurements, repro commands, and the limits of the evidence
  (the issue's original 35-logit swing at position 197 is not reproduced).
- scripts/matched_width_trace.sh, scripts/compare_matched_width.py: the
  matched-context (PREFILL = 128 + j) trace harness and comparator that redo
  every Evidence 1 figure.
- CHANGELOG: a Known limitations entry under Unreleased pointing at the
  document (lablup#2778, does not block 0.8.0).

Every number in the document is traceable to a command recorded there.
@hephaex

hephaex commented Nov 7, 2026

Copy link
Copy Markdown
Contributor Author

Superseded by #2879.

This branch was cut from a stale fork base and carried 5 unrelated commits (imagegen and others already merged upstream), which inflated the PR-visible diff to 70 files / +10430. Rather than rewrite published history, the single intended commit was replayed onto current upstream/main (f45a92cc) and opened as #2879, whose diff is exactly 4 files / +446.

Closing this one. Nothing here is lost: the contents live in #2879.

@hephaex hephaex closed this Nov 7, 2026
@inureyes inureyes added status:done Completed type:docs Documentation improvements or additions priority:medium Medium priority area:core mlxcel-core: MLX FFI, primitives, KV cache, layers labels Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core mlxcel-core: MLX FFI, primitives, KV cache, layers priority:medium Medium priority status:done Completed type:docs Documentation improvements or additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Explain the temperature 0 flip between plain and block-built KV history

2 participants