Remove LogDensityFunctionWrapper and replace VarInfo(mld, ...) with InitFromVector#1335
Remove LogDensityFunctionWrapper and replace VarInfo(mld, ...) with InitFromVector#1335anurag-mds wants to merge 6 commits intoTuringLang:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1335 +/- ##
==========================================
- Coverage 78.59% 78.58% -0.02%
==========================================
Files 50 50
Lines 3626 3624 -2
==========================================
- Hits 2850 2848 -2
Misses 776 776 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
b2d8a8a to
fcca4c7
Compare
|
I’d suggest we keep VarInfo. |
|
I wholly disagree -- the varinfo generated contained wrong data, and it's not something we should be giving people to use. |
|
Ah, okay, maybe I didn't fully get the motivation. Let's chat when we meet. |
|
Actually I used the JuliaFormatter once directly as using JuliaFormatter
format(".")This changed multiple files and also throwed many warnings saying The formatter couldn't be applied here. then I ran for the specific files I changed using JuliaFormatter
format(["HISTORY.md", "docs/make.jl", "docs/src/api.md", "ext/DynamicPPLMarginalLogDensitiesExt.jl", "test/ext/DynamicPPLMarginalLogDensitiesExt.jl"])the formatter worked and I pushed the code but still formatting CI is failing I can't get it why? |
|
Are you using JuliaFormatter v1? https://turinglang.org/docs/contributing/code-formatting/ |
docs/src/api.md
Outdated
|
|
||
| ```@docs | ||
| VarInfo(::MarginalLogDensities.MarginalLogDensity{<:DPPLMLDExt.LogDensityFunctionWrapper}, ::Union{AbstractVector,Nothing}) | ||
| InitFromVector(::MarginalLogDensities.MarginalLogDensity{<:DynamicPPL.LogDensityFunction}, ::Union{AbstractVector,Nothing}) |
There was a problem hiding this comment.
I am concerned that InitFromVector is not a super clear name and that we may need to rename it later, whereas VarInfor is more stable.
There was a problem hiding this comment.
It already exists, though: https://turinglang.org/DynamicPPL.jl/stable/ldf/models/ and it's not really that complicated to use.
I'm conscious of backwards compatibility, but I really strongly believe that VarInfo is not the right thing to keep around. As you are aware, there have been many perf gains in DynamicPPL recently. But we haven't managed to do that because I'm some hacker Linus Torvalds genius who optimised low level code: they're just because we have better, more modular, interfaces that don't make users pay for things that they don't need.
VarInfo is the exact antithesis of that: it's a struct that bundles lots of stuff together and forces users to pay for things they don't need. Besides the performance issues, it also leads to incorrect results with unflatten!! because log-probs and transforms are not updated in tandem with the parameters, which is an issue I've pointed out many times. That's exactly the reason why I think we should remove this method.
If we want Turing/DynamicPPL to be something that people trust, then correctness is very, very important. I think it's the single most important thing, even more so than performance.
2bfc892 to
effb450
Compare
Fixed: was using the wrong JuliaFormatter version. Formatting CI passed now. |
|
I haven't commented yet as I was following the discussion between the maintainers regarding the interface design. I just wanted to clarify: was the change mentioned by @yebai intended for me to implement, or was it a request for @penelopeysm’s approval? If it is for me, I will update the name from Could you also clarify if |
|
It's a typo. And it's not just about the name, it's really about the interface design. I don't really want to repeat myself, so I'll just point to #1308 (comment). |
|
Hi @penelopeysm, I ran into two issues: Issue 1:
Because My suggestion is to use an anonymous function instead:
This captures Issue 2: Tracer types -- Could you confirm whether this is the right fix? |
|
Ahh, yes, darn. We still need some kind of wrapper around LogDensityFunction. You can use an anonymous function, I think I generally prefer a callable struct though because (1) it's easier to dispatch on in type signatures, and (2) also easier to compare (every new anonymous function declaration creates a separate one). julia> (x -> x + 1) == (x -> x + 1)
falseSo the only new thing is that the wrapper doesn't store a VarInfo anymore, sorry to mislead on that. The tracer types should subtype Real. What are the types that you are having trouble with? |
05347ca to
35fe956
Compare
69a1419 to
50d6cfa
Compare
9d84c10 to
d204804
Compare
|
Hey @penelopeysm, Can you check the PR? |
|
I'll look at it next week when I'm back at work, but I'll self-request a review so that it doesn't slip off the radar. |
LogDensityFunctionWrapperwas a trivial struct whose sole purpose was to convert theLogDensityFunctiontype to the two-argument callable signature expected byMarginalLogDensities, and to carry aVarInfoto be reconstructed later. ButLogDensityFunctionalready contains all the information we'll ever need (it contains both the model and thetransform_strategyas well as_varname_ranges), so this wrapper was unnecessary. I removed it and added a two-argument callable method toLogDensityFunctionin the extension.The
VarInfo(mld, ...), which this method enabled, was also problematic because it would unflatten parameter values into aVarInfousingunflatten!!, which would leave the log probabilities and other accumulated data in an inconsistent state. I've now replaced it withInitFromVector(mld, ...), which returns an initialisation strategy that the user can pass toinit!!to get a fully consistentVarInfoby re-computing the model.Closes #1308