-
Notifications
You must be signed in to change notification settings - Fork 35
[Merged by Bors] - Simplification of tilde-callstack #252
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
right::MultivariateDistribution, left::AbstractMatrix, vn::VarName | ||
) | ||
vns = map(axes(left, 2)) do i | ||
return VarName(vn, (vn.indexing..., Tuple(i))) |
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.
Slightly confused here - is the argument Tuple(i)
redundant with vn.indexing
?
EDIT: Got the answer after reading the previous code. Maybe consider adding a comment here?
bors try |
tryBuild failed: |
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.
Can you add deprecations to make it non-breaking?
Actually, how would I do this? E.g. there's no "equivalent" for |
Luckily Part of the API are only DynamicPPL.jl/src/DynamicPPL.jl Lines 84 to 89 in 5ffbbd2
(BTW it seems there is a typo?! I am quite certain we intended to export |
Ooooh I didn't think we exported any of these! But cool, then I'll do that 👍 |
Wait, isn't guaranteed to be breaking since |
AFAICT |
Oh yeah true, haha. Weird that we even export |
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Looks good but it would be good to wait until Turing is compatible with DynamicPPL 0.11 since otherwise we can't run the integration tests properly. |
bors try |
tryBuild failed: |
Btw, @devmotion how do you think we should implement |
Aaah they're disabled by default? I was thinking of the same but didn't bother suggesting it since I thought this would mean that people just using DPPL would see the dep-warnings. Hmm, kind of annoying though 😕 Maybe just better to make a breaking release together with #253 ? |
Personally I think it would be better to make a non-breaking release and add the deprecation warnings, and also to keep the PRs separate. We can keep the deprecations only for a short time but it would keep DynamicPPL and Turing better synced and it would give us a bit more time to fix the deprecations in Turing. It just feels more relaxed. |
But aren't we going to make a new breaking release of DPPL very soon anyways, following merging of #253 ? So the process is:
I'll do it though, but it just seems unnecessary since this PR itself adds no new functionality and so the result for the user is the same whether this PR makes it in or not. And so we might as well just wait with merging this PR until we've merged #253 into it. |
I don't have a very strong opinion but my feeling is that deprecations and non-breaking releases would be helpful, despite the additional effort. A non-breaking release is picked up by Turing automatically and does not require any fixes which might create delays and cause problems if we want to propagate other non-breaking changes or bugfixes to Turing while doing the refactoring. It requires additional commitment and effort if we want to minimize this delay since we basically have to fix the breaking changes immediately in Turing whereas deprecations don't have to be fixed right away. BTW is #253 actually breaking? The |
That's actually a good point, but if we deprecate the code for wrapper-contexts, e.g. function tilde_assume(...)
# do stuff
...
# Here we're currently calling `tilde_assume` again, which makes sense.
# But now we have to call `tilde`, which is then forwarded to `tilde_assume`.
return tilde(...)
end I'm not sure this makes our lives easier when making changes 😅
Yes because you have stuff like https://github.com/TuringLang/Turing.jl/blob/c79dce028b3edd0be284bf28b13d83956606b786/src/inference/ess.jl#L138-L144 and https://github.com/TuringLang/Turing.jl/blob/c79dce028b3edd0be284bf28b13d83956606b786/src/modes/ModeEstimation.jl#L27-L39. These will break. |
Only if we go with my suggestion I assume? If (probably only initially) we just unwrap function tilde_assume(c::SamplingContext, ...)
return tilde(c.rng, c.sampler, ....)
end etc., then these definitions would still be reached it seems. This would also avoid any issues regarding propagating it downwards, unwrapping etc since the logic would be exactly the same. Actually, that's what I assumed we would do as a start and hence I became a bit confused by all our discussions lately 😄 Then we could first fix the tilde pipeline deprecations in Turing and then start to modify and improve the pipeline in DynamicPPL in a second step. But ultimately I think you should decide if you want to aim for a non-breaking release in this PR and include the deprecations since you are working on it and it would be additional work for you. |
Ughh yeah true. I've gotten a bit too tunnel-visioned on the separation between sampling and evaluation.
I.e. if we're making that change and want it to be non-breaking, it's literally just a refactoring that the users never see 😕
I'm strongly leaning towards just breaking 😕 It's just because we're going to need to do some signficant work on downstream packages to accomodate the changes anyways, and the non-breaking changes we can make are both somewhat annoying (e.g. having to call I really prefer just merging into this PR, and then making sure that integration-tests pass, before making one big breaking release. From an end-user perspective, there will be no difference between this and making the non-breaking releases first. |
I think it's ok to make a breaking release if we can
It is worth noting that there are several non-Turing packages (indirectly) depending on DynamicPPL, e.g. |
Just checked real quick, and none of those touch the internals of DPPL, e.g. overloading |
src/context_implementations.jl
Outdated
end | ||
function tilde(rng, ctx::PriorContext, sampler, right, vn::VarName, inds, vi) | ||
function tilde_assume(rng, ctx::PriorContext, sampler, right, vn::VarName, inds, vi) |
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.
Can't we get rid of inds
at this place, too? The value of it is (kind of by implicit contract) supposed to be the same as vn.indexing
anyway. The only reason for its existence I can remember is that is seemed convenient to me for AutoGibbs...
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'm also of the opinion that we should do stuff like that, but I figured I'd leave it out of this particular PR and remove such redundancies later.
Btw, would love to hear your thoughts on #253 :)
This is #253 but the only motivation here is to get `SamplingContext` in, nothing relating to interactions with other contexts, etc. Co-authored-by: Hong Ge <[email protected]>
Codecov Report
@@ Coverage Diff @@
## master #252 +/- ##
===========================================
- Coverage 74.50% 62.90% -11.61%
===========================================
Files 15 15
Lines 1216 1294 +78
===========================================
- Hits 906 814 -92
- Misses 310 480 +170
Continue to review full report at Codecov.
|
Co-authored-by: David Widmann <[email protected]>
Looks like we're ready to go? |
Oh actually, I guess we should wait for #261. |
Are we ready to give bors the 👍 ? This won't be affected by the libtask issue since we're not testing Turing in the integration tests. |
bors try |
bors r+ |
This PR introduces the simplification of the tilde-callstack as discussed in #249. Copy-pasted from there: - Remove unnecessary complexity in `~` implementation. - Current calling hierarchy for a `~` statement is: - `tilde_assume` -> `tilde(rng, ...)` -> `_tilde(rng, ...)` -> `assume` - `tilde_observe` -> `tilde(...)` -> `_tilde(...)` -> `observe` - Similarly for `dot_tilde_assume` and `dot_tilde_observe`. - This is super-confusing and difficult to debug. - `_tilde` is currently only used for `NamedDist` to allow overriding the variable-name used for a particular `~` statement. - Propose the following changes: - Remove `_tilde` and handle `NamedDist` _before_ calling `tilde_assume`, etc. by using a `unpack_right_vns` (and `unpack_right_left_vns` for dot-statements) (thanks to @devmotion) - Rename `tilde_assume` (`tilde_observe`) and to `tilde_assume!` (`tilde_observe!`), and `tilde(rng, ...)` (`tilde(...)`) to `tilde_assume(rng, ...)` (`tilde_observe(...)`). - `tilde_assume!` simply calls `tilde_assume` followed by `acclogp(varinfo, result_from_tilde_assume)`, so the `!` here is to indicate that it's mutating the `logp` field in `VarInfo`. Co-authored-by: Hong Ge <[email protected]>
This PR introduces the simplification of the tilde-callstack as discussed in #249.
Copy-pasted from there:
~
implementation.~
statement is:tilde_assume
->tilde(rng, ...)
->_tilde(rng, ...)
->assume
tilde_observe
->tilde(...)
->_tilde(...)
->observe
dot_tilde_assume
anddot_tilde_observe
._tilde
is currently only used forNamedDist
to allow overriding the variable-name used for a particular~
statement._tilde
and handleNamedDist
before callingtilde_assume
, etc. by using aunpack_right_vns
(andunpack_right_left_vns
for dot-statements) (thanks to @devmotion)tilde_assume
(tilde_observe
) and totilde_assume!
(tilde_observe!
), andtilde(rng, ...)
(tilde(...)
) totilde_assume(rng, ...)
(tilde_observe(...)
).tilde_assume!
simply callstilde_assume
followed byacclogp(varinfo, result_from_tilde_assume)
, so the!
here is to indicate that it's mutating thelogp
field inVarInfo
.