Skip to content

Support scan for Trace_ELBO - #1693

Merged
fehiepsi merged 10 commits into
pyro-ppl:masterfrom
aleatory-science:master
Dec 18, 2023
Merged

fehiepsi merged 10 commits into
pyro-ppl:masterfrom
aleatory-science:master

Conversation

@deoxyribose

Copy link
Copy Markdown
Contributor

Issue #1685

Reuse the substitute_stack to store the replay trace, and replay the sites in the scan'ed function one iteration at a time.

@fehiepsi

fehiepsi commented Dec 4, 2023

Copy link
Copy Markdown
Member

Nice support, @deoxyribose! Could you add tests for this change?

frans added 2 commits December 6, 2023 13:12
@deoxyribose

deoxyribose commented Dec 6, 2023 •

Copy link
Copy Markdown
Contributor Author

I've added a test that does SVI with an AutoNormal guide, and checks that results are relatively accurate. I've kept model and data size to a minimum, the test takes around 3-4 seconds on my machine. There already was a test combining scan, SVI and AutoNormal (test_subsample_guide in test/infer/test_autoguide.py), but it doesn't run inference and checks results, so the current version of scan passes it.

@fehiepsi fehiepsi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks great! Thanks, @deoxyribose !

Comment thread numpyro/contrib/control_flow/scan.py Outdated
site["value"] = site["value"][i]
return site

return {k: get_ith_value(v.copy()) for k, v in replay_trace.items()}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: it is better to do the copy inside git_ith_value

@fehiepsi
fehiepsi merged commit fb7a029 into pyro-ppl:master Dec 18, 2023
@OlaRonning
OlaRonning deleted the master branch February 28, 2024 10:31
OlaRonning added a commit to aleatory-science/numpyro that referenced this pull request May 6, 2024
* scan replay handling

* fix off by one error

* cleaned a bit

* lint

* use substack

* handle custom guides

* handle empty value shape

* a

* test

* move copy inside get_ith_value

---------

Co-authored-by: frans <[email protected]>
Co-authored-by: OlaRonning <[email protected]>
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

Successfully merging this pull request may close these issues.

3 participants