-
Notifications
You must be signed in to change notification settings - Fork 36
Allow user to track specific varnames #846
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
a677b07
to
bb8adb7
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## breaking #846 +/- ##
============================================
- Coverage 84.60% 84.56% -0.05%
============================================
Files 34 34
Lines 3832 3841 +9
============================================
+ Hits 3242 3248 +6
- Misses 590 593 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
4206707
to
62e4ed5
Compare
@torfjelde @mhauru I primarily wanted to get your thoughts on whether this makes sense, but if you think it does, then the PR is also ready for proper code review :) (Separate question: should we also allow users to specify symbols (which we can convert to VarNames easily)?) |
f8114d6
to
06d6e4e
Compare
It does feel like which variables to collect into a chain should rightfully be the concern of I'll hold back from reviewing the implementation until others have commented on the design and interface. |
I'm personally a bit worried about opening the can of worms that is "more fields in Is there a reason why this isn't just part of the |
I did already add it to part of the method signature. However, if it's restricted to just that, then there's no clear way for the user to control it, since the user doesn't have an easy hook into The main alternative I see would be to change the signature of |
But even this doesn't give the user an easy way to hook into it, unless we also go the full distance and implement the keyword argument to Basically the question is how can we give the user a way to specify the varnames to keep, that doesn't involve adding a kwarg to |
Can we encode these in the model's embedded |
We could, but what benefit do you see in doing that compared to having a separate field? It might seem tidier when looking at the definition of the Model struct, but under the hood there's the same amount of complexity. Also imo it doesn't really belong to the context (for example the tilde pipeline doesn't need that information when evaluating the model). |
Haha, yeah basically 😬 |
ok, let's do it properly then, it'll probably take a couple of months 😅 |
Summary
This implements the suggestion in #845 by:
DynamicPPL.Model
, calledtracked_varnames
DynamicPPL.set_tracked_varnames
, which allows the user to set this field and thus specify which varnames are to be tracked;values_as_in_model
to usetracked_varnames
appropriately.It also separates the tests for
values_as_in_model
into their own file (previously they were scattered intest/model.jl
andtest/compiler.jl
)I tested this PR together with the version of Turing.jl in TuringLang/Turing.jl#2487 and can confirm that this works as intended:
Possible alternatives: dispatch
In #845 I suggested using a different dispatch-based method to control which varnames were tracked:
The thing I don't like about this is that it's not possible (or at best, awkward) to run the same model twice while collecting different variables, as it would depend on whether the method is defined or not. Having it as a field on the model is much cleaner.
Possible alternatives: kwarg to
sample
The cleanest user interface would probably be to add a keyword argument to
sample
. This is, of course, very complicated, sincesample
lives in AbstractMCMC and it's not obvious that varnames are general enough to merit appearing there. In my opinion this will have to wait for AbstractMCMC to be refactored in a way that it can take a generic type for 'parameter names', and then DynamicPPL can set that type to be VarName. See also TuringLang/Turing.jl#2511.However, the fact that
values_as_in_model
also takes an argument would allow us to fairly easily implement this on the DynamicPPL end when the time comes, because the keyword argument tosample
can just be passed through the chain of calls.TODOs
Closes #845