[Project] Benchmarking torch.linalg.solve on Apple Silicon: CPU vs. MPS speed, accuracy, and dtype support

Hey everyone. For a numerical computations course at CU Boulder, my team and I benchmarked how well PyTorch 2.15.0 solves Ax = b on Apple Silicon Macs (specifically M2 Max and M3 Pro). We tested CPU vs. MPS, four precisions (float64, float32, float16, and bfloat16), and matrices with condition numbers from 10 to 10^7. Here are our findings:

  • MPS only supports float32 for linear solves, and CPU doesn’t support float16/bfloat16, so we built our own QR solver for low precision
  • The GPU only beats the CPU on large matrices: we found that number to be around 1,100 on the M3 Pro and around 2,300 on the M2 Max
  • Accuracy Follows Theory: we found that the forward error grows like k*u as predicted, while the backward error stays near u.

Here’s the link to our repo: pytorch-visualizer/benchmarks/linalg_mps at main · Reeves-me/pytorch-visualizer · GitHub

We would appreciate feedback, especially if you’ve seen different results on other Macs.