Hello,
I am trying to convert a PyTorch neural network model into a Bayesian Pyro model.
I want to avoid the StopIteration
error (see below) that arises when I execute the command next(myPyTorchModel.parameters()).device
, where myPyTorchModel
is a Pyro model.
To be more specific, before converting my PyTorch model into a Pyro model, when I execute the command next(myPyTorchModel.parameters()).device
, I get the following output:
device(type='cpu')
Whereas when I execute the same command after converting my PyTorch model into a Pyro model, I get output like below:
module.to_pyro_module_(myPyTorchModel)
for m in myPyTorchModel.modules():
for name, value in list(m.named_parameters(recurse=False)):
setattr(m, name, module.PyroSample(prior=dist.Normal(0, 1)
.expand(value.shape)
.to_event(value.dim())))
next(myPyTorchModel.parameters()).device
OUTPUT: File "<ipython-input-9-be50535fd794>", line 1, in <module>
next(myPyTorchModel.parameters()).device
StopIteration
How can I prevent this StopIteration
error with Pyro models?
Thank you,