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

Support for mutable params #1016

Merged
merged 35 commits into from
Jun 23, 2021
Merged

Support for mutable params #1016

merged 35 commits into from
Jun 23, 2021

Conversation

fehiepsi
Copy link
Member

@fehiepsi fehiepsi commented Apr 21, 2021

Close #990.

This PR introduces an additional mutable_state field in SVIState, which stores parameters marked by infer={"mutable": True}. Those parameters will be skipped in the optimizer and it is the job of the model/guide to update them, e.g.

def model(...):
    p = numpyro.param("p", {"a": 1}, infer={"mutable": True}) 
    p["a"] = 10  # update p
  • Support mutable params in haiku
  • Add new primitive numpyro.mutable
  • Add a few assertations (e.g. params is None == mutable is None)
  • Consider to replicate methods with new input/output signatures

@fehiepsi fehiepsi added the WIP label Apr 21, 2021
Copy link
Member

@fritzo fritzo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @fehiepsi, could you provide some documentation somewhere (maybe in the numpyro.param docstring?) to explain what mutable params are and why they might be useful? I'm struggling to imagine a use case from the interface alone.

fritzo
fritzo previously approved these changes Jun 22, 2021
Copy link
Member

@fritzo fritzo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for your patience and for explaining the code!

Copy link
Member

@fritzo fritzo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

I hav reviewed general design and skimmed code. I have not meticulously reviewed all logic (e.g. destructured assignment) and assume tests will catch type errors.

@fritzo fritzo merged commit 5bcea01 into pyro-ppl:master Jun 23, 2021
@fehiepsi
Copy link
Member Author

Thanks for reviewing, @fritzo! Right now we don't have a good set of tests but we can exercise this pattern in PR #1056.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow propagate mutable states in SVI
2 participants