Memory Leak with brms After MAC OS upgrade

Hello, I am trying to run a brms model but running into memory errors even with very small input dataframes. I suspect the problem arises from OS / CLI upgrades and my Makevars file. Here is a code example.


library('tidyverse')
library('brms')

# Run stan model
gt_fit <- brm(
  formula = gross ~ (1|pid), 
  family = 'lognormal', 
  chains = 2, cores=2,
  data = df %>%
    sample_n(1000) %>%
    filter(gross > 0) %>%
    select(pid, gross)
  ) 

This results in the following output:


Compiling the C++ model
Start sampling
 Error: vector memory exhausted (limit reached?) 

Please note the small sample input. Other notebooks with much more demanding memory requirements work just fine (but they don’t use stan).

Here is some useful context:

  • I recently upgraded to Catalina (~a month ago), then last week I updated my command line tools and uninstalled / reinstalled R and R binaries.

Here is my sessionInfo()

R version 3.6.2 (2019-12-12)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Catalina 10.15.2

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

Select packages:

brms_2.10.0
Rcpp_1.0.3
rstan_2.19.2
rstantools_2.0.0
vctrs_0.2.1

I suspect the problem is with my Makevars file but don’t want to go around changing things by trial and error.

VER=-9
CC=gcc$(VER)
CXX=g++$(VER)
CXX11=g++$(VER)
CXX14=g++$(VER)
CXX17=g++$(VER)
CFLAGS=-mtune=native -g -O2 -Wall -pedantic -Wconversion
CXXFLAGS=-mtune=native -g -O2 -Wall -pedantic -Wconversion
FLIBS=-L/usr/local/Cellar/gcc/9.2.0_1/lib/gcc/9

If I simply comment out all lines in my Makevars file, I get the following output from the above command.

Compiling the C++ model
Start sampling

SAMPLING FOR MODEL 'b5453acd8ba84f03789636be384f4dc7' NOW (CHAIN 1).
Chain 1: 
Chain 1: Gradient evaluation took 0.000102 seconds
Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 1.02 seconds.
Chain 1: Adjust your expectations accordingly!
Chain 1: 
Chain 1: 
Chain 1: Iteration:    1 / 2000 [  0%]  (Warmup)
[1] "Error in sampler$call_sampler(args_list[[i]]) : " "  c++ exception (unknown reason)"                
error occurred during calling the sampler; sampling not done

I don’t know what may cause this problem, but perhaps @bgoodri has some ideas?

I would not have -g in Makevars because it creates debug information. It is better to have -g0 to make sure the debug information is not created, but all that needs to be in CXX14FLAGS for rstan.