# Chain Failure when running model

**URL:** <https://discourse.pymc.io/t/chain-failure-when-running-model/4593>\
**Category:** Questions\
**Created:** [March 2, 2020, 12:25pm UTC](https://discourse.pymc.io/t/chain-failure-when-running-model/4593 "2020-03-02T12:25:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![km17084](https://avatars.discourse-cdn.com/v4/letter/k/b5ac83/32.png) [@km17084](https://discourse.pymc.io/u/km17084)\
**Post date:** [March 2, 2020, 12:25pm UTC](https://discourse.pymc.io/t/chain-failure-when-running-model/4593/1 "2020-03-02T12:25:03Z")

</div>

I am trying to use PyMC3 to regress the thermal conductivity of low alloy steels. I have set up the model as such:

* * *

with pm.Model() as FeCCrMn\_T\_model:  
# we also pass the database  
mypriors = {‘Intercept’: pm.Normal.dist(mu=60, sd=100)}  
pm.glm.GLM.from\_formula('Conductivity ~ T+C+Cr+Mn+T_C+T_Cr+T_Mn’, FeCCrMn\_T, priors=mypriors) #T_C_Cr_Mn

```
#do the sampling with 2000 iterations and 4 separate chains.
trace = pm.sample(2000, chains=2,)
prior = pm.sample_prior_predictive()
posterior_predictive = pm.sample_posterior_predictive(trace)

#save everything in a ArviZ inference object for ease of analysis
fit_CCrMnT = az.from_pymc3(trace=trace, prior=prior, posterior_predictive=posterior_predictive)

```

* * *

When I try to run this however, I keep running into the following error:

* * *

## Auto-assigning NUTS sampler… Initializing NUTS using jitter+adapt\_diag… Multiprocess sampling (2 chains in 2 jobs) NUTS: [sd, T:Mn, T:Cr, T:C, Mn, Cr, C, T, Intercept] Sampling 2 chains: 14%|█▍ | 715/5000 [00:06\<00:41, 104.49draws/s]

RemoteTraceback Traceback (most recent call last)  
RemoteTraceback:  
“”"  
Traceback (most recent call last):  
File “C:\Users\Karan Mohindra\Anaconda3\lib\site-packages\pymc3\parallel\_sampling.py”, line 110, in run  
self.\_start\_loop()  
File “C:\Users\Karan Mohindra\Anaconda3\lib\site-packages\pymc3\parallel\_sampling.py”, line 160, in \_start\_loop  
point, stats = self.\_compute\_point()  
File “C:\Users\Karan Mohindra\Anaconda3\lib\site-packages\pymc3\parallel\_sampling.py”, line 191, in \_compute\_point  
point, stats = self.\_step\_method.step(self.\_point)  
File “C:\Users\Karan Mohindra\Anaconda3\lib\site-packages\pymc3\step\_methods\arraystep.py”, line 247, in step  
apoint, stats = self.astep(array)  
File “C:\Users\Karan Mohindra\Anaconda3\lib\site-packages\pymc3\step\_methods\hmc\base\_hmc.py”, line 130, in astep  
self.potential.raise\_ok(self.\_logp\_dlogp\_func.\_ordering.vmap)  
File “C:\Users\Karan Mohindra\Anaconda3\lib\site-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 `Intercept`.ravel()[0] is zero.  
“”"

The above exception was the direct cause of the following exception:

ValueError Traceback (most recent call last)  
ValueError: Mass matrix contains zeros on the diagonal.  
The derivative of RV `Intercept`.ravel()[0] is zero.

The above exception was the direct cause of the following exception:

RuntimeError Traceback (most recent call last)  
 in   
6  
7 #do the sampling with 2000 iterations and 4 separate chains.  
----\> 8 trace = pm.sample(2000, chains=2,)  
9 prior = pm.sample\_prior\_predictive()  
10 posterior\_predictive = pm.sample\_posterior\_predictive(trace)

~\Anaconda3\lib\site-packages\pymc3\sampling.py in sample(draws, step, init, n\_init, start, trace, chain\_idx, chains, cores, tune, progressbar, model, random\_seed, discard\_tuned\_samples, compute\_convergence\_checks, \*\*kwargs)  
435 \_print\_step\_hierarchy(step)  
436 try:  
–\> 437 trace = \_mp\_sample(\*\*sample\_args)  
438 except pickle.PickleError:  
439 \_log.warning(“Could not pickle model, sampling singlethreaded.”)

~\Anaconda3\lib\site-packages\pymc3\sampling.py in \_mp\_sample(draws, tune, step, chains, cores, chain, random\_seed, start, progressbar, trace, model, \*\*kwargs)  
967 try:  
968 with sampler:  
–\> 969 for draw in sampler:  
970 trace = traces[draw.chain - chain]  
971 if (trace.supports\_sampler\_stats

~\Anaconda3\lib\site-packages\pymc3\parallel\_sampling.py in **iter** (self)  
391  
392 while self.\_active:  
–\> 393 draw = ProcessAdapter.recv\_draw(self.\_active)  
394 proc, is\_last, draw, tuning, stats, warns = draw  
395 if self.\_progress is not None:

~\Anaconda3\lib\site-packages\pymc3\parallel\_sampling.py in recv\_draw(processes, timeout)  
295 else:  
296 error = RuntimeError(“Chain %s failed.” % proc.chain)  
–\> 297 raise error from old\_error  
298 elif msg[0] == “writing\_done”:  
299 proc.\_readable = True

RuntimeError: Chain 1 failed.

* * *

What do you think I can change here?

---

<div class="post-metadata">

**Author:** ![AlexAndorra](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/alexandorra/32/9142_2.png) [@AlexAndorra](https://discourse.pymc.io/u/AlexAndorra)\
**Post date:** [March 7, 2020, 4:01pm UTC](https://discourse.pymc.io/t/chain-failure-when-running-model/4593/2 "2020-03-07T16:01:43Z")

</div>

Hi,  
I’m not familiar with the GLM module, but I think your prior is misspecified – see [this tutorial](https://docs.pymc.io/notebooks/GLM-linear.html).  
Plus, I don’t know your data, but I think your prior’s sd is really big, which can mess up sampling.  
Hope this helps 🖖
