You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] M5 float32 precision issue since 0.30.0 #3534
Describe the bug
On Apple M5, float32 matmul / sdpa have lower precision than on M4 (verified on multiple machines).
This regression first turned up in version 0.30, 0.29.4 is still fine.
To Reproduce
Running the script below on M4 gives
hip: Apple M4
macOS: 26.3.1
torch version: 2.11.0
mlx version: 0.31.2
device: Device(gpu, 0)
max abs diff vs torch CPU: 3.815e-05
mean abs diff: 2.968e-06
while on M5 the diff is much larger:
chip: Apple M5
macOS: 26.3.1
torch version: 2.11.0
mlx version: 0.31.2
device: Device(gpu, 0)
max abs diff vs torch CPU: 5.196e-02
mean abs diff: 9.812e-03
Awesome, that solves the issue, thanks!
(For future readers: This needs to be set before running any MLX computation, seems like the env var is cached).
python -c "
import mlx.core as mx, torch, numpy as np, platform, subprocess, os
os.environ['MLX_ENABLE_TF32']='0'
chip = subprocess.run(['sysctl', '-n', 'machdep.cpu.brand_string'],
capture_output=True, text=True).stdout.strip()
torch.manual_seed(0)
a = torch.randn(256, 256, dtype=torch.float32)
b = torch.randn(256, 256, dtype=torch.float32)
ref = a @ b
out = np.array(mx.array(a.numpy()) @ mx.array(b.numpy()))
diff = (torch.from_numpy(out) - ref).abs()
print(f'chip: {chip}')
print(f'macOS: {platform.mac_ver()[0]}')
print(f'torch version: {torch.__version__}')
print(f'mlx version: {mx.__version__}')
print(f'device: {mx.default_device()}')
print(f'max abs diff vs torch CPU: {diff.max().item():.3e}')
print(f'mean abs diff: {diff.mean().item():.3e}')
"
results in
chip: Apple M5
macOS: 26.3.1
torch version: 2.11.0
mlx version: 0.31.2
device: Device(gpu, 0)
max abs diff vs torch CPU: 3.815e-05
mean abs diff: 2.968e-06
This is because of Neural Accelerators kicking in, in short it is Apple's equivalent of NVIDIA Tensor Cores which trade precision for much better performance. I'm closing this issue since it is expected behavior, and what other frameworks do by default.
Activity
zcbenz commentedon May 12, 2026
Can you try running with environment variable
MLX_ENABLE_TF32=0?priorphil commentedon May 13, 2026
Awesome, that solves the issue, thanks!
(For future readers: This needs to be set before running any MLX computation, seems like the env var is cached).
results in
zcbenz commentedon May 13, 2026
This is because of Neural Accelerators kicking in, in short it is Apple's equivalent of NVIDIA Tensor Cores which trade precision for much better performance. I'm closing this issue since it is expected behavior, and what other frameworks do by default.