Repository navigation
test(core): guard the TF32 test pin and record its decode impact - #2132
Merged
Merged
Conversation
inureyes
added a commit
that referenced
this pull request
Oct 6, 2026
8 tasks
Issue #1065 was filed as an M5 precision defect. The cause is MLX's default MLX_ENABLE_TF32=1, which runs f32 GEMMs with 10-bit mantissa inputs on CUDA Ampere and later (cuBLAS FAST_TF32) as well as on Apple GPU generation 17 (NAX). #1260 already pins the variable to 0 in both lib test binaries. This change closes what was left. - Add tf32_pin_tests, an f32 GEMM (16x512x16, off MLX's gemv path) checked against an f64 host reference. On GB10 it passes with the pin and fails at 5.8e-3 against a 1e-4 bound under MLX_ENABLE_TF32=1. Before this, nothing in mlxcel-core went red on CUDA when the pin was lost: the four tests #1065 named stay green there under TF32 because their shapes use gemv and SDPA, not cuBLAS. - Correct both ctor doc comments, which said the breakage was Apple-only. - Print the measured divergence in the two remaining chunked-SDPA assertions. - Document MLX_ENABLE_TF32 in docs/environment-variables.md with the GB10 decode A/B, and stop naming the M5 attention kill switch as #1065's suspect. Decode A/B on GB10, greedy, 256 tokens: the f32 checkpoint plamo-2-1b changed output on 1 of 5 prompts, deterministically in both arms over 5 runs, at unchanged throughput. bf16, f16 and 4-bit checkpoints showed no difference attributable to the variable. Shipped numerics stay on the MLX default. Closes #1065
inureyes
force-pushed
the
fix/issue-1065-tf32-closeout
branch
from
October 6, 2026 07:38
46c77a8 to
8fe6575
Compare
18 tasks
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
#1065's title and "Hardware dependence" section are wrong: the failures are not M5-specific. The cause is MLX's default
MLX_ENABLE_TF32=1, which runs f32 GEMMs with 10-bit mantissa inputs on CUDA Ampere+ (cuBLASCUBLAS_COMPUTE_32F_FAST_TF32) and Apple GPU generation 17 (NAX). The M1 Ultra passed only because it has no TF32-class path. The main fix already landed: #1260 pinsMLX_ENABLE_TF32=0in both lib test binaries, #1262/#1263 document it at theverify-test-cudagate, #1196 added the attention kill switch (which does not affect these tests). This PR closes what remained:mlxcel-core/src/tf32_pin_tests.rs: an f32 GEMM (16x512x16, off MLX's gemv path) against an f64 host reference. Nothing inmlxcel-corewent red on CUDA when the pin was lost, because the four tests fix(core): f32 matmul and single-query SDPA lose ~fp16 precision on M5, breaking four numeric tests #1065 named pass on CUDA even under TF32 (their shapes use gemv/SDPA, not cuBLAS).src/lib.rsandmlxcel-core/src/lib.rsno longer say "Apple only".docs/environment-variables.md: newMLX_ENABLE_TF32row with the measured decode impact; theMLXCEL_METAL4_ATTENTIONrow no longer names the route as fix(core): f32 matmul and single-query SDPA lose ~fp16 precision on M5, breaking four numeric tests #1065's suspect.Tolerances are unchanged. Shipped numerics stay on the MLX default, per the existing policy (unit tests verify full-f32 algorithm equivalence; TF32 output is not f32 evidence).
Decision on production decode
GB10, greedy, 256 tokens, default vs
MLX_ENABLE_TF32=0, arms alternated:TF32 changes greedy output only where dense f32 GEMMs exist, which in practice means f32 checkpoints. On CUDA, MLX sends unbiased single-row matmuls to a gemv kernel the setting does not reach, so prefill-sized GEMMs are the likely site; that split is read from MLX source, not measured. The default stays; the docs tell operators to set
MLX_ENABLE_TF32=0for f32-exact output.Test plan
5211f58d, CUDA,--test-threads=1: the 4mlxcel-coretests from fix(core): f32 matmul and single-query SDPA lose ~fp16 precision on M5, breaking four numeric tests #1065 pass by default and underMLX_ENABLE_TF32=1(3 runs each). The 3 root-lib tests from the 2026-08-17 comment pass by default and fail 3/3 underMLX_ENABLE_TF32=1(deepseek_v2 2.70e-4, florence2 1.43e-4)=0, fail 3/3 under=1(5.84e-3 vs 1e-4 bound)layers::tests::chunked_,mla::decode::decode_tests,tf32_pin_testsall pass on CUDAcargo fmt --check,cargo clippy -p mlxcel-core --lib --tests --features cuda -- -D warningsNot verified on this host
MLX_ENABLE_TF32=0, and test(harness): pin f32 GEMMs to full precision, and accept minijinja's Python-style bools #1260 reported the suite green on M5 with the pin.MLX_ENABLE_TF32=1on M5 (expected from the NAX dispatch, not run).Closes #1065