- What tutorial are you running?

Bayesian Regression - Introduction (Part 1) - What version of Pyro are you using?

Pyro Version 1.7.0 - Please link or paste relevant code, and steps to reproduce.

Hello! First and foremost, I just wanted to thank you for creating such an amazing library. I really love working with Pyro.

In the Bayesian Linear Regression tutorial, I’m trying to speed up the final step where “We generate 800 samples from our trained model.” In particular, I’m trying to set the parameter parallel=True in the Predictive class:

predictive = Predictive(model, guide=guide, num_samples=800,

return_sites=(“linear.weight”, “obs”, “_RETURN”), parallel=True)

However, when making this change I get the following error:

RuntimeError: t() expects a tensor with <= 2 dimensions, but self is 3D

Trace Shapes:

Param Sites:

Sample Sites:

sigma dist 800 1 |

value 800 1 |

linear.weight dist 800 1 | 1 3

value 800 | 1 3

linear.bias dist 800 1 | 1

value 800 | 1

Looking through this forum and the Pyro docs, I’ve tried “wrapping the existing model in an outermost `plate`

messenger” but I keep getting this error. My main question is how to modify the model used in the tutorial to support generating samples in parallel. From the tutorial, this is the original model definition that I’ve been using:

class BayesianRegression(PyroModule):

def **init**(self, in_features, out_features):

super().**init**()

self.linear = PyroModule[nn.Linear](in_features, out_features)

self.linear.weight = PyroSample(dist.Normal(0., 1.).expand([out_features, in_features]).to_event(2))

self.linear.bias = PyroSample(dist.Normal(0., 10.).expand([out_features]).to_event(1))

```
def forward(self, x, y=None):
sigma = pyro.sample("sigma", dist.Uniform(0., 10.))
mean = self.linear(x).squeeze(-1)
with pyro.plate("data", x.shape[0]):
obs = pyro.sample("obs", dist.Normal(mean, sigma), obs=y)
return mean
```

Thanks for your help!