Will the new M1 chip affect cmdstanR?

Hi all,

I used to be a Windows user but recently I found that using MacBook Pro might make my life easier in using Python (Pystan) and command line based computing (cluster computing, cmdstanR). However I heard some bad news on the effect of new M1 chip on some software. Just curious will this affect my user experience or I should still choose the older version with Intel chip?

Thx!

1 Like

Hi,

we do not expect issues there, but until we test on a real machine we wont really know. Cmdstanr and also rstan runs without a problem on Linux + ARM, which will hopefully transfer to macs.

You will definitely have to install all R packages from source for some time as CRAN will not build them until they get a M1 machine. This does not affect cmdstanr but might affect your overall R experience.

2 Likes

Some more info on this:

R & RStudio will run using the Rosseta 2 dynamic translation from Intel binary to ARM binary for some time. At least until there is a Fortran 90 compiler for the M1 chip. R requires that to build native binaries for M1. Until that happens I expect R/Rstudio to run considerably slower compared to Intel machines.

More info here:


and

The other thing is that M1 will not allow the use of more than 16GB of RAM. But that is not an issue many will hit.

Actually… looks like it might be faster even under Rosetta2: https://twitter.com/kjhealy/status/1328718684492279808?s=20

Actually with 8 cores it will be quite easy to fill 16 GB of RAM if doing parallel calculations. I’ve maxed out 64GB RAM on several occasions this way in R. Maybe folks don’t run Stan models that big though.

2 Likes

Nice! Though we can’t really say how much of that is due to the lightning fast SSDs in the new Mac’s. I do expect native M1 code to be faster than Intel in the end.

Based on the tweet we also have a timeframe for the native R for M1: April 2021.
Thanks for the link!

2 Likes

A quick update:

A user reported that cmdstan via cmdstanr works OK after adding
CXX="arch -arch arm64e clang++" to the makefile flags.

So for cmdstan you need to add the following to to make/local and rebuild cmdstan
CXX="arch -arch arm64e clang++"

For cmdstanr you need to run

cmdstanr::cmdstan_make_local(cpp_options = list(CXX="arch -arch arm64e clang++"))
rebuild_cmdstan()

and then everything should work fine. The next cmdstan version will handle this automatically.

3 Likes

Nice! Any word from them on speed of Stan on M1 ?

I wondered just that. Posted the question on the PR: https://github.com/stan-dev/math/pull/2208

Hi All,

These are all benchmarks of a model I’m working on:

mid-2013 1.3Ghz Intel MacBook Air: ~490 seconds
M1 MacBook Pro under Rosetta 2: ~240 seconds
M1 MacBook Pro native Arm: ~125 seconds.

It seems like going native arm64 is worth the hassle!

Kind wishes,

Nico

This is what I did to make it work:

In the Terminal.app, not the terminal window in RStudio

cd ~
git clone --recursive https://github.com/stan-dev/cmdstan.git
cd cmdstan/stan/lib/stan_math
git remote add nicokist git@github.com:nicokist/math.git
git pull nicokist bigsur_arm64
git checkout bigsur_arm64
cd ../../..
make build

in R:

library(cmdstanr)
set_cmdstan_path('~/cmdstan/')
cmdstanr::cmdstan_make_local(cpp_options = list(CXX="arch -arch arm64e clang++"))
cmdstanr_example(example = 'schools_ncp')
3 Likes

Just to clarify, in order to build cmdstan this also requires the makefile fix?

I don’t think so, since I built it from the Mac OS Terminal it’s automatically an arm64 executable. I’ve updated my previous post to make that clearer.

I think for the building stan/stan-math/cmdstan from the Rosetta 2 R environment it’s probably better to use arch -arch arm64e make build rather than adjust CXX, as boost gave an error when I tried adjusting CXX and running rebuild_cmdstan(), I guess because it uses more than just the c++ compiler…

2 Likes