Repository navigation
test: compare Gemma 3 truncated-restore rows computed at the same prefill length - #3722
Conversation
…fill length Refs lablup#3652. On Metal the Gemma 3 truncated-restore test fails for Turbo4Asym at window 32, 32 tokens cut to 31, while it passes on CUDA. The test compared rows its donor computed in a 32-token prefill with rows the control computed in a 31-token prefill. On Metal a row's result depends on the total prefill length by the last bits: with no snapshot at all, in plain Fp16, a cold 32-token prefill gives rows 16 to 30 logits that differ from a cold 31-token prefill of the same tokens (48 against 47 tokens differ in rows 32 to 46, 64 against 63 in rows 48 to 62), at windows 32, 64 and 4096 alike. The comparison therefore measured the matmul, not the truncation. The donor now forwards the kept prefix and the dropped tokens as two calls, so the kept rows come out of the same forward the control runs. The byte-equality assertion is unchanged.
4a81964 to
2886959
Compare
|
Hardening review: no changes needed, merging as is. Reviewed against the PR body (no linked issue; the failure is reported in #3652). The nightly evidence matches: runs 46937282079 and 47171225366 on the macOS runner fail The change fixes a test defect, not a product regression. Truncated restore never promised bit-identity with a cold prefill whose rows came from a forward of a different length; that last-bit difference is the same one any prompt-cache hit carries. Splitting the donor's prefill at the cut makes the kept rows come from the same forward shape as the control, so the byte-equality assertion still isolates the truncation. The ring is still full at Validation on NVIDIA GB10 (CUDA, current main with no drift):
Metal could not be run here; the Metal pass relies on the author's run in the PR body. |
Summary
Refs #3652.
On macOS,
make verify-testfailsmodels::gemma3::gemma3_tests::quantized_snapshot::a_truncated_quantized_restore_reproduces_a_cold_prefill_of_the_prefix, which passes on CUDA (GB10). The test came in with #3498. It is not a product bug: the test compares against a reference whose bit-identity depends on the backend's matmul. This PR changes that one test; no code path changes.The nightly also failed two Turbo boundary-index tests in
mlxcel-core(cache::turbo::codebook::tests::device_boundary_indices_match_host_at_the_edgesandcache::turbo::quant::device_tests::device_pack_handles_boundary_ties_and_extremes). An earlier revision of this PR loosened those tests. #3686 has since fixed the cause in product code:boundary_indices_on_devicenow compares signed integer order keys, so Metal no longer flushes the subnormal inputs onto the zero midpoint. Both tests pass unchanged on currentmainon Metal, and their strict device == host assertion now guards that fix. That part has been dropped from this PR.Failing on
main(5bf7b8628), Apple M4, macOS 26.2,--features metal,accelerate:Cause
The failure is not caused by the snapshot, the truncation or Turbo4Asym. Comparing cold prefills directly, with no snapshot at all, on the same fixture in plain
Fp16, the logits that rows0..shortget from a cold prefill oflongtokens and from a cold prefill ofshorttokens are:long/shortOn Metal, a row's result therefore depends on the total length of the prefill it was computed in, by the last bits. A split prefill or any prompt-cache hit already has this effect; the restore did not introduce it. The test's donor prefilled all
storedtokens in one forward, so for(window, window - 1)the rows it kept came from a 32-token (or 64-token) forward, while the control computed them in a 31-token (63-token) forward. On CUDA those agree for these shapes, so the test passed there.At the previous MLX pin (
5a48f9cc) a two-operand f32matmulshowed the same thing in isolation. For a lower-triangularP(L x L) andV(L x 2), the firstL - 1rows ofP @ Vdiffered fromP[:L-1, :L-1] @ V[:L-1]atL= 32, 48 and 64, and not atL= 16. That probe was not re-run after #3685; the table above was re-measured at the current pin and is unchanged.Change
The donor now forwards the kept prefix (
tokens[..target]) and the dropped tokens (tokens[target..stored]) as two calls. The kept rows then come out of the same forward the control runs, so the bit-for-bit comparison measures the truncation and nothing else.windowtokens when the snapshot is taken, and the cut still has to drop rows that are in the buffer.6 -> 6(no second forward) and6 -> 1.a_restored_quantized_state_reproduces_a_cold_split_prefill_bit_for_bit, which compares like with like.a_truncated_gemma4_restore_cuts_every_populated_layer) feeds per-token K/V straight into the caches with no model forward, so it does not depend on prefill length. It passes on Metal.Mutation check (MLX
5a48f9cc): withkv_snapshot::truncate_rotatingchanged to return before trimming (the sliding layer keeps every stored row), the reworked test fails at its logits assertion and the other five tests in the module still pass. The mutation was reverted before the commit.CHANGELOG is not changed (test-only).
Verification
Apple M4 (10 cores, 16 GB), macOS 26.2, Xcode 26.6, rustc 1.97.1, MLX
6371f1ce.Before, on
main5bf7b8628:After, on this commit:
The 16 ignored tests in
models::gemma3carry#[ignore]attributes onmain(serial-MLX, checkpoint or IREE gated); this change adds or removes no#[ignore].The earlier revision of the test change passed on CUDA (NVIDIA GB10, sm_121, CUDA 13.0):
models::gemma374 passed, 0 failed, 16 ignored. The Gemma 3 hunk is byte-identical to that revision; the CUDA run was not repeated on this base.Limits
make verify-testwas not run on the Mac; only the two modules above.