Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gen.train not updating parameters #414

Closed
JGameCreation opened this issue May 13, 2021 · 1 comment
Closed

Gen.train not updating parameters #414

JGameCreation opened this issue May 13, 2021 · 1 comment

Comments

@JGameCreation
Copy link
Contributor

Hi! I try to use Gen.train and wrote this very simple test code:

@gen function model()
    @param x_mu::Float64
    x = @trace(normal(x_mu, 1.), :x)
end
function data_generator()
    x = normal(3., 1.)
    constraints = Gen.choicemap()
    constraints[:x] = x
    return ((), constraints)
end
update = Gen.ParamUpdate(Gen.FixedStepGradientDescent(0.1), model);
init_param!(model, :x_mu, 1.0)
scores = Gen.train!(model, data_generator, update,
    num_epoch=200, epoch_size=100, num_minibatch=1, minibatch_size=100, evaluation_size=20, verbose=true);
for param in get_params(model)
    println("$param $(get_param(model, param))")
end

I would expect the parameter x_mu to be trained but it always remains unchanged.

@alex-lew
Copy link
Contributor

alex-lew commented Mar 3, 2022

@JGameCreation Sorry for the (very) late reply!

The issue here is that the ParamUpdate object needs to either:

  • manually specify a list of parameters to train, using the explicit param_list argument (
    update = ParamUpdate(conf, param_lists...)
    ); or
  • be created after the init_param! call, in which case it will train all initialized parameters.

In your example, switching the order of the init_param line and the ParamUpdate line fixes the issue. This is not documented, but definitely should be. I've opened another issue to track that (#455). Thanks for the report and sorry again for the months-late reply!

@alex-lew alex-lew closed this as completed Mar 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants