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

link and invlink should correctly work with Selector and thus Gibbs #542

Merged
merged 12 commits into from
Oct 10, 2023

Conversation

torfjelde
Copy link
Member

TuringLang/Turing.jl#2096 is failing because the current implementations of link and invlink ignore the "space" of the sampler.

This PR makes it so that link and invlink now more closely replicates the behavior of link!! and invlink!!.

I saw "more closely" because they are still different. The "immutable" versions supports changing the sizes of the underlying storage (which is necessary when we're working with distribution whose dimensionality changes when linking, e.g. Dirichlet).

src/varinfo.jl Outdated Show resolved Hide resolved
src/varinfo.jl Outdated Show resolved Hide resolved
src/varinfo.jl Outdated Show resolved Hide resolved
src/varinfo.jl Outdated Show resolved Hide resolved
@torfjelde
Copy link
Member Author

It's worth noting that once we have TuringLang/Turing.jl#2099 all this shenanigans with Selector, etc. should slowly be phased out.

src/varinfo.jl Outdated Show resolved Hide resolved
torfjelde and others added 2 commits October 9, 2023 00:21
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@torfjelde
Copy link
Member Author

This now looks good to go @devmotion @yebai !

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.

Thanks, @torfjelde -- I have a few clarity questions below. Otherwise, this PR looks good to me.

src/varinfo.jl Show resolved Hide resolved
src/varinfo.jl Outdated Show resolved Hide resolved
) where {names,space}
vals = Expr(:tuple)
for f in names
if inspace(f, space) || length(space) == 0
Copy link
Member

@yebai yebai Oct 9, 2023

Choose a reason for hiding this comment

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

Suggested change
if inspace(f, space) || length(space) == 0
# we select all variables in `varinfo` if `space = nothing`,
if inspace(f, space) || length(space) == 0

Copy link
Member Author

Choose a reason for hiding this comment

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

space is never nothing though. At "best" it's an empty tuple. Remember, space !== vns. The scenario with vns === nothing only comes into play in the next call.

vns = metadata.vns

# Construct the new transformed values, and keep track of their lengths.
vals_new = map(vns) do vn
# Return early if we're already in unconstrained space.
if istrans(varinfo, vn)
# HACK: if `target_vns` is `nothing`, we ignore the `target_vns` check.
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 not entirely clear to me why this is a HACK.

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe HACK isn't quite the right word, but it's somewhat ugly design IMO. And the overall thing of "defining a new _getvns which does something slightly different only for a particular sampler" is hack.

@coveralls
Copy link

Pull Request Test Coverage Report for Build 6463168354

  • 32 of 33 (96.97%) changed or added relevant lines in 1 file are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.1%) to 81.518%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/varinfo.jl 32 33 96.97%
Files with Coverage Reduction New Missed Lines %
src/varinfo.jl 1 92.78%
Totals Coverage Status
Change from base Build 6251720719: 0.1%
Covered Lines: 2448
Relevant Lines: 3003

💛 - Coveralls

@codecov
Copy link

codecov bot commented Oct 10, 2023

Codecov Report

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

Comparison is base (d204fcb) 81.39% compared to head (cb2f40e) 81.51%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #542      +/-   ##
==========================================
+ Coverage   81.39%   81.51%   +0.12%     
==========================================
  Files          25       25              
  Lines        2983     3003      +20     
==========================================
+ Hits         2428     2448      +20     
  Misses        555      555              
Files Coverage Δ
src/DynamicPPL.jl 33.33% <ø> (ø)
src/varinfo.jl 92.78% <96.96%> (+0.21%) ⬆️

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

@torfjelde torfjelde enabled auto-merge October 10, 2023 09:40
@torfjelde torfjelde added this pull request to the merge queue Oct 10, 2023
Merged via the queue into master with commit 0289358 Oct 10, 2023
12 of 13 checks passed
@torfjelde torfjelde deleted the torfjelde/varinfo-link-fixes branch October 10, 2023 13:41
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