AdamCobb / hamiltorch

PyTorch-based library for Riemannian Manifold Hamiltonian Monte Carlo (RMHMC) and inference in Bayesian neural networks
BSD 2-Clause "Simplified" License
426 stars 63 forks source link

AttributeError: 'list' object has no attribute 'parameters' #18

Closed tgautam03 closed 2 years ago

tgautam03 commented 2 years ago

Hi

I am working through your blog post and got this error when executing the following code block.

params_init = hamiltorch.util.flatten(list(net.parameters())).to(device).clone()
step_size = 0.003
num_samples = 3000
num_steps_per_sample = 1
tau_out = 1. # Must be set to 1. for 'multi_class'
params_hmc = hamiltorch.sample_model(net, x_train, y_train, params_init=params_init, num_samples=num_samples,
                               step_size=step_size, num_steps_per_sample=num_steps_per_sample, tau_out=tau_out)

I've no idea what to do here.

Thanks

AdamCobb commented 2 years ago

Could you provide the error message?

tgautam03 commented 2 years ago

I just figured it out. Modified the first line to params_init = hamiltorch.util.flatten(net).to(device).clone() and it's working now. flatten accepts model directly.

AdamCobb commented 2 years ago

OK great! Nice work :)