Repository navigation
fix(test): bound iquestloop chunked prefill by measured bf16 noise - #2418
Merged
Merged
Conversation
check_chunked_prefill failed on GB10 at chunk 97 against a 0.25 single-pass bound. The divergence is bf16 precision, not a chunk-boundary bug: with every floating tensor promoted to f32 at load and MLX_ENABLE_TF32=0, chunk sizes 128/97/64/32 land within 2.1e-05 of the single-pass row, and mlxcel matches the f32 oracle to 4.7e-04 (the 1.7 to 1.9 bf16 oracle deltas and the rank 2/3 swap disappear). The real-checkpoint check now measures every chunk size before asserting, holds the greedy token and TIE_GAP-separated order, and bounds the top-5 logit delta at 1.0 (measured worst 0.625) and KL(single || chunked) at 0.015 (measured worst 0.0074). A new f32 synthetic test, chunked_prefill_matches_single_pass_past_the_window, compares every position at the 218-token, window-64 geometry and fails on a one-key cache slip and a one-position pass-2 RoPE slip, which stay inside bf16 noise on the checkpoint. Doc comments that blamed a quantized lm_head and f16 now name bf16 activations. Closes #2143
f32::max and the > comparisons skip NaN, so both chunked-prefill checks could pass on NaN rows, the failure this seam had before (#401/#408). Both now assert every logit is finite before comparing. The f32 synthetic test gains a 100 + 30 x 1 + 88 schedule, so a multi-token chunk is appended after single-token decode has wrapped the ring. Its docs no longer claim that a multi-token tail sees a wrapped ring. The parity file shares one top-k helper, and its docs now agree on the 1.87 oracle deviation and give the chunked routes' own distance from f32 (1.87 to 2.33). Refs #2143
inureyes
force-pushed
the
fix/issue-2143-iquest-chunked-prefill-bound
branch
from
October 16, 2026 01:52
f8f9c1f to
58b51d0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2143
Root cause: precision, not chunk-boundary logic
The chunked and single-pass routes use the same keys, offsets and masks; they round differently in bf16. Measured on this GB10 (
~/models/mlx/iquest-coder-v1-40b-loop-instruct-4bit,--test-threads=1, deterministic across runs and identical with and withoutMLXCEL_SDPA_DETERMINISTIC=1) with a temporary, uncommitted patch that promotes every bf16 tensor (1445 of them) to f32 at load:MLX_ENABLE_TF32=0Chunks 63 and 65 behave the same. The 1.7 to 1.8 oracle deltas and the rank swap that the issue pairs with this failure also come from bf16 activations. The 4-bit weights are not the cause, since the f32 run uses them too. Neither bf16 route is more accurate: KL(f32 || bf16 single) is 0.0047, and the chunked rows sit at 0.0041 to 0.0071.
The investigation comment on #2143 names the same mechanisms: short chunks take a different SDPA route, and the keys sit at different block offsets. Its proposed corrections (scoped cuDNN dispatch, alignment-preserving K/V padding) would narrow a precision gap, not fix a logic error, so they are left for a follow-up.
Change (tests only, no production change)
check_chunked_prefillmeasures all four chunk sizes before asserting and reports every failure. It keeps the greedy token and the TIE_GAP-separated order, and bounds the top-5 delta at 1.0 (measured worst 0.625) and KL(single || chunked) at 0.015 (measured worst 0.0074). The doc comment records the measurement table.chunked_prefill_matches_single_pass_past_the_window(synthetic, f32): 218 tokens, window 64, chunks 128/97/65/64/63/32/1, plus 100, then 30 single tokens, then 88 (a multi-token append after the ring has wrapped). It compares every position against a 1e-4 bound (clean max 5.4e-07). The existing 64+32 test checks only the last row and missed a one-key cache slip.f32::maxand the bound comparisons skip NaN, which is this seam's historical failure (fix(models): gemma4 sliding-window single-pass prefill degenerates to <pad> beyond the window #401/fix: harden sliding-window >window prefill across non-Gemma models; guard causal_attention windowed K/V slice #408).lm_headnow name bf16.What the bf16 bound can and cannot see (fault injection in
forward_pass2on continuation chunks)Validation
gpu-lock run -- target/test-fast/deps/iquestloopcoder_parity-<hash> --test-threads=1, run from$HOMEsomodels/mlx/...resolves.models::iquestloopcoder_testspasses 18/18. Clippy (--lib --tests -D warnings), fmt and the five contract checks pass.make verify-test-cudaworkspace gate (left to the merge gate).