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

Fixes for SimpleVarInfo with Ref #527

Merged
merged 4 commits into from
Sep 1, 2023
Merged

Conversation

torfjelde
Copy link
Member

VarInfo uses Ref for its logp-field, partially because it makes us compatible with Zygote.jl; Zygote.jl does support differentiating through mutations of Ref, though it's slow: FluxML/Zygote.jl#999

By default, SimpleVarInfo does not mutate its logp field, and so it uses a simple Real instead of a RefValue{<:Real}. This then works fine with Zygote because no mutation occurs, until we start using threads, in which case we're working with a Vector{<:Real} instead of Vector{<:RefValue{<:Real}}, as is done by default with VarInfo.

This can cause some issues when Julia is started with threads, e.g. https://discourse.julialang.org/t/error-running-museinference-jl-example/103360/4.

This PR adds more testing for SimpleVarInfo with Ref + a fix allowing proper usage with threads.

Copy link
Member

@yebai yebai left a comment

Choose a reason for hiding this comment

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

Looks good.

lp = getlogp(vi_typed)
return map((vi_untyped, vi_typed, svi_typed, svi_untyped)) do vi
return map((
Copy link
Member

Choose a reason for hiding this comment

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

It's slightly strange that we performed a functionality test for setlogp!! inside this utility function.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, maybe. But it's really not something we rely on. This is just to make the varinfos as consistent with each other as possible, i.e. they should have the same values and the same logp.

Alternatively, we can always just use zero instead, but then that would also require setlogp!! 😕

@codecov
Copy link

codecov bot commented Sep 1, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.23% 🎉

Comparison is base (549d9b1) 80.40% compared to head (e38ba9e) 80.64%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #527      +/-   ##
==========================================
+ Coverage   80.40%   80.64%   +0.23%     
==========================================
  Files          24       24              
  Lines        2776     2779       +3     
==========================================
+ Hits         2232     2241       +9     
+ Misses        544      538       -6     
Files Changed Coverage Δ
src/simple_varinfo.jl 71.27% <100.00%> (+3.49%) ⬆️
src/test_utils.jl 84.78% <100.00%> (+0.08%) ⬆️

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

@github-actions
Copy link
Contributor

github-actions bot commented Sep 1, 2023

Pull Request Test Coverage Report for Build 6048032021

  • 6 of 6 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.2%) to 80.641%

Totals Coverage Status
Change from base Build 6018544130: 0.2%
Covered Lines: 2241
Relevant Lines: 2779

💛 - Coveralls

@torfjelde torfjelde added this pull request to the merge queue Sep 1, 2023
Merged via the queue into master with commit e2178c6 Sep 1, 2023
12 of 13 checks passed
@torfjelde torfjelde deleted the torfjelde/simplevarinfo-ref-fix branch September 1, 2023 14:07
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.

2 participants