· 6 min read
I wanted to compare two laptops on different GPU operations, related to deep learning.
The two laptops I compared are:
- the MacBook Air M2 (8 CPU cores: 4 performance + 4 efficiency, 8 GPU cores), 16GB of unified memory — macOS 27.1,
- the Lenovo Yoga Slim 7 Ultra 14IPH11 , with an Intel Core Ultra 7 355 (8 cores: 4P + 4 low-power E) and an integrated Intel Xe3 GPU — Fedora Linux 45 (Silverblue).
To be honest, I expected both machines to be roughly equal, with a slight advantage for the MacBook Air M2… but that was not the case.
Both machines run the same PyTorch benchmark script, but the device backend differs: the Yoga uses XPU and the MacBook uses MPS (Metal Performance Shaders).
I wanted to benchmark different parts, so I measured:
MatMul: a 4096x4096 matrix multiplication,MLP Forward: a fully-connected forward pass,Attention: an attention pass,- and
Train Step: a full forward + backward + optimizer step.
The code is available here.
The shapes are shown next to each line, and TFLOPS assume the standard 2·N³ FLOPs for an N×N matmul. I benchmarked both float32 and bfloat16 (bf16). At that time I forgot float16 (or f16), but I included this format later in this post.
#
First results #
For those experiments, I unplugged both laptops, and put the battery mode to ‘balanced’ on the Lenovo Yoga, and to ‘standard (no battery saver)’ on the MacBook.
This is the output for the Lenovo Yoga:
Benchmarking on: xpu
MatMul 4096x4096 (torch.float32): 54.67 ms/iter | 2.51 TFLOPS
MatMul 4096x4096 (torch.bfloat16): 7.94 ms/iter | 17.30 TFLOPS
MLP Forward (256x2048): 7.20 ms/iter | 138.8 iters/s
Attention (16x1024x1024): 105.63 ms/iter | 155,103 tok/s
Train Step (16x1024x1024): 979.87 ms/iter | 16,721 tok/s
and for the MacBook:
Benchmarking on: mps
MatMul 4096x4096 (torch.float32): 61.11 ms/iter | 2.25 TFLOPS
MatMul 4096x4096 (torch.bfloat16): 109.59 ms/iter | 1.25 TFLOPS
MLP Forward (256x2048): 7.33 ms/iter | 136.4 iters/s
Attention (16x1024x1024): 83.71 ms/iter | 195,718 tok/s
Train Step (16x1024x1024): 945.79 ms/iter | 17,323 tok/s
I made this table as a better comparison view:
| Benchmark | Yoga XPU | Mac M2 | Winner |
|---|---|---|---|
| MatMul fp32 | 2.51 TFLOPS | 2.25 TFLOPS | Yoga (+12%) |
| MatMul bf16 | 17.30 TFLOPS | 1.25 TFLOPS | Yoga (13.8x) |
| MLP forward | 138.8 iters/s | 136.4 iters/s | Yoga (+2%) |
| Attention | 155,103 tok/s | 195,718 tok/s | Mac (+26%) |
| Train step | 16,721 tok/s | 17,323 tok/s | Mac (+4%) |
The Mac wins attention and the training step. The Yoga wins every matmul tested here (fp32, bf16) and the MLP forward pass. The bf16 matmul gap is enormous: 13.8x, or 109.59 ms vs 7.94 ms per iteration. On the M2, bf16 is also 1.8x slower than fp32. The MLP, attention, and training rows are single numbers, not per-format.
At first, I was confused by the results. How is it possible that bfloat16 operations were so slow on the MacBook?
First, let’s explore what is bfloat16, and how it compares to float16 and float32 formats.
#
What is bfloat16? #
bfloat16 stands for Brain Floating Point, a 16-bit format developed by Google Brain. Like float16, it halves memory usage compared to float32, but it trades precision for range.
bfloat16 has the same range of values as float32 using half as many bits. That drops decimal precision from ~7 significant digits in float32 to 2 to 3 significant digits in bfloat16, which makes it an interesting format for deep learning experiments.
| Feature | float32 (FP32) | float16 (FP16) | bfloat16 (BF16) |
|---|---|---|---|
| Total Bits | 32 bits | 16 bits | 16 bits |
| Sign Bit | 1 bit | 1 bit | 1 bit |
| Exponent Bits (Range) | 8 bits | 5 bits | 8 bits |
| Mantissa / Fraction Bits (Precision) | 23 bits | 10 bits | 7 bits |
| Max Representable Value | ~3.4 × 10^38 | ~65,504 | ~3.4 × 10^38 |
| Smallest Positive Normal | ~1.18 × 10^-38 | ~6.1 × 10^-5 | ~1.18 × 10^-38 |
| Decimal Precision | ~7 significant digits | ~3–4 significant digits | ~2–3 significant digits |
But why is bf16 good for deep learning?
First, the range. The 8-bit exponent matches fp32, so gradients and activations rarely overflow or underflow. Unlike fp16, bf16 does not need loss scaling during training.
Then, the memory. 16-bit storage cuts the footprint and memory bandwidth in half compared to fp32.
Finally, the throughput. Matrix units such as Intel’s XMX, NVIDIA tensor cores, or TPUs have native bf16 paths, and they usually accumulate in fp32. The fp32 accumulator is what makes the 7-bit mantissa tolerable.
The trade-off is precision: bf16 has fewer mantissa bits than fp16. For most weights and activations, that is fine, especially with fp32 accumulation. Operations that need more precision (reductions, softmax, normalization) stay in fp32 in a mixed-precision setup.
Crucially, bf16 is only fast when the hardware has a native bf16 path, which is the case only for the Yoga.
float16, meanwhile, has existed for much longer in Apple’s graphics and mobile GPUs, so on M1/M2 hardware fp16 is the fast 16-bit format.
#
bfloat16 support on Apple Silicon #
The M1 has no native bf16 support at all. The M2 and M3 CPUs implement the Armv8.6-A instruction set, which includes bf16 instructions. MPSGraph has exposed a bf16 data type since macOS 14 (Sonoma), but the M2 GPU has no native bf16 matrix path. So PyTorch’s MPS backend runs bf16 matmuls by converting the inputs to fp32, computing in fp32, and converting the result back to bf16. That adds memory traffic and conversion instructions to every operation, which is exactly what the 1.8x slowdown reflects. Compared to the MacBook, the Yoga’s Xe3 GPU has XMX matrix engines with native bf16 support. The M2 GPU has no dedicated matrix engines (Apple only added neural accelerators with the M5). That explains the speed-up.
For context, native bf16 matrix acceleration on the GPU only arrives with the M5’s neural accelerators.
#
Adding float16 to the comparison #
I don’t like unfair comparisons, so let me add float16 to the benchmark:
Benchmarking on: xpu # Lenovo Intel Ultra 7
MatMul 4096x4096 (torch.float16): 9.12 ms/iter | 15.07 TFLOPS
Benchmarking on: mps # MacBook Air M2
MatMul 4096x4096 (torch.float16): 54.49 ms/iter | 2.52 TFLOPS
Now the picture is clearer:
| MatMul 4096x4096 | fp32 | fp16 | bf16 | Best |
|---|---|---|---|---|
| Yoga XPU | 2.51 TFLOPS | 15.07 TFLOPS | 17.30 TFLOPS | bf16 (6.9x fp32) |
| Mac M2 | 2.25 TFLOPS | 2.52 TFLOPS | 1.25 TFLOPS | fp16 (1.12x fp32) |
On the Yoga, fp16 is 15% slower than bfp16, but 6.9x faster than fp32. On the M2, fp16 is twice as fast as bf16, and slightly faster than fp32. The 13.8x bf16 gap between the two machines shrinks to 6.0x for fp16 and 1.1x for fp32.
So for matmul workloads, the Yoga is faster across the board (and dramatically so for bf16).
#
Conclusion #
Here, the practical lesson is to check which format your device actually accelerates before switching your code to it. It seems obvious at first, but let’s keep this in mind: a floating-point format is only fast when the hardware has a native path for it.
If you want to compare with my results on your own laptop (desktop is cheating…), the code is in my Git repository here.