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

Pickle save for VIPosterior #951

Merged
merged 9 commits into from
Feb 22, 2024
Merged

Conversation

manuelgloeckler
Copy link
Contributor

@manuelgloeckler manuelgloeckler commented Feb 20, 2024

Will work for any default flow and VIPosterior input

  • For custom distributions, it might fail if the object is not pickable
  • For custom distributions, the build_fn is gone after saving -> Local unpickable function currently; maybe change that;
  • Add tests

@manuelgloeckler manuelgloeckler added the enhancement New feature or request label Feb 20, 2024
@manuelgloeckler manuelgloeckler self-assigned this Feb 20, 2024
@manuelgloeckler manuelgloeckler linked an issue Feb 20, 2024 that may be closed by this pull request
@manuelgloeckler manuelgloeckler added the blocked Something is in the way of fixing this. Refer to it in the issue label Feb 20, 2024
@manuelgloeckler
Copy link
Contributor Author

Blocked by PyRight #848 .

Copy link

codecov bot commented Feb 21, 2024

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (2830fda) 76.02% compared to head (ccac2bc) 76.09%.
Report is 2 commits behind head on main.

Files Patch % Lines
sbi/inference/posteriors/vi_posterior.py 96.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #951      +/-   ##
==========================================
+ Coverage   76.02%   76.09%   +0.06%     
==========================================
  Files          80       80              
  Lines        6319     6341      +22     
==========================================
+ Hits         4804     4825      +21     
- Misses       1515     1516       +1     
Flag Coverage Δ
unittests 76.09% <97.14%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@manuelgloeckler
Copy link
Contributor Author

Here is a small summary about what was changed

VIPosterior pickle support

To make the VIPosterior pickable and deepcopy compatible, unpickable files must be removed and manually rebuilt.

  • To support pickle on has to override __setstate__ (rebuilding removed stuff) and __getstate__ (removing unpickable stuff).
  • The __deepcopy__ protocol uses this function by default. Necessary modifications to make it pickable, however, make it incompatible with deep copy (at least in some relevant cases, covered by tests). This requires overriding __deepcopy__.
  • In addition to the deep copy tests, I added a pickle test (uses torch.save, and deletes it afterwards)

Pyright Fix

  • Fixed all pyright errors (given current pyright version)
  • Errors due to insufficient type information in external libraries is ignored using notype

@manuelgloeckler manuelgloeckler removed the blocked Something is in the way of fixing this. Refer to it in the issue label Feb 22, 2024
Copy link
Contributor

@janfb janfb left a comment

Choose a reason for hiding this comment

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

Great, thanks for fixing this!! 👍

Just some documentation comments. feel free to merge once they are addressed.

sbi/inference/posteriors/vi_posterior.py Show resolved Hide resolved
sbi/inference/posteriors/vi_posterior.py Show resolved Hide resolved
sbi/inference/posteriors/vi_posterior.py Outdated Show resolved Hide resolved
sbi/samplers/mcmc/slice.py Show resolved Hide resolved
tests/vi_test.py Outdated Show resolved Hide resolved
@manuelgloeckler manuelgloeckler merged commit ee7e9a3 into main Feb 22, 2024
3 checks passed
@janfb janfb deleted the 684-viposterior-object-cant-save branch June 20, 2024 10:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

VIPosterior object can't save
2 participants