Error with trace ADVI


I am trying to run a model on a large dataset using ADVI. I am able to fit the model. But when I am trying to sample from it. It gives me this error.

Traceback (most recent call last):
File “”, line 102, in
tr = approx.sample(draws=100)
File “/home/anil.gaddam/.conda/envs/pymc3_env/lib/python2.7/site-packages/pymc3/variational/”, line 1589, in sample
samples = self.sample_dict_fn(draws) # type: dict
File “/home/anil.gaddam/.conda/envs/pymc3_env/lib/python2.7/site-packages/pymc3/variational/”, line 1567, in inner
_samples = sample_fn(draws)
File “/home/anil.gaddam/.conda/envs/pymc3_env/lib/python2.7/site-packages/theano/compile/”, line 917, in call
storage_map=getattr(self.fn, ‘storage_map’, None))
File “/home/anil.gaddam/.conda/envs/pymc3_env/lib/python2.7/site-packages/theano/gof/”, line 325, in raise_with_op
reraise(exc_type, exc_value, exc_trace)
File “/home/anil.gaddam/.conda/envs/pymc3_env/lib/python2.7/site-packages/theano/compile/”, line 903, in call
self.fn() if output_subset is None else
ValueError: rng_mrg cpu-implementation does not support more than (2**31 -1) samples
Apply node that caused the error: mrg_uniform{TensorType(float64, vector),inplace}(<TensorType(int32, matrix)>, MakeVector{dtype=‘int64’}.0)
Toposort index: 11
Inputs types: [TensorType(int32, matrix), TensorType(int64, vector)]
Inputs shapes: [(15360, 6), (1,)]
Inputs strides: [(24, 4), (8,)]
Inputs values: [‘not shown’, array([3415522600])]
Outputs clients: [[‘output’], [Shape_i{0}(mrg_uniform{TensorType(float64, vector),inplace}.1), Subtensor{int64::}(mrg_uniform{TensorType(float64, vector),inplace}.1, ScalarFromTensor.0), Subtensor{:int64:}(mrg_uniform{TensorType(float64, vector),inplace}.1, ScalarFromTensor.0)]]

HINT: Re-running with most Theano optimization disabled could give you a back-trace of when this node was created. This can be done with by setting the Theano flag ‘optimizer=fast_compile’. If that does not work, Theano optimizations can be disabled with ‘optimizer=None’.
HINT: Use the Theano flag ‘exception_verbosity=high’ for a debugprint and storage map footprint of this apply node.

P.S: I am running it on a remote server because of memory constraints. I aam real need of help .

Help much appreciated.


It seems like you are trying to sample too many samples - how are you calling the function?

I am using approx.sample(100) after fitting model using ADVI. Model fits fine. But if I try and sample it,it fails. I am stuck with these for a few weeks now. How can I possibly get results if I keep running it on a remote server.

What kind of error did you see? My guess is memory problem…

Even when I tried with lesser data the problem persists.

Is there any way that I can sample in batches or someway in which I can make it work?

Reading the error message and combine with the model parameter size you mentioned in another post, I think the problem is that your Random Variable is simply too large for pymc3/theano to work properly. Unfortunately, I dont have any answer except advice you to reduce the shape of your random variables.