Sorry, can you clarify how to use m.named_parameters()
to get those names?
Similarly, is there a way to specify the names to be used within that nn.Sequential
? One issue I ran into was if I have two blocks of nn.Sequential (e.g. for mu and theta), I got an error that params had the same names. I got around this by writing a separate function for mu and then that function gets called in forward
.
@scope(prefix = 'mu')
def mu_func(self, in_features, h1, out_features):
mu = nn.Sequential(
nn.Linear(in_features, h1),
nn.ReLU(),
nn.Linear(h1, out_features)
)
pyro.nn.module.to_pyro_module_(mu)
for m in mu.modules():
for name, value in list(m.named_parameters(recurse=False)):
setattr(m, name, PyroSample(prior=dist.Normal(0., 3.)
.expand(value.shape)
.to_event(value.dim())))
return mu
Is there a better way to do multiple nn.Sequential?