Skip to content

Bayesian regression example doesn’t work with N=1 #717

@lazypanda1

Description

@lazypanda1

Hi,

When I run the bayesian_regression.py example on github, with N = 1 on line 44, I get an error from Tensor flow. Is there an assumption that N must be at least 2? While values of N < 2 may be corner cases, Pyro could improve user experience by explicitly checking N values and giving users a more friendly error message, rather than sending bad values to Tensor flow. Here’s the error with N=1:

$ python bayesian_regression.py
Traceback (most recent call last):
   File "bayesian_regression.py", line 140, in <module>
 	main(args)
   File "bayesian_regression.py", line 117, in main
 	epoch_loss = svi.step(data)
   File "/usr/local/lib/python2.7/dist-packages/pyro/infer/svi.py", line 98, in step
 	loss = self.loss_and_grads(self.model, self.guide, *args, **kwargs)
   File "/usr/local/lib/python2.7/dist-packages/pyro/infer/elbo.py", line 65, in loss_and_grads
 	return self.which_elbo.loss_and_grads(model, guide, *args, **kwargs)
   File "/usr/local/lib/python2.7/dist-packages/pyro/infer/trace_elbo.py", line 181, in loss_and_grads
 	torch_backward(surrogate_loss)
   File "/usr/local/lib/python2.7/dist-packages/pyro/infer/util.py", line 34, in torch_backward
 	x.backward()
   File "/usr/local/lib/python2.7/dist-packages/torch/autograd/variable.py", line 167, in backward
 	torch.autograd.backward(self, gradient, retain_graph, create_graph, retain_variables)
   File "/usr/local/lib/python2.7/dist-packages/torch/autograd/__init__.py", line 99, in backward
 	variables, grad_variables, retain_graph)
RuntimeError: matrices expected, got 3D, 2D tensors at /pytorch/torch/lib/TH/generic/THTensorMath.c:1411
"

Environment:

Python version : 3.6
Pyro version: 0.1.2
Pytorch version: 0.3.0post4

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions