Repository navigation
test: make three Metal-only nightly failures backend-correct - #3722
Open
Jaeyeong-CHOI wants to merge 1 commit into
Open
Jaeyeong-CHOI wants to merge 1 commit into
Jaeyeong-CHOI wants to merge 1 commit into
Conversation
Refs lablup#3652. The macOS nightly fails three tests that pass on CUDA; none is a product bug. The Turbo boundary-index tests (codebook edges, Turbo4 device pack) put the smallest positive subnormal beside the codebook's zero midpoint. Metal's GPU compare flushes subnormals to zero, so the device gives that input the lower index where the host gives the upper one. The two neighbouring centroids are equally far from such an input up to twice its magnitude, so the quantization error is unchanged. The tests now require the host rule on the inputs as given or, on a flushing backend, on the inputs with subnormals flushed; every other input is still held to the host rule exactly, and each test asserts the two expectations differ. The doc comment of boundary_indices_on_device names the exception. The Gemma 3 truncated-restore 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 (32 against 31 tokens differ in rows 16 to 30 in plain Fp16 with no snapshot; an f32 matmul shows the same at contraction length 32 against 31), so the comparison measured the matmul, not the truncation. The donor now forwards the kept prefix and the dropped tokens as two calls, and the byte-equality assertion is unchanged.
This branch has not been deployed
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.
Summary
Refs #3652.
make verify-teston macOS fails three tests that pass on CUDA (GB10). They came in with #3497, #3500 and #3498. None of the three is a product bug: two assert a host/device agreement on subnormal inputs that a flush-to-zero backend cannot give, and one compares against a reference whose bit-identity depends on the backend's matmul. This PR changes the three tests and one doc comment; no code path changes.Failing on
main(beedecbb1), Apple M4, macOS 26.2,--features metal,accelerate:mainmlxcel-corecache::turbo::codebook::tests::device_boundary_indices_match_host_at_the_edgescodebook.rs:997"bits 3 head_dim 64": device index 3, host index 4 at the two positions holdingf32::from_bits(1)mlxcel-corecache::turbo::quant::device_tests::device_pack_handles_boundary_ties_and_extremesquant/device_tests.rs:124"boundary indices d=64, t=1"mlxcelmodels::gemma3::gemma3_tests::quantized_snapshot::a_truncated_quantized_restore_reproduces_a_cold_prefill_of_the_prefixgemma3_quantized_snapshot_tests.rs:183"Turbo4Asym, window 32, 32 tokens cut to 31: the suffix logits differ from a cold prefill of the prefix"1 and 2: subnormals on Metal
boundary_indices_on_devicecounts the codebook midpoints strictly below each input withgreater(x[..., None], boundaries). The symmetric Lloyd-Max codebooks (3- and 4-bit) have a midpoint at exactly0.0. Metal's GPU compare flushes subnormals to zero, sof32::from_bits(1) > 0.0is false on the device: the smallest positive subnormal sits on the zero midpoint and takes the lower index, while the host'spartition_point(|b| b < v)gives it the upper one. The two tests putboundary.next_up()next to every midpoint (and the codebook test also has±f32::from_bits(1)directly), so both hit this at the zero midpoint.This does not matter numerically. The two centroids such an input can land on are equally far from it up to twice its magnitude, which is below
f32::MIN_POSITIVE, so the quantization error is the same either way. Making the device bit-identical to the host here would mean comparing on integer bit patterns in the cache's hot quantize path to fix a case activations do not produce. The tests now accept exactly two outcomes:The whole index vector has to equal one of the two, so every non-subnormal input (both zeros, NaN, the infinities, the finite extremes, each boundary and the floats beside it) is still held to the host rule exactly. Each test also asserts the two expectations differ, so the subnormal case cannot quietly become vacuous. In the codebook test the hand-stated rule ("one float above a boundary takes the upper index") expects the lower index only for the subnormal above the zero midpoint on a backend that was seen to flush. The doc comment of
boundary_indices_on_devicesaid the device rule "agrees with the host function on every input"; it now names this exception. The existing bullets are kept.3: Gemma 3 truncated restore
The failure is not caused by the snapshot, the truncation or Turbo4Asym. I ran the same comparison over more cases (a throwaway test, not committed) on the same fixture:
Fp16, whichTABLESdoes not include, fails the same way: 32 cut to 31 and 64 cut to 63 differ, as do 32 to 30 and 64 to 62.Int8passes 32 to 31, andTurbo4Asympasses 64 to 63, thoughFp16fails both cuts. The quantized layers evidently absorb the difference in those two cases; I did not trace why.So I compared cold prefills directly, with no snapshot at all. On the same
Fp16fixture, the logits that rows0..shortget from a cold prefill oflongtokens and from a cold prefill ofshorttokens are:long/shortA two-operand f32
matmulshows the same thing in isolation: for a lower-triangularP(L x L) andV(L x 2), the firstL - 1rows ofP @ Vdiffer fromP[:L-1, :L-1] @ V[:L-1]in 21, 27 and 26 elements atL= 32, 48 and 64, and in none atL= 16. In f16, and forsoftmax, none differ. A row's result therefore depends on the total length of the prefill it was computed in, on Metal, by the last bits. This is the same effect a split prefill or any prompt-cache hit already has; the restore did not introduce it. The test's donor prefilled allstoredtokens 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.The donor now forwards the kept prefix (
tokens[..target]) and the dropped tokens (tokens[target..stored]) as two calls. The kept rows are then computed by the same forward the control runs, so the bit-for-bit comparison measures the truncation and nothing else. The assertion is unchanged (byte equality of the suffix logits). The ring is still full atwindowtokens when the snapshot is taken, and the cut still has to drop rows that are in the buffer. A donor that took its rows from one forward is still covered for a restore without a cut bya_restored_quantized_state_reproduces_a_cold_split_prefill_bit_for_bit, which compares like with like.Mutation check: with
kv_snapshot::truncate_rotatingchanged to return before trimming (the sliding layer keeps every stored row), the reworked test fails at its logits assertion (gemma3_quantized_snapshot_tests.rs:195). The other five tests in the module still pass. The mutation was reverted before the commit.Checked, per the review list
f32::MIN/MAX,±f32::MIN_POSITIVEand±f32::from_bits(1), at head dims 64/128/256 and t = 1 and 4096. The Gemma 3 test keeps its four cuts, including6 -> 6(no second forward) and6 -> 1.flush_subnormalsis linear in the input.boundary_indices_on_deviceis used byquant3::quantize_v_turbo3andquant::pack_rotated_turbo4; its behaviour is unchanged. The other device-vs-host tests incache::turbo(includingquant3'scoordinates_on_every_boundary_take_the_lower_indexand the dense sweep) have no subnormal input and pass on Metal unchanged. The Gemma 4 counterpart (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, and it passes on Metal.[Unreleased]section onmainat the moment.Verification
Apple M4 (10 cores, 16 GB), macOS 26.2, Xcode 26.6 (Metal 32023.883), rustc 1.97.1, MLX
5a48f9cc.Before, on
mainbeedecbb1:After, on this commit:
On CUDA, NVIDIA GB10 (sm_121), CUDA 13.0, same commit tree (
3861d88f):The two
cache::turbocounts are not comparable: the CUDA filtercache::turboalso matches thecache::turbo_testsmodule, whichcache::turbo::on Metal does not (with the wider filter the Metal build lists 211 tests).The 16 ignored tests in
models::gemma3carry#[ignore]attributes onmain(serial-MLX, checkpoint or IREE gated); this change adds or removes no#[ignore].Limits
make verify-testwas not run on the Mac; the CUDA run above covers the two touched modules, not the whole suite.