# M1 Apple silicon ML performance

Testing out a new M1 Macbook pro with Mathematica 13.0.0. I verified that I used the correct version and it is running natively on ARM.

Mathematica in general runs great, and much fast than on my previous 2015 Macbook (Intel). The benchmarking function (Benchmark[]) confirms this.

Now, when using the ML features of Mathematica this changes. Here is a simple LeNet example from https://reference.wolfram.com/language/tutorial/NeuralNetworksIntroduction.html#621730217

trainingData = ResourceData["MNIST", "TrainingData"];
testData = ResourceData["MNIST", "TestData"];
NetTrain[NetModel["LeNet"], trainingData, All, ValidationSet -> testData]


When I run this I'm getting slightly over 700 samples/second. Here is the NetTrain result object:

For comparison, my 2015 Intel Macbook (i7 4980HQ) manages close to 2000 examples/s on the same example using the CPU.

My question is if this is just the state of Mathematica and the new ARM architecture or is there something that can be done to speed up the ML functions for Apple Silicon based macs?

Thanks everyone, E

• Welcome to the Mathematica Stack Exchange. Have you considered asking Wolfram support for help?
– Syed
Jan 31 at 19:56
• I have not, it's not really an issue for me I just want to understated it. If I have to run any serious ML tasks it would run on a GPU anyways. Jan 31 at 20:02
• I'm just curious as to why a machine that is so much more powerful performs poorly in this (rather) narrow task. Jan 31 at 20:03
• I’d comment that the power of the cpu isn’t always a good indicator for algorithmic performance, i believe the problem that you’re seeing is related to the Similar amd problem not taking advantage of intels hardware accelerated matrix algorithms built into the chip. Feb 1 at 12:30
• Possibly related?: mathematica.stackexchange.com/q/256740/4999 Feb 1 at 14:46

It may be an issue where your machine isn't utilizing the parallel kernels. I'm using an M1 Mac and notice that by default it doesn't use all of the cores unless you use LaunchKernels first. If you run the Benchmarking functions you should also notice a speedup if you use LaunchKernels first.

When running your example in a fresh notebook I get a slow speed initially as shown here with around 138 examples/s.

If I first launch parallel kernels I get a significant speedup, around 760 examples/s.

LaunchKernels[];
NetTrain[NetModel["LeNet"],trainingData,All,ValidationSet->testData]


• I didn't DV and don't why someone else did. — However, my experience is different. I have an M1 Max/32GB. I tried your method: fresh start each trial, with/without LaunchKernels, and let it run a couple of minutes longer than you did. Both ways I got 700-800 examples/s. If anything, it tended to be faster without LaunchKernels. Once I got ~450 ex/s, but that was with LaunchKernels. In all cases, the main kernel ran at ~850% and the FE at ~30%. I never got anywhere near 2000 ex/s the OP reports for their Intel Mac. You don't seem to get that high either, which might explain the DV. Apr 14 at 15:11
• I wonder what I'm observing then. I noticed the same thing when using BenchmarkReport. When running in a new notebook I get a score of 2.36 and after using LaunchKernels I get a score of 5.38. This is with using a standard M1/16GB.
– Nate
Apr 14 at 16:34
• @Nate Try running BenchmarkReport both with and without LaunchKernels, keeping track of the wall clock time (the total run time). Even though you get a higher score with LaunchKernels, it actually takes significantly longer to complete the benchmark. I.e., with LaunchKernels it's not faster, it's slower. I thus think what's going on is that, when you run the benchmark with LaunchKernels, it runs multiple benchmarks at once (which slows things down), and somehow combines the scores (resulting in a higher score). Thus the benchmark result you get with LaunchKernels probably isn't meaningful. Jun 6 at 7:06