-
Notifications
You must be signed in to change notification settings - Fork 35
[WIP] InitContext
#967
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
Draft
penelopeysm
wants to merge
9
commits into
breaking
Choose a base branch
from
py/initcontext
base: breaking
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
[WIP] InitContext
#967
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41f6975
to
20d0909
Compare
38652f7
to
bc16e09
Compare
Benchmark Report for Commit 97df07fComputer Information
Benchmark Results
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## breaking #967 +/- ##
============================================
- Coverage 82.77% 4.29% -78.48%
============================================
Files 38 39 +1
Lines 4011 3909 -102
============================================
- Hits 3320 168 -3152
- Misses 691 3741 +3050 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR largely follows through on the proposal in #955. I have tried to keep the changes to as minimal a set as possible, but there is a lot of entwined code, sorry.
Removes
SamplingContext
,SampleFromPrior
, andSampleFromUniform
Creates a new leaf context,
InitContext
. Its behaviour is to create new values, or overwrite existing variables in a VarInfo if they exist.Introduces initialisation strategies,
PriorInit
,UniformInit
, andParamsInit
. See docstrings for more info.Changes
evaluate_and_sample!!
(introduced in Removecontext
from model evaluation (usemodel.context
instead) #952) toinit!!
Moves all the VarInfo-initialisation code (used to be in
sampler.jl
) toParamsInit
.Auxiliary changes that follow from the above:
The function
initialsampler
, which was used to specify how initial values were generated for a given sampler, has been removed. The correct replacement isinit_strategy(::AbstractSampler)
; however, that should be in Turing not DynamicPPL.Note that, after deleting the infamous
assume
method forSampleFromPrior
, there is no longer any code that actually reads thedel
flag on VarInfo. There is a fair amount of code that writes to thedel
flag which has to be updated.setval_and_resample!
followed by model evaluation is replaced withParamsInit
with an incomplete set of parameters.setval_and_resample!
used to usenested_setindex_maybe
. The role of this function was to handle cases where the VarName of interest wasx
, but instead of supplyingx
, the user supplied (say)x[1]
andx[2]
. This has now been replaced withhasvalue(dict, vn, dist)
which usesdist
to determine whether the sub-variablesx[1]
andx[2]
provide enough information to reconstruct the full variablex
. For example, this would return true ifdist
isMvNormal(zeros(2), I)
.A long-held goal of mine is to split up
contexts.jl
andcontext_implementations.jl
such that each context is in its own file. To help get us to this stage, I've put all theInitContext
-related code insidesrc/contexts/init.jl
. This should, hopefully, also make reviewing easier.TODO for this PR
ParamsInit
: currently, initialising viaNamedTuple
orDict
is OK, butVector
will fail.truncated
Turing.jl#2476)TODO for future PRs
Look at this!:
Closes #859
Closes #955
Closes #797 (indirectly, since
initialize_parameters
is nowinit!!(..., ::ParamsInit)
)Closes #774
Closes #375
Furthermore, once an upstream interface to InitContext is put into Turing, this will also solve:
TuringLang/Turing.jl#2476