2.16.1 and adapt_delta

  • Operating System: Mac
  • brms Version: 2.16.1

Since updating to brms 2.16.1, I’m having difficulty using adapt_delta. Here’s an example:

library(brms)

data(package = "rethinking", Howell1)

# this runs, but the chains are a mess 
# because of the terrible prior used on sigma
fit1 <- brm(
  data = Howell1,
  height ~ 1,
  prior = prior(uniform(0, 100), class = sigma),
  cores = 4, seed = 4
)

# this fails to run
fit2 <- brm(
  data = Howell1,
  height ~ 1,
  prior = prior(uniform(0, 100), class = sigma),
  cores = 4, seed = 4,
  control = list(adapt_delta = 0.9)
)

The second model, fit2, returned the following:

Warning: It appears as if you have specified an upper bounded prior on a parameter that has no natural upper bound.
If this is really what you want, please specify argument 'ub' of 'set_prior' appropriately.
Warning occurred for prior 
sigma ~ uniform(0, 100)

Compiling Stan program...
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `clang++ -E -nostdinc -x c++ -P -C -I /var/folders/hm/3s73t2vd2lz35rvqyfxdshy40000gn/T//RtmphqLf8P  -I /Users/solomonkurz/Dropbox/ML coef()   -o /var/folders/hm/3s73t2vd2lz35rvqyfxdshy40000gn/T//RtmphqLf8P/file125411c35eb70.stan /var/folders/hm/3s73t2vd2lz35rvqyfxdshy40000gn/T//RtmphqLf8P/file12541469010a9.stan >/dev/null 2>/dev/null'
recompiling to avoid crashing R session
Start sampling
starting worker pid=78171 on localhost:11382 at 09:41:46.234
starting worker pid=78185 on localhost:11382 at 09:41:46.441
starting worker pid=78199 on localhost:11382 at 09:41:46.637
starting worker pid=78213 on localhost:11382 at 09:41:46.833

SAMPLING FOR MODEL '6ca711e8ed4dd648c40f21e5c8889091' NOW (CHAIN 1).
Error in unserialize(socklist[[n]]) : error reading from connection

SAMPLING FOR MODEL '6ca711e8ed4dd648c40f21e5c8889091' NOW (CHAIN 2).

I think the problem is with the uniform prior not having the boundaries set, not with adapt_delta.

I understand the uniform prior is bad news. But the first model (with the uniform prior) returns a fit object. The second model (with the same uniform prior) does not return a fit object. So far, this has happened every time I’ve tried to use adapt_delta since updating to 2.16.1, regardless of the prior and so on.

strange. does it happen with models not involving uniform prior as well? I assume your answer says yes. does it happen with both rstan and cmdstanr?

Yes, it even happens in the model below, which has all default priors.

fit2 <- brm(
  data = Howell1,
  height ~ 1,
  cores = 4, seed = 4,
  control = list(adapt_delta = 0.9)
)

I got these messages:

Compiling Stan program...
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `clang++ -E -nostdinc -x c++ -P -C -I /var/folders/hm/3s73t2vd2lz35rvqyfxdshy40000gn/T//RtmphqLf8P  -I /Users/solomonkurz/Dropbox/ML coef()   -o /var/folders/hm/3s73t2vd2lz35rvqyfxdshy40000gn/T//RtmphqLf8P/file12541502acfd6.stan /var/folders/hm/3s73t2vd2lz35rvqyfxdshy40000gn/T//RtmphqLf8P/file125413d3e77cb.stan >/dev/null 2>/dev/null'
recompiling to avoid crashing R session
Start sampling
starting worker pid=82428 on localhost:11382 at 08:55:22.281
starting worker pid=82442 on localhost:11382 at 08:55:22.482
starting worker pid=82456 on localhost:11382 at 08:55:22.692
starting worker pid=82470 on localhost:11382 at 08:55:22.896

SAMPLING FOR MODEL '0cab45274f69753162098d3e9ecde70f' NOW (CHAIN 1).

SAMPLING FOR MODEL '0cab45274f69753162098d3e9ecde70f' NOW (CHAIN 2).
Error in unserialize(socklist[[n]]) : error reading from connection

The procedure did not return a fit object.

But it does work with backend = "cmdstanr"!

# default priors
fit4 <- brm(
  data = Howell1,
  height ~ 1,
  cores = 4, seed = 4,
  control = list(adapt_delta = 0.9),
  backend = "cmdstanr"
)

# terrible uniform prior
fit5 <- brm(
  data = Howell1,
  height ~ 1,
  cores = 4, seed = 4,
  prior = prior(uniform(0, 100), class = sigma),
  control = list(adapt_delta = 0.9),
  backend = "cmdstanr"
)

Both worked fine. So we have isolated the problem to when backend = "rstan".

1 Like

what happens when you only use 1 core?

Setting cores = 1, but keeping the default number of chains, causes problems.

fit6 <- brm(
  data = Howell1,
  height ~ 1,
  cores = 1, seed = 4,
  control = list(adapt_delta = 0.9)
)

It repeatedly crashed RStudio. When trying it directly in R, it just got hung up–it’s been going now for 15 minutes when I’d have expected it to finish within a minute or two.

I don’t know to be honest. I don’t think this is caused by brms because adapt_delta should (in the worst case) not be passed properly so didn’t cause any change in this case. since it chanbes something I suppose it is passed correctly (my code inspection suggests so). I suppose the problem is more related to the sampling backend. could you try re-installing the related packages?

1 Like

Uninstalling brms and rstan and then reinstalling them from CRAN was a failure. However, resinstalling them both using remotes::install_github("paul-buerkner/brms") was a success. adapt_delta no longer causes problems. So perhaps the issue had to do with some difference between the current version of rstan on CRAN (2.21.2) and the more current version used in the GitHub install (2.26.3).

1 Like