ValueError: Mass matrix contains zeros on the diagonal. The derivative of RV `@@@`.ravel()[0] is zero

Hi @junpenglao @aseyboldt

PyMC is new to me. Using PyMC3, I’m attempting to create a Bayesian regression model. The data dimension is 156 x 12. Priors are generated using the OLS model, where there is substantial multicollinearity and positive autocorrelation in the error terms. Assume that the domain will circumvent these conditions. I keep running into the mass matrix has zeros on the diagonal value error when generating the model. I read every topic on this issue. Scaling the values resolved the ValueError. But checking if there is a long-lasting solution to this. Please find the code and the traceback below. Thanks in advance!

The below python code is tested on:
PyMC3 v3.11.5
Python v3.8
Jupyter Notebook v6.4.8

priors_dict = priorsdata.set_index('Features').to_dict()
priors_dict = priors_dict['Prior']
  
sd_dict = sddata.set_index('Features').to_dict()
sd_dict = sd_dict['Std_Error']
  
model_df = df.copy()
formula = 'Value ~ ' + ' + '.join(['%s' % variable for variable in model_df.columns[:-1]])
my_priors = {}
my_priors['Intercept'] = pm.Normal.dist(mu = mu_intercept, tau = 1/(sd_intercept**2))

for e in priors_dict.keys():
    my_priors[e] = pm.Normal.dist(mu = priors_dict[e], tau = 1/(sd_dict[e]**2))

with pm.Model() as normal_model:
    family = pm.glm.families.Normal()
    pm.glm.GLM.from_formula(formula = formula, data = model_df, family = family, priors = my_priors)
    
    draws = 1000
    chains = 2
    tune = 1000
    normal_trace = pm.sample(draws = draws, chains = chains, tune = tune, random_seed = 1729, cores = 2, init = "adapt_diag")

RemoteTraceback Traceback (most recent call last)
RemoteTraceback:
“”"
Traceback (most recent call last):
File “C:\Users\fn.ln.conda\envs\pm3env\lib\site-packages\pymc3\parallel_sampling.py”, line 137, in run
self._start_loop()
File “C:\Users\fn.ln.conda\envs\pm3env\lib\site-packages\pymc3\parallel_sampling.py”, line 191, in _start_loop
point, stats = self._compute_point()
File “C:\Users\fn.ln.conda\envs\pm3env\lib\site-packages\pymc3\parallel_sampling.py”, line 216, in _compute_point
point, stats = self._step_method.step(self._point)
File “C:\Users\fn.ln.conda\envs\pm3env\lib\site-packages\pymc3\step_methods\arraystep.py”, line 276, in step
apoint, stats = self.astep(array)
File “C:\Users\fn.ln.conda\envs\pm3env\lib\site-packages\pymc3\step_methods\hmc\base_hmc.py”, line 147, in astep
self.potential.raise_ok(self._logp_dlogp_func._ordering.vmap)
File “C:\Users\fn.ln.conda\envs\pm3env\lib\site-packages\pymc3\step_methods\hmc\quadpotential.py”, line 268, in raise_ok
raise ValueError(“\n”.join(errmsg))
ValueError: Mass matrix contains zeros on the diagonal.
The derivative of RV var1.ravel()[0] is zero.
The derivative of RV var2.ravel()[0] is zero.
The derivative of RV var3.ravel()[0] is zero.
The derivative of RV var4.ravel()[0] is zero.