Skip to content

[BUG] M5 float32 precision issue since 0.30.0 #3534

Closed

Description

@priorphil

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

Snippet to reproduce:

python -c "
import mlx.core as mx, torch, numpy as np, platform, subprocess
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}')
"

Expected behavior
Similar numerics.

Additional context
Same picture on the M5 pro.

Activity

  1. zcbenz commented on May 12, 2026

    @zcbenz
    Member

    Can you try running with environment variable MLX_ENABLE_TF32=0?

  2. priorphil commented on May 13, 2026

    @priorphil
    Author

    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
    
  3. zcbenz commented on May 13, 2026

    @zcbenz
    Member

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions