Hi team,
long time listener, first time caller, love your work - thank you!
I have been installing pymc on some new pi4s and I run into a very repeatable problem.
I have models I’ve built and run successfully on a pi3b+ previously and without changes I have tried to use them as the test case for setting up my new boards. They get to 206 samples and return the ominous ‘Mass matrix contains zeros on the diagonal’, I read about it and saw plenty of discussion around the model definition, though it struck me as odd that I haven’t changed anything since previously using these models successfully. I picked up some ‘hello world’ type examples from the pymc pages and I hit the exact same error at the exact same location, 206 samples, all variables, every time, regardless of the model.
Hence my belief that I might be running into some library or compatibility issues as the common element of difference to the existing set up is that the failing cases are all new debian buster, newly installed pymc3, numpy, & theano. So I expect (I have since upgraded the old board also) that I might have been on an older numpy version or something like this?
I am hoping I have overlooked something simple in installing, anyway here is the problem as cleanly as I can give it to see what you might know of it;
N.b. everything has been installed with ‘sudo pip3 install…’ which I point out as I saw some other discussion about ‘master’ vs ‘stable’. The following is on a newly rebooted process, nothing else going on on the machine.
pi@pi4-1:~ $ python3
Python 3.7.3 (default, Dec 20 2019, 18:57:59)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymc3 as pm
>>> pm.__version__
'3.8'
>>> import numpy as np
>>> np.__version__
'1.18.4'
>>> import theano
>>> theano.__version__
'1.0.4'
>>>
>>> size = 100
>>> true_intercept = 1
>>> true_slope = 2
>>>
>>> x = np.linspace(0, 1, size)
>>>
>>> # y = a + b*x
... true_regression_line = true_intercept + true_slope * x
>>>
>>> # add noise
... y = true_regression_line + np.random.normal(scale=.5, size=size)
>>>
>>> # Add outliers
... x_out = np.append(x, [.1, .15, .2])
>>> y_out = np.append(y, [8, 6, 9])
>>>
>>> data = dict(x=x_out, y=y_out)
>>>
>>> with pm.Model() as model:
... pm.glm.GLM.from_formula('y ~ x', data)
... trace = pm.sample(2000, cores=2)
...
<pymc3.glm.linear.GLM object at 0xb08a4eb0>
Auto-assigning NUTS sampler...
Initializing NUTS using jitter+adapt_diag...
Multiprocess sampling (2 chains in 2 jobs)
NUTS: [sd, x, Intercept]
Sampling 2 chains, 0 divergences: 4%|▌ | 206/5000 [00:15<05:57, 13.42draws/s]
pymc3.parallel_sampling.RemoteTraceback:
"""
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/pymc3/parallel_sampling.py", line 110, in run
self._start_loop()
File "/usr/local/lib/python3.7/dist-packages/pymc3/parallel_sampling.py", line 160, in _start_loop
point, stats = self._compute_point()
File "/usr/local/lib/python3.7/dist-packages/pymc3/parallel_sampling.py", line 191, in _compute_point
point, stats = self._step_method.step(self._point)
File "/usr/local/lib/python3.7/dist-packages/pymc3/step_methods/arraystep.py", line 247, in step
apoint, stats = self.astep(array)
File "/usr/local/lib/python3.7/dist-packages/pymc3/step_methods/hmc/base_hmc.py", line 130, in astep
self.potential.raise_ok(self._logp_dlogp_func._ordering.vmap)
File "/usr/local/lib/python3.7/dist-packages/pymc3/step_methods/hmc/quadpotential.py", line 231, in raise_ok
raise ValueError('\n'.join(errmsg))
ValueError: Mass matrix contains zeros on the diagonal.
The derivative of RV `sd_log__`.ravel()[0] is zero.
The derivative of RV `x`.ravel()[0] is zero.
The derivative of RV `Intercept`.ravel()[0] is zero.
"""
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/dist-packages/pymc3/parallel_sampling.py", line 110, in run
self._start_loop()
File "/usr/local/lib/python3.7/dist-packages/pymc3/parallel_sampling.py", line 160, in _start_loop
point, stats = self._compute_point()
File "/usr/local/lib/python3.7/dist-packages/pymc3/parallel_sampling.py", line 191, in _compute_point
point, stats = self._step_method.step(self._point)
File "/usr/local/lib/python3.7/dist-packages/pymc3/step_methods/arraystep.py", line 247, in step
apoint, stats = self.astep(array)
File "/usr/local/lib/python3.7/dist-packages/pymc3/step_methods/hmc/base_hmc.py", line 130, in astep
self.potential.raise_ok(self._logp_dlogp_func._ordering.vmap)
File "/usr/local/lib/python3.7/dist-packages/pymc3/step_methods/hmc/quadpotential.py", line 231, in raise_ok
raise ValueError('\n'.join(errmsg))
ValueError: Mass matrix contains zeros on the diagonal.
The derivative of RV `sd_log__`.ravel()[0] is zero.
The derivative of RV `x`.ravel()[0] is zero.
The derivative of RV `Intercept`.ravel()[0] is zero.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
File "/usr/local/lib/python3.7/dist-packages/pymc3/sampling.py", line 469, in sample
trace = _mp_sample(**sample_args)
File "/usr/local/lib/python3.7/dist-packages/pymc3/sampling.py", line 1059, in _mp_sample
for draw in sampler:
File "/usr/local/lib/python3.7/dist-packages/pymc3/parallel_sampling.py", line 394, in __iter__
draw = ProcessAdapter.recv_draw(self._active)
File "/usr/local/lib/python3.7/dist-packages/pymc3/parallel_sampling.py", line 297, in recv_draw
raise error from old_error
RuntimeError: Chain 0 failed.
As I said, it’s very repeatable for the environments I’m testing, pi3b+, pi4, new models as well as old, complex as well as simple. All stop right at 206.