Hi!
I am writing again about the same issue posted here: PyroModule for LSTM.
I have been following this example : Neural Networks — Pyro documentation
But either there is a bug or I am not doing something in the right order, hehe
Pseudo code of my model:
def Convert_to_PyroSample(model):
for m in model.modules():
for name, value in list(m.named_parameters(recurse=False)):
setattr(m, name, PyroSample(prior=dist.Normal(0, 1).expand(value.shape).to_event(value.dim())))
class GRU(nn.Module): # I am not sure whether this should already be PyroModule (with either option the error persists)
def __init__(self):
super(...)
self.GRU = nn.GRU(flags...)
self.h_0 = nn.Parameter(torch.rand(GRU_hidden_size), requires_grad = True) #Shuld it be converted to PyroParam here?
def forward(self,input):
to_pyro_module(self.GRU)
Convert_to_PyroSample(self.GRU)
h_0_contig = PyroParam(self.h_0.repeat(...).contiguous()) # Not convinced about this
output,_ = self.GRU(input, h_0_contig)
return output
a) If I try to convert h_0_contig to PyroParam I get this error:
File “/home/…/anaconda3/lib/python3.7/site-packages/torch/nn/modules/rnn.py”, line 175, in check_hidden_size
if hx.size() != expected_hidden_size:
AttributeError: ‘PyroParam’ object has no attribute ‘size’
b) If I don’t bother with PyroParam I get the same error as in https://forum.pyro.ai/t/pyromodule-for-lstm/1596.:
File “/home/…/anaconda3/lib/python3.7/site-packages/torch/nn/modules/rnn.py”, line 716, in forward
self.dropout, self.training, self.bidirectional, self.batch_first)
TypeError: expected Tensor as element 0 in argument 2, but got PyroSample
I am just confused on the semantics, thanks for your help in advance! I am using pyro 1.3.0
Best wishes