14
$\begingroup$

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:

enter image description here

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

$\endgroup$
9
  • 1
    $\begingroup$ Welcome to the Mathematica Stack Exchange. Have you considered asking Wolfram support for help? $\endgroup$
    – Syed
    Commented Jan 31, 2022 at 19:56
  • 1
    $\begingroup$ 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. $\endgroup$
    – Edward
    Commented Jan 31, 2022 at 20:02
  • 1
    $\begingroup$ I'm just curious as to why a machine that is so much more powerful performs poorly in this (rather) narrow task. $\endgroup$
    – Edward
    Commented Jan 31, 2022 at 20:03
  • 1
    $\begingroup$ 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. $\endgroup$ Commented Feb 1, 2022 at 12:30
  • 1
    $\begingroup$ Possibly related?: mathematica.stackexchange.com/q/256740/4999 $\endgroup$
    – Michael E2
    Commented Feb 1, 2022 at 14:46

1 Answer 1

0
$\begingroup$

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.

enter image description here

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

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

enter image description here

$\endgroup$
4
  • $\begingroup$ 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. $\endgroup$
    – Michael E2
    Commented Apr 14, 2022 at 15:11
  • $\begingroup$ 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. $\endgroup$
    – Nate
    Commented Apr 14, 2022 at 16:34
  • $\begingroup$ @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. $\endgroup$
    – theorist
    Commented Jun 6, 2022 at 7:06
  • $\begingroup$ @theorist, the parallel kernels require the data distribution before the run on it. This is slow enough and, thus, parallelization really good for the long enough tasks. The benchmark is too short and data distribution to kernels eats too much part of total time. $\endgroup$
    – Rom38
    Commented Sep 25, 2023 at 18:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.