MCMC.run not passing all arguments?

Hi!
I am new to pyro and having a little difficulty setting up a hierarchical regression model, not sure where I am going wrong. I specified my model as:

def model( x, y, ts, bs ):
w = pyro.sample('w', pyro.distributions.Normal(0,1).expand((9,1)))

b_prior = pyro.sample('b_prior', pyro.distributions.Normal(0,1000))
b_scale = pyro.sample('b_scale', pyro.distributions.HalfCauchy(9))

b = pyro.sample('b', pyro.distributions.Normal(b_prior, b_scale).expand((201,)))                      

noise_std  = pyro.sample('noise_std', pyro.distributions.HalfCauchy(9))

z = torch.matmul(x, w ) * ts  + b[bs.long()]

with pyro.plate('data',z.shape[0]):
    pyro.sample('obs', pyro.distributions.Normal(z,noise_std), obs=y)'


nuts_kernel = pyro.infer.mcmc.NUTS(model,adapt_step_size=True)

posterior  = mcmc.MCMC(nuts_kernel,
                  num_samples=300,
                  warmup_steps=200,
                  num_chains=1).run(x, y, ts, bs )

But when I run I get:

TypeError: model() missing 2 required positional arguments: ‘ts’ and ‘bs’

If I call the model function directly with the same arguments I get the expected output. Appreciate the help!

It seems that this bug is fixed at Fix bug in initial trace setter in HMC by neerajprad · Pull Request #1675 · pyro-ppl/pyro · GitHub. Could you try again with dev branch version: pip install git+https://github.com/uber/pyro?

2 Likes

Yes! That did the trick, many thanks!

Confirming that the dev branch worked for me too. If someone doesn’t want to use the dev branch, I’ve found that passing in your data as an iterable and unpacking inside the model works just as well.

1 Like