Slower and freez machine when run brm model with brms package

Dear all, I want to run the brm model, but it freezes the machine after a few seconds without results, just like the attached picture, could anyone help and thanks

in advance.

Note: my machine with os Debien 10.

library(rstan)
rstan_options(auto_write = TRUE)
options(mc.cores = parallel::detectCores(1))
library(brms)
library(devtools)
find_rtools()


fit<-brm(Dc~treat, mydata, family = bernoulli(link = "logit"),
         
         prior = c(set_prior("normal(0,10)", class = "Intercept"),
                   
                   set_prior("normal(0,10)", class = "b")),
         
         inits = "random",chains = 1, iter = 500,
         
         cores = 1, control = list(adapt_delta = 0.9), seed = 12345)

the data “mydata” is like this:

str(mydata)
‘data.frame’: 190 obs. of 2 variables:
$ Dc : int 1 0 0 0 0 0 0 1 0 0 …

$ treat: int 1 1 1 1 1 1 1 1 1 1 …

Does removing the seed = 12345 help? Also where is mydata? I see it in the model.

not all, its did not make change,

mydata: is just .csv file imported before.

Please post data if possible.

1 Like

its like this:

str(mydata)
‘data.frame’: 190 obs. of 2 variables:

$ Dc : int 1 0 0 0 0 0 0 1 0 0 …

$ treat: int 1 1 1 1 1 1 1 1 1 1 …

Hi Rani,

I was able to run your model with some basic fake data:

mydata = data.frame(
    Dc = sample(0:1,190,replace = T),
    treat = sample(0:1,190,replace = T) 
)

When you say that it ‘freezes’ do you mean that it just stays on Compiling the C++ model for a minute or so and then runs, or that R crashes?

Hi @andrjohns
Thanks for your replay , but
its stay on Compiling the C++ model and freeze, I should restart from power, also I did that on studio cloud and it crashed.
In the Rstudio cloud (online), I used the first example given in brm help and the same problem, but here he gave the message that the computation is crashed.

c

Hi again
I run it again and it gave me this error on studio could

Compiling the C++ model
Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! file552375f4c3b9.cpp:6:36: warning: ISO C++11 requires whitespace after the macro name
#define STAN__SERVICES__COMMAND_HPP#include <boost/integer/integer_log2.hpp>
^
In file included from /home/rstudio-user/R/x86_64-pc-linux-gnu-library/3.6/BH/include/boost/smart_ptr/shared_ptr.hpp:28:0,
from /home/rstudio-user/R/x86_64-pc-linux-gnu-library/3.6/BH/include/boost/shared_ptr.hpp:17,
from /home/rstudio-user/R/x86_64-pc-linux-gnu-library/3.6/BH/include/boost/date_time/time_clock.hpp:17,
from /home/rstudio-user/R/x86_64-pc-linux-gnu-library/3.6/BH/include/boost/date_time/posix_time/posix_time_types.hpp:10,
from /home/rstudio-user/R/x86_64-pc-linux-gnu-library/3.6/rstan/include/rstan/stan_fit.hpp:13,
from /home/rstudio-user/R/x86_64-pc-linux-gnu-library/3.6/rstan/include/rstan/rstaninc.hpp:3,

In addition: Warning message:
In system(cmd, intern = !verbose) :
running command ‘/opt/R/3.6.0/lib/R/bin/R CMD SHLIB file552375f4c3b9.cpp 2> file552375f4c3b9.cpp.err.txt’ had status 1
Error in sink(type = “output”) : invalid connection

Can you run:

example(stan_model,run.dontrun = TRUE,verbose=TRUE)

And post the line that starts with error: ?

I run it on my machine its like this:

example(stan_model,run.dontrun = TRUE,verbose=TRUE)
Warning messages:
1: In find.package(package, lib.loc, verbose = verbose) :
package ‘boot’ found more than once, using the first from
“/home/kamel/R/x86_64-pc-linux-gnu-library/3.6/boot”,
“/usr/lib/R/library/boot”
2: In find.package(package, lib.loc, verbose = verbose) :
package ‘MASS’ found more than once, using the first from
“/home/kamel/R/x86_64-pc-linux-gnu-library/3.6/MASS”,
“/usr/lib/R/library/MASS”
3: In example(stan_model, run.dontrun = TRUE, verbose = TRUE) :
no help found for ‘stan_model’

and on studio cloud its like this

example(stan_model,run.dontrun = TRUE,verbose=TRUE)
Warning message:
In example(stan_model, run.dontrun = TRUE, verbose = TRUE) :
no help found for ‘stan_model’

Oh sorry, I should have mentioned that you need to load rstan first:

library(rstan)
example(stan_model,run.dontrun = TRUE,verbose=TRUE)

sorry for late, but it freezed three times on my machine, I tried on studio cloud and its looks like this

Error in compileCode(f, code, language = language, verbose = verbose) :
Compilation ERROR, function(s)/method(s) not created! file55e812e58a4a.cpp:6:36: warning: ISO C++11 requires whitespace after the macro name
#define STAN__SERVICES__COMMAND_HPP#include <boost/integer/integer_log2.hpp>
^
In file included from /home/rstudio-user/R/x86_64-pc-linux-gnu-library/3.6/BH/include/boost/smart_ptr/shared_ptr.hpp:28:0,
from /home/rstudio-user/R/x86_64-pc-linux-gnu-library/3.6/BH/include/boost/shared_ptr.hpp:17,
from /home/rstudio-user/R/x86_64-pc-linux-gnu-library/3.6/BH/include/boost/date_time/time_clock.hpp:17,
from /home/rstudio-user/R/x86_64-pc-linux-gnu-library/3.6/BH/include/boost/date_time/posix_time/posix_time_types.hpp:10,
from /home/rstudio-user/R/x86_64-pc-linux-gnu-library/3.6/rstan/include/rstan/stan_fit.hpp:13,
from /home/rstudio-user/R/x86_64-pc-linux-gnu-library/3.6/rstan/include/rstan/rstaninc.hpp:3,

Let’s focus on your local machine for now, since rstudio cloud can have other issues.

When you say that it freezes, can you do anything else in RStudio? Like opening the ‘File’ menu or something similar? Does your whole computer freeze or just RStudio?

really the whole computer freeze.

How much RAM does your computer have?

4 :(

4GB? That’s likely the issue. Model compilation can take up roughly 2GB of memory, so you’re likely running out of memory, and the computer is swapping (storing information on the hard drive or SSD, rather than in RAM). This causes the computer to become pretty unresponsive.

I think if you leave it for long enough that the model will finish compiling and your computer will start responding again, but it will take much longer than a normal model compilation time. Definitely close as many other programs as possible (especially web browsers like chrome & firefox) so that your computer has as much RAM as possible to work with

1 Like

its ok,
no error message

its like this (last part)

SAMPLING FOR MODEL ‘16a540c6086086816528e4524def24d9’ NOW (CHAIN 4).
Chain 4:
Chain 4: Gradient evaluation took 6e-06 seconds
Chain 4: 1000 transitions using 10 leapfrog steps per transition would take 0.06 seconds.
Chain 4: Adjust your expectations accordingly!
Chain 4:
Chain 4:
Chain 4: Iteration: 1 / 2000 [ 0%] (Warmup)
Chain 4: Iteration: 200 / 2000 [ 10%] (Warmup)
Chain 4: Iteration: 400 / 2000 [ 20%] (Warmup)
Chain 4: Iteration: 600 / 2000 [ 30%] (Warmup)
Chain 4: Iteration: 800 / 2000 [ 40%] (Warmup)
Chain 4: Iteration: 1000 / 2000 [ 50%] (Warmup)
Chain 4: Iteration: 1001 / 2000 [ 50%] (Sampling)
Chain 4: Iteration: 1200 / 2000 [ 60%] (Sampling)
Chain 4: Iteration: 1400 / 2000 [ 70%] (Sampling)
Chain 4: Iteration: 1600 / 2000 [ 80%] (Sampling)
Chain 4: Iteration: 1800 / 2000 [ 90%] (Sampling)
Chain 4: Iteration: 2000 / 2000 [100%] (Sampling)
Chain 4:
Chain 4: Elapsed Time: 0.009914 seconds (Warm-up)
Chain 4: 0.009146 seconds (Sampling)
Chain 4: 0.01906 seconds (Total)
Chain 4:
curr.fun: symbol <-
… after ‘expression(fit2 <- sampling(mod, data = list(y_mean = 5)))’

That means everything is working, can you try your brms model?

Yes, but its too slow, more than three min, however with stanarm just a few second. I do not know why.
I have q quick question on that, you think here I successed in using the function argunments to define skeptical prior (mean zero and low variance )

fit<-brm(Dc~treat, mydata, family = bernoulli(link = “logit”),

     prior = c(set_prior("normal(0,0.15)", class = "Intercept"),
               
               set_prior("normal(0,0.15)", class = "b")),
     
     inits = "random",chains = 1, iter = 500,
     
     cores = 1, control = list(adapt_delta = 0.9))