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

Remove dot_tilde pipeline #804

Merged
merged 18 commits into from
Feb 18, 2025
Merged

Remove dot_tilde pipeline #804

merged 18 commits into from
Feb 18, 2025

Conversation

mhauru
Copy link
Member

@mhauru mhauru commented Feb 7, 2025

This PR reimplements .~ so that it is turned into a loop over ~ statements at macro time. It also restricts the RHS of .~ to be a univariate distribution. This breaks code where either an array of distributions or a multivariate distribution was used on the RHS. The former case can easily be worked around by rather using ~ product_distribution(...) (and performance is in many cases improved by it), the latter case is presumably rare and can be worked around by using a loop.

All the real changes are in compiler.jl and the tests. Everything else is just deleting code that is no longer needed after this change.

Copy link

codecov bot commented Feb 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.43%. Comparing base (4b9665a) to head (30c241f).
Report is 1 commits behind head on release-0.35.

Additional details and impacted files
@@               Coverage Diff                @@
##           release-0.35     #804      +/-   ##
================================================
- Coverage         86.32%   84.43%   -1.90%     
================================================
  Files                35       34       -1     
  Lines              4162     3823     -339     
================================================
- Hits               3593     3228     -365     
- Misses              569      595      +26     

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

@coveralls
Copy link

coveralls commented Feb 7, 2025

Pull Request Test Coverage Report for Build 13377908373

Details

  • 37 of 37 (100.0%) changed or added relevant lines in 2 files are covered.
  • 57 unchanged lines in 11 files lost coverage.
  • Overall coverage decreased (-1.9%) to 84.525%

Files with Coverage Reduction New Missed Lines %
src/context_implementations.jl 2 81.25%
src/debug_utils.jl 2 0.0%
src/sampler.jl 3 90.63%
src/threadsafe.jl 4 57.14%
src/utils.jl 4 73.36%
src/distribution_wrappers.jl 5 38.89%
src/varinfo.jl 5 82.17%
src/values_as_in_model.jl 6 66.67%
src/extract_priors.jl 8 71.43%
src/compiler.jl 9 85.96%
Totals Coverage Status
Change from base Build 13376471008: -1.9%
Covered Lines: 3228
Relevant Lines: 3819

💛 - Coveralls

@@ -139,8 +139,6 @@

@testset "SimpleVarInfo on $(nameof(model))" for model in
DynamicPPL.TestUtils.DEMO_MODELS
model = DynamicPPL.TestUtils.demo_dot_assume_matrix_dot_observe_matrix()
Copy link
Member Author

Choose a reason for hiding this comment

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

Note that this line was making us always test one single model, even though we were ostensibly in a loop over models. Presumably this got committed by accident at some point.

Comment on lines +156 to +159
# TODO(mhauru) Fix linked SimpleVarInfos to work with our test models.
# DynamicPPL.settrans!!(deepcopy(svi_nt), true),
# DynamicPPL.settrans!!(deepcopy(svi_dict), true),
# DynamicPPL.settrans!!(deepcopy(svi_vnv), true),
Copy link
Member Author

Choose a reason for hiding this comment

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

If you remove the line a bit above, that was fixing the model, it turns out that even on master many of the models fail with linked SimpleVarInfos. Some passed, I'm not sure what it was that made the difference. Presumably some quirk of SimpleVarInfo interacted badly with some types of models.

With the new implementation of .~ all of the test models fail with linked SimpleVarInfos. I assume its the same problem as before, but now manifesting itself in all test models, due to changes in the test models. Hence commenting out these three. I wouldn't really call this a regression in tests, in that these only ever passed for a few select models, whereas now at least we check the unlinked SimpleVarInfos for all models.

@mhauru
Copy link
Member Author

mhauru commented Feb 7, 2025

One single test in pointwise_logdensities fails still, something about converting to Chains. I'll figure it out next week. If anyone wants to review the main changes in compiler.jl in the meanwhile, feel free.

@torfjelde
Copy link
Member

Will leave approval to someone who is more hands on, but really like this:)

One thing: seems like this would warrant a bump of the minor version given it's breaking?

@mhauru
Copy link
Member Author

mhauru commented Feb 10, 2025

Thanks @torfjelde!

One thing: seems like this would warrant a bump of the minor version given it's breaking?

The PR is proposed to be merged to the release-0.35 branch which includes a bunch of other breaking changes and a minor version bump.

@mhauru mhauru requested a review from penelopeysm February 12, 2025 18:13
@mhauru
Copy link
Member Author

mhauru commented Feb 12, 2025

The remaining test failures are Mooncake issues. Not sure what to do about them (mark as broken?), but it does make this ready for review.

@mhauru
Copy link
Member Author

mhauru commented Feb 13, 2025

@willtebbutt confirms that the Mooncake test failures are an instance of compintell/Mooncake.jl#319, which in turn is caused by a Julia compiler bug.

@penelopeysm
Copy link
Member

penelopeysm commented Feb 13, 2025

I'm happy to approve on the code changes, but I'm hesitant to click on the button because I'm still very curious about the Mooncake errors. I managed to get a simple model with a literal on the LHS to error (see compintell/Mooncake.jl#484 for context) and I'm extremely confused by why it happens only with one model and not the others, and only in some cases but not.

I'd like to understand, from the DynamicPPL point of view, what it is in that one model that gives it problems.

@penelopeysm
Copy link
Member

I'm also aware that could be a huge time sink, and could easily be one day of good work.

@willtebbutt
Copy link
Member

willtebbutt commented Feb 13, 2025

FWIW, I would only say that it's a good use of time to get to the bottom of why one DynamicPPL model triggers this only if you're keen to practice your compiler-debugging skills. I'm hoping to have a patch sorted by the end of the day, so if you're happy to hold off on pressing the button for a few hours, it should go away anyway.

@penelopeysm
Copy link
Member

penelopeysm commented Feb 14, 2025

Rewriting

@model function f() # errors!
    s ~ InverseGamma(2, 3)
    m ~ Normal(0, sqrt(s))
    [1.5, 2.0] .~ Normal(m, sqrt(s))
end

into

@model function f() # fine!
    s ~ InverseGamma(2, 3)
    m ~ Normal(0, sqrt(s))
    [1.5, 2.0][(1,)...] ~ Normal(m, sqrt(s))
    [1.5, 2.0][(2,)...] ~ Normal(m, sqrt(s))
end

avoids the Mooncake error. In fact, even

@model function f() # also fine!
    s ~ InverseGamma(2, 3)
    m ~ Normal(0, sqrt(s))
    x = [1.5, 2.0]
    for idx in Iterators.product(axes(x)...)
        x[idx...] ~ Normal(m, sqrt(s))
    end
end

is perfectly fine. I don't know why the current implementation of .~ is problematic, but I wonder if there is a workaround that will let us circumvent the Mooncake issue.


BTW, while digging into this, I found that there are other demo models (e.g. demo_assume_observe_literal, but basically anything with a literal on the LHS) which Mooncake errors on if we call

This was an error on my part, see compintell/Mooncake.jl#484 (comment) for context.

Copy link
Member

@penelopeysm penelopeysm left a comment

Choose a reason for hiding this comment

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

I concede defeat

@penelopeysm
Copy link
Member

Maybe mark the tests as broken, but that's about it

@mhauru
Copy link
Member Author

mhauru commented Feb 14, 2025

Over in compintell/Mooncake.jl#319 @willtebbutt said he wanted to see if he could put in a quick workaround, so I'll wait to hear from him first, but I'm happy to mark as broken if need be.

@penelopeysm
Copy link
Member

Oh, okay, we can wait then!

@willtebbutt
Copy link
Member

willtebbutt commented Feb 14, 2025

Just to double check I'm interpreting CI results correctly: am I right in saying that compintell/Mooncake.jl#319 is only causing this PR problems on Julia 1.11, not 1.10?

(This would make sense, as the offending code only appears to appear in the compiler in 1.11.)

@mhauru
Copy link
Member Author

mhauru commented Feb 14, 2025

Just to double check I'm interpreting CI results correctly: am I right in saying that compintell/Mooncake.jl#319 is only causing this PR problems on Julia 1.11, not 1.10?

Yup, so it seems.

@willtebbutt
Copy link
Member

Fab. I'm just waiting for CI to pass in compintell/Mooncake.jl#487 , then I'll make a release which should fix the problem.

@willtebbutt
Copy link
Member

v0.4.90 ought to solve the problem :)

@mhauru mhauru requested a review from penelopeysm February 18, 2025 10:32
Copy link
Member

@penelopeysm penelopeysm left a comment

Choose a reason for hiding this comment

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

Sorry, I didn't mean to rescind my original approval with that change above. Happy to merge!

@mhauru mhauru merged commit f5e84f4 into release-0.35 Feb 18, 2025
17 of 18 checks passed
@mhauru mhauru deleted the mhauru/dot-tilde-to-loops branch February 18, 2025 17:15
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.

5 participants