ValueError: Unexpected type in draw_value: <class 'theano.gof.graph.Constant'>

Hi Pymc3 Comunity,
I’m posting this question here as well as rasing it as an issue on Github, in case someone here has seen something similar.

I get the above error when sampling from the posterior predictive.

It appears that somewhere in the theano graph a theano.NoneConst is being created, and sample_posterior_predictive throws an error when it tries to sample from it.

In the example model below, the ANOVA type model has a mean for each group, where each group is defined by 2 factors (x and g). Both g and x are used to pick a specific group mean parameter which the DV (y) is then sampled from. Here im modeling a single DV, but i’d like to extend it to model 2 DV, so my parameters have a dimention for the output.

I think this is something to do with funny broadcasting, because when I don’t include the y dimension in my parameters, there is no issue (see note in code).

The example:

    #create some data
    n_d = 500
    n_x = 2
    n_g = 10
    g = np.random.randint(0, n_g, (n_d,))  # group
    x = np.random.randint(0, n_x, (n_d,))  # x factor
    true_x_effect = np.random.normal(0, 10, (n_x,))
    true_g_effect = np.random.normal(0, 10, (n_g,))
    y = np.random.normal(true_x_effect[x]+true_g_effect[g], 1)
    data = pd.DataFrame({'x':x, 'y1':y, 'g':g})
    y_vars = ['y1']
    n_y = len(y_vars)

    with pm.Model() as model:
        multi_dim_rv = pm.Normal('multi_dim_rv', mu=0, sd=1, shape=(n_x, n_g, n_y))
        indexed_rv = multi_dim_rv[data['x'], data['g'], :] #if : is replaced by 0 (effectivly removing y dimention), this works fine
        error = pm.HalfCauchy('error', 10)
        obs_data = data[y_vars].values
        obs = pm.Normal('obs', mu=indexed_rv, sd=error, observed=obs_data)
        print('dist_shape', obs.distribution.logp(data[y_vars].values).tag.test_value.shape) #shapes seem ok
        print('data_shape', obs_data.shape) #shapes seem ok
        trace = pm.sample() #samples fine.
        pm.sample_posterior_predictive(trace) #NoneConst error here.


Traceback (most recent call last):
  File "/home/bdyetton/PSleep/src/modeling/", line 323, in <module>
  File "/home/bdyetton/PSleep/src/modeling/", line 282, in test_ppc_issue
    pm.sample_posterior_predictive(trace) #NoneConst error here.
  File "/home/bdyetton/anaconda3/envs/psleep/lib/python3.7/site-packages/pymc3/", line 1167, in sample_posterior_predictive
    values = draw_values(vars, point=param, size=size)
  File "/home/bdyetton/anaconda3/envs/psleep/lib/python3.7/site-packages/pymc3/distributions/", line 627, in draw_values
  File "/home/bdyetton/anaconda3/envs/psleep/lib/python3.7/site-packages/pymc3/distributions/", line 817, in _draw_value
  File "/home/bdyetton/anaconda3/envs/psleep/lib/python3.7/site-packages/pymc3/distributions/", line 495, in random
    point=point, size=size)
  File "/home/bdyetton/anaconda3/envs/psleep/lib/python3.7/site-packages/pymc3/distributions/", line 627, in draw_values
  File "/home/bdyetton/anaconda3/envs/psleep/lib/python3.7/site-packages/pymc3/distributions/", line 851, in _draw_value
    raise ValueError('Unexpected type in draw_value: %s' % type(param))
ValueError: Unexpected type in draw_value: <class 'theano.gof.graph.Constant'>

Has anyone hit something like this before?

Versions and main components

  • PyMC3 Version: Master (8/18/19)
  • Theano Version: 1.0.4
  • Python Version: 3.7
  • Operating system: Windows 10
  • How did you install PyMC3: pip

This was a bug. See Github.