Variational Bayes - rstan - Error: cannot allocate vector of size 250.0 Gb

I have been trying to run a model that does complete with NUTS, however with vb I get the error message

Error: cannot allocate vector of size 250.0 Gb

I have quite a lot of data although not millions of points, and I am only saving couple of parameters that I need.

Is it possible this huge data structures could be optimized or avoided? Any suggestion is welcome.

1 Like

I don’t know the answer, but I moved this to the algorithms category. I would’ve thought GB would use less memory—were you using diagonal/mean field?

How complex is your R code? You might try StanJulia/ StanVariational.jl which is a wrapper for CmdStan. Admittedly not a great answer, though as I understand it 250.0 Gb is the amount in addition to the memory already allocated, so you have a long way to go in R. I’m really curious if Julia is much better for this particular problem.

The minimal overhead should be with CmdStan, which streams out all the intermediate output.

Also, one thing to try is to turn off sampling, which may automatically draw samples from the approximation and return those. If you ask for a lot of those (even by default), it can take up a lot of space.

1 Like