-
Notifications
You must be signed in to change notification settings - Fork 35
Remove context
from model evaluation (use model.context
instead)
#952
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
Conversation
context
from model evaluation (use model.context
instead)
Benchmark Report for Commit fa90d1cComputer Information
Benchmark Results
|
DynamicPPL.jl documentation for PR #952 is available at: |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## breaking #952 +/- ##
============================================
+ Coverage 82.55% 82.94% +0.38%
============================================
Files 38 38
Lines 4075 4068 -7
============================================
+ Hits 3364 3374 +10
+ Misses 711 694 -17 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
04404b3
to
1dc56f6
Compare
That's an excellent direction. When duplicate contexts were first introduced, I was always bothered by them. We merged the relevant PRs to avoid blocking incremental improvements. |
One minor comment on naming: |
I'd be happy to rename. Will wait for @mhauru to review before doing it -- though I also realise that about 99% of usecases for |
Comparing to this, this runtime seems to have ~doubled:
Not the end of the world, but any idea why? LDA has also gotten slower but I care less because it's so bad anyway. |
The time on this branch is the same as on the breaking branch, though: so maybe it came from an earlier merge into there? I'm just in the process of updating all those branches so can take a look in a while |
Also, while you're on leave, maybe this is a nice time for me to try to hack together something to monitor benchmark patterns over time haha |
My bad, I wasn't thinking when picking the thing to compare to. Nothing to do there then. I'm still mid-review, but wondering about what to do about accumulators. I would like to say that I was hasty in merging the first accumulator stuff into |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really like this PR. Just a few tiny typos and a couple of questions about code style.
# ^ Weird Documenter.jl bug means that we have to write the two above separately | ||
# as it can only detect the `function`-less syntax. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there's an issue to track for this could link it. No worries if not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few issues about callable structs but I couldn't find one that was explicitly about this. I'll try to make an MWE
d751976
to
fa90d1c
Compare
Okay, I fixed all the stuff. I renamed it to I think the main argument for releasing it now is that I could use it upstream in some of the Turing sampler + LDF work, but I'm actually happy to hold off on that until we have a resolution to #955, and #955 in turn certainly needs to wait for accs to be done. So I think the happiest course of action is just for me to find other things to do until we are ready to release accs. |
Your argument for why it's okay to build this on top of accumulators is convincing and relieving. |
Summary
This PR modifies the model evaluation function,
model.f
for somemodel::DynamicPPL.Model
, to not take a context as its third argument. Thus, its signature looks likef(model, varinfo, args...; kwargs...)
whereargs
andkwargs
are forwarded from the function that defines the model.During model evaluation, the tilde-pipeline would always dispatch on the
__context__
argument, and would completely ignore the__model__.context
. It has now been changed so that it dispatches on__model__.context
.As a result of this, we can remove the
context
argument from most model evaluation code as well as LogDensityFunction. This simplifies a lot of code.There are a handful of minor follow-up points:
Combination of
__context__
and__model__.context
Inside the model evaluation function, the model's context was previously being ignored. However, if one were to call
evaluate!!(model, varinfo, context)
, the model's context does not get ignored: it is combined together withcontext
in order to form a larger context stack, which then becomes the actual evaluation context.DynamicPPL.jl/src/model.jl
Lines 942 to 944 in 3e54c2d
After this PR, the intention is that if you want to keep that combining behaviour, you should do it manually. However, several 'outs' are provided:
sample!!(rng, model, varinfo, sampler)
is provided. This wrapsmodel.context
in aSamplingContext(rng, sampler)
before callingevaluate!!
. This takes care of most invocations ofevaluate!!
where this combining behaviour was being used.(As a bonus, this also helps us remove the rng and sampler arguments from
evaluate!!
, which greatly simplifies that function:evaluate!!
shenanigans #720)evaluate!!(model, varinfo, context)
still exists, but is dep-warned._evaluate!!(model, varinfo, context)
still exists with the same behaviour without a depwarn. This is only retained because submodels depend on this and I would like to leave this change for a subsequent PR, as that needs to be reasoned about more deeply.Models as callables
Previously,
(model::Model)(args...)
would forward toevaluate!!(args...)
. I think this behaviour is quite dangerous (#629) and even in that PR it was mentioned that we should be more explicit about what args we take, which I fully agree with.Along with cleaning up
evaluate!!
, this PR also cleans up models as callables such that the only allowed signatures aremodel()
,model(rng)
,model(varinfo)
, andmodel(rng, varinfo)
. Thus you are no longer allowed to specify a context (you shouldcontextualize
the model instead), or a sampler (the default sampler wasSampleFromPrior()
and given thatmodel(...)
was always being used to sample from the prior, it seems hugely unlikely that anybody was really passing a different sampler, and if they were, they can jolly well callfirst(DynamicPPL.sample!!(rng, model, varinfo, sampler))
).Remaining test failure
The remaining test failure (Julia-pre) is unrelated to this PR.
Closes #951
This is a step towards fixing #720 but it's not complete; that will have to wait for #960