Skip to content

test(core): guard the TF32 test pin and record its decode impact - #2132

Merged
inureyes merged 3 commits into
mainfrom
fix/issue-1065-tf32-closeout
Oct 6, 2026
Merged

inureyes merged 3 commits into
mainfrom
fix/issue-1065-tf32-closeout

Conversation

@inureyes

@inureyes inureyes commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

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+ (cuBLAS CUBLAS_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 pins MLX_ENABLE_TF32=0 in both lib test binaries, #1262/#1263 document it at the verify-test-cuda gate, #1196 added the attention kill switch (which does not affect these tests). This PR closes what remained:

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:

checkpoint weights result
plamo-2-1b f32 1 of 5 prompts diverges (after ~40 words), deterministic in both arms, 5/5 runs each; 38 tok/s both arms
llama-3.1-8b-bf16 f16 identical, 3 prompts x 2 runs
qwen2.5-0.5b-bf16 bf16 run-to-run variation in both arms alike, not attributable
qwen3-0.6b 4-bit run-to-run variation in both arms alike, not attributable

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=0 for f32-exact output.

Test plan

  • At origin/main 5211f58d, CUDA, --test-threads=1: the 4 mlxcel-core tests from fix(core): f32 matmul and single-query SDPA lose ~fp16 precision on M5, breaking four numeric tests #1065 pass by default and under MLX_ENABLE_TF32=1 (3 runs each). The 3 root-lib tests from the 2026-08-17 comment pass by default and fail 3/3 under MLX_ENABLE_TF32=1 (deepseek_v2 2.70e-4, florence2 1.43e-4)
  • New sentinel: pass by default and with =0, fail 3/3 under =1 (5.84e-3 vs 1e-4 bound)
  • After the change: layers::tests::chunked_, mla::decode::decode_tests, tf32_pin_tests all pass on CUDA
  • cargo fmt --check, cargo clippy -p mlxcel-core --lib --tests --features cuda -- -D warnings

Not verified on this host

Closes #1065

@inureyes inureyes added status:review Under review type:test Test related changes priority:high High priority area:core mlxcel-core: MLX FFI, primitives, KV cache, layers labels Oct 6, 2026
inureyes added a commit that referenced this pull request Oct 6, 2026
@inureyes inureyes added status:done Completed and removed status:review Under review labels Oct 6, 2026
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
inureyes force-pushed the fix/issue-1065-tf32-closeout branch from 46c77a8 to 8fe6575 Compare October 6, 2026 07:38
@inureyes
inureyes merged commit a41154e into main Oct 6, 2026
26 checks passed
@inureyes
inureyes deleted the fix/issue-1065-tf32-closeout branch October 6, 2026 08:21
@inureyes inureyes added this to the 0.8 milestone Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core mlxcel-core: MLX FFI, primitives, KV cache, layers priority:high High priority status:done Completed type:test Test related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(core): f32 matmul and single-query SDPA lose ~fp16 precision on M5, breaking four numeric tests

1 participant