DynamicPPL.jl
DynamicPPL.jl copied to clipboard
Linearization/flattening of SimpleVarInfo
This PR introduces a couple of things, though these are related:
unflatten(original[, spl], x): converts from a certain inputx, usually aVector, into an instance similar tooriginal.- Effectively the same as the current constructor
VarInfo(varinfo_old, spl, x). - I looked into using ParameterHandling.jl for this but decided against it for a couple of reasons:
- Seems overkill.
unflatten-equivalent is constructed as a closure, which means that we need to keep track of this returned method rather than just using a "template"AbstractVarInfo+ construction of unflattening requires construction of the flatten representation + the way one specifies the types is a bit too opinionated (which causes some issues with certain AD-frameworks) + closures can have less desirable performance characteristics.- The current Turing.jl-codebase is easily adapted to this
unflattensince it's really just a matter of replacing callsVarInfo(varinfo_old, spl, x)withunflatten(varinfo_old, spl, x). A ParameterHandling.jl approach will require more work.
- Effectively the same as the current constructor
link!!andinvlink!!, BangBang-versions oflink!andinvlink!, respectively, with some differences:- These take additional arguments which should always be sufficient to determine the transformation. These are:
modelsamplert::AbstractTransformation. This sets us up for allowing alternative transformations to be used. As of right now, this only has an affect when callinglink!!andinvlink!!, not when used inside of the tilde-pipeline.
- Also adds the logabsdet-jacobian term to the
logp, so thatgetlogp(vi) ≠ getlogp(link!!(vi))holds. This allows us to compute, say,logjointby first linkingviin a single pass, and then computelogjoint(settrans!(vi, NoTransformation()), θ_constrained). Such a pattern, in particular if the transformation has been specified by the user themselves, will usually have much better performance than thelogpdf_with_trans(..., true)within the tilde-callstack.
- These take additional arguments which should always be sufficient to determine the transformation. These are:
make_default_varinfo(rng, model, sampler)which allows one to overload on a, say, per-model or model-sampler-combination basis to specify which implementation ofAbstractVarInfoto use.- Not entirely happy with this approach :confused:
EDIT: This should be merged after #420
This should be ready for a review @devmotion @yebai
bors try
bors try
try
Already running a review
bors try
So the tests are breaking because the Emcee sampler in Turing is explictily calling initialize_parameters!!. It's not a function we're exporting to technically this shouldn't be a breaking chance, but given that it is indeed breaking downstream packages, should I make this a breaking release?
Yes, happy to make this a breaking PR to avoid surprises. This PR contains significant new code/features anyway.
Done. But as I said, everything passes except this one thing, so updating Turing is trivial.
bors try
bors try
bors try
bors cancel
It seems bors is on strike again. Let me know when this is ready for another look; I'll review and merge it manually.
bors try
try
Already running a review
bors cancel
@torfjelde Did you run the tests locally?
They succeeded before I did the refactoring, so let me give it a go once more first.
bors try
try
Already running a review
This is now passing with and without threads locally on Julia 1.8. Do we know what's wrong with bors?
I'll take a careful look later today and try to merge it manually.
Re bors, there seems to be a pattern that bors will strike if we feed it too many changes in one PR.
Cool!
Re
bors, there seems to be a pattern thatborswill strike if we feed it too many changes in one PR.
Regarding bors: but is there a way to reset it?
Re
bors, there seems to be a pattern thatborswill strike if we feed it too many changes in one PR. Regarding bors: but is there a way to reset it?
I didn't find one, but I didn't try very hard either.
Aight!
Btw, let me click the "Merge" button. You just let me know when you've reviewed and you're happy. This is just in case I discover something in the mean time.
Regarding bors: but is there a way to reset it?
A bit late, but one can check the dashboard here if it is unclear if/what the problem is: https://app.bors.tech/repositories/24589 (one can navigate to it from the bors website or, IIRC, from the bors checks on Github)
One can cancel borg with bors r- or bors try- (depending on whether it was triggered with bors r+ or bors try). One can also run bors retry (and other things: https://bors.tech/documentation/). It seems the error message shows up if one runs bors try but there is already a bors try command running.