Repository navigation
Description
Problem
On GB10 (sm_121, --features cuda, test-fast profile, --test-threads=1), iquestloopcoder_matches_the_float32_oracle fails in check_chunked_prefill (tests/iquestloopcoder_parity.rs:350-382), at the hard-coded 0.25 logit bound at line 376:
chunk 97: logit for token 5123 is 29.5, single-pass says 29.125
The failure is identical at the #1873 baseline 56d82fbc and at main a4974fab; neither the test nor src/models/iquestloopcoder*.rs changed between them, so it predates the ROCm routing work. It also fails with MLX_ENABLE_TF32=0, so it is not the TF32 class. Metal status is unknown.
The delta is 3 bf16 ulps at that magnitude, so it may be accumulated precision between chunked and single-pass prefill rather than a logic bug, but chunk 97 straddles the 64-token loop_window_size boundary, which is exactly where the pass-2 RotatingKVCache (kept + L keys) and the windowed mask from mlxcel_core::causal_attention (src/models/iquestloopcoder.rs:451-466) must agree. The earlier oracle sections pass, but their logged deltas grow past the window: up to 0.41 on the short prompt, about 1.7 to 1.8 on the 218-token prompt, with the 2nd and 3rd ranked tokens swapped against the f32 oracle. Look at both together.
Approach
Determine which it is: compare chunked against single-pass per layer (or run both in f32) for chunk sizes 128/97/64/32. A divergence that disappears in f32 is precision; one that persists, or that appears first at the window boundary, is a mask or cache-offset bug to fix in src/models/iquestloopcoder.rs.
Acceptance Criteria
- Root cause identified and stated in the PR: chunk-boundary logic or precision.
- Either chunked prefill is fixed to agree with single-pass within the test's tolerance on CUDA, or, if precision only, the tolerance is widened to a measured bound with the measurement and reason in the PR.
-
iquestloopcoder_paritypasses undermake verify-test-cudaon GB10.
Reproduce
cargo test -p mlxcel --profile test-fast --features cuda --test iquestloopcoder_parity --no-run
gpu-lock run --tag iquest-parity -- target/test-fast/deps/iquestloopcoder_parity-<hash> --test-threads=1
Activity
Jaeyeong-CHOI commentedon Oct 7, 2026
Investigation: attention dispatch and local-KV alignment, rather than missing window tokens
I investigated the
218-token single-pass versus97 + 97 + 24chunked case on DGX Spark GB10 (sm_121), using an instrumented checkout based oncb83045220de3fa3ead28d33447e9ffa66ba0ccf. The attention inputs are BF16, head dimension 128, local window 64; the alignment experiments used cuDNN 9.13.0 / frontend 1.16.0.Two distinct sources of numerical disagreement were isolated. This is an investigation report and proposed correction strategy, not a validated production fix.
1. Small-chunk dispatch changes the numerical path
In the first attention layer, the corresponding Q/K/V values agree, but the final 24-query chunk takes the unfused fallback while the larger calls use cuDNN. The existing small-masked-append routing is in
supports_sdpa_cudnn.Replaying the same captured Q/K/V, without model execution or cache updates:
The original-output replay gates passed byte-for-byte. Disabling cuDNN globally is not an equivalent fix: the fallback-only comparison still had 15 differing elements, with differences observed in its QK/probability/PV stages.
At whole-model level, route unification reduced the maximum full-versus-chunk difference across the final token's 76,800 logits from 0.625 to 0.1875 in this case, but did not eliminate it. This does not establish general output quality or complete model equivalence.
2. Cropping local KV changes physical key alignment, not the valid token set
After route unification, the first remaining traced divergence is pass 2, layer 0, local attention. Both layouts contain exactly the same valid 64-token windows and matching Q/K/V values. The two continuation chunks differ in 8,854 + 846 = 9,700 output elements.
The following controls distinguish length from placement:
0/64/128,2/130,3/131, and32/96formed exact-output groups. At fixed length 218, three masked dummy prefix slots reproduced the original placement's output; retaining all 131 real prefix tokens was unnecessary.Thus, in these captures, physical KV placement is causal; length alone and loss of required cache tokens do not explain the difference. Right-padding alone does not restore the original alignment.
3. Strongly supported arithmetic explanation, with a defined limit
A forward, 64-key-block online-softmax model, rounding the unnormalized exponentials to BF16 before the value multiplication while retaining the pre-quantization denominator, reproduced all 15,019 observed basis-V diagnostic output changes, including locations and signed deltas, with no extra changed locations. An independent CPU implementation agreed.
The same fixed model matched 1,239,008 of 1,239,040 original-V output elements. Removing only that intermediate BF16 rounding in the CPU model removed the tested placement-dependent differences.
This supports the mechanism: cropping changes block boundaries and running maxima; intermediate BF16 rounding makes the otherwise equivalent blockwise softmax computations numerically non-equivalent.
However, this is not an instruction-exact cuDNN reconstruction. The model was selected using the basis-V observations, not in a blind experiment. Those diagnostic outputs are not direct dumps of the original fused kernel's probability tensor. The remaining 32 elements are CPU-model-versus-cuDNN residuals, not the original 9,700 cropping differences; exact internal instructions and bitwise normalization statistics remain unresolved. Also, 64 is observed for this configuration, not a universal cuDNN tile-size contract.
Across 5,200 same-condition repeats in the earlier captured-input tests, no repeat-to-repeat output variation was observed. The evidence therefore supports path/layout-dependent precision here, rather than establishing the same failure as cuDNN #1412. This finite sample does not prove universal determinism.
Proposed correction and PR scope
S = cache.offset - returned_kv_len; prependS % Bfinite zero K/V slots and mask them out, with experimentally validatedB = 64here. Apply this atforward_pass2. Keep stored cache contents, offsets, RoPE, and the valid key set unchanged. This requires at most 63 extra slots, although concatenation/copy costs still need measurement. The minimal-size padded view and the combined whole-model change have not yet been validated on GPU; this is a candidate, not a ready-to-merge patch.causal_attentionsingle-query branch slices over-window KV again, removing such padding; a wrapped rotating cache may also return physical ring order. The multi-query formula cannot simply be applied to decode or a one-token tail.Before proposing a fix PR, I would require captured-input regression tests, correction/revert controls, chunk sizes around the 32-query dispatch and 64-key boundaries, one-token tails, append-after-ring-wrap coverage, full-model logits and continued decoding, and latency/peak-memory measurements. I would keep the existing tolerance unchanged during those comparisons rather than treating a relaxed bound as proof of a correction.
The investigation and independent numerical checks were AI-assisted. No combined production correction or performance improvement is claimed by this report.
fix(test): reject NaN in iquestloop chunked prefill checks
fix(test): bound iquestloop chunked prefill by measured bf16 noise
fix(test): reject NaN in iquestloop chunked prefill checks
fix(test): bound iquestloop chunked prefill by measured bf16 noise (l…