Skip to content

Commit fb669a1

Browse files
authored
Merge branch 'breaking' into py/turing-fixes
2 parents 6e67ce7 + 11d0b69 commit fb669a1

17 files changed

+391
-14
lines changed

.github/workflows/CI.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,3 @@ jobs:
8080
files: lcov.info
8181
token: ${{ secrets.CODECOV_TOKEN }}
8282
fail_ci_if_error: true
83-
84-
- uses: coverallsapp/github-action@v2
85-
with:
86-
github-token: ${{ secrets.GITHUB_TOKEN }}
87-
path-to-lcov: lcov.info

HISTORY.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,22 @@ Their APIs are the same.
7171
The implementation of the `varname_leaves` and `varname_and_value_leaves` functions have been moved to AbstractPPL.jl.
7272
Their behaviour is otherwise identical, and they are still accessible from the DynamicPPL module (though still not exported).
7373

74+
## 0.37.5
75+
76+
A minor optimisation for Enzyme AD on DynamicPPL models.
77+
78+
## 0.37.4
79+
80+
An extension for MarginalLogDensities.jl has been added.
81+
82+
Loading DynamicPPL and MarginalLogDensities now provides the `DynamicPPL.marginalize` function to marginalise out variables from a model.
83+
This is useful for averaging out random effects or nuisance parameters while improving inference on fixed effects/parameters of interest.
84+
The `marginalize` function returns a `MarginalLogDensities.MarginalLogDensity`, a function-like callable struct that returns the approximate log-density of a subset of the parameters after integrating out the rest of them.
85+
By default, this uses the Laplace approximation and sparse AD, making the marginalisation computationally very efficient.
86+
Note that the Laplace approximation relies on the model being differentiable with respect to the marginalised variables, and that their posteriors are unimodal and approximately Gaussian.
87+
88+
Please see [the MarginalLogDensities documentation](https://eloceanografo.github.io/MarginalLogDensities.jl/stable) and the [new Marginalisation section of the DynamicPPL documentation](https://turinglang.org/DynamicPPL.jl/v0.37/api/#Marginalisation) for further information.
89+
7490
## 0.37.3
7591

7692
Prevents inlining of `DynamicPPL.istrans` with Enzyme, which allows Enzyme to differentiate models where `VarName`s have the same symbol but different types.

Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
3333
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
3434
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
3535
MCMCChains = "c7f686f2-ff18-58e9-bc7b-31028e88f75d"
36+
MarginalLogDensities = "f0c3360a-fb8d-11e9-1194-5521fd7ee392"
3637
Mooncake = "da2b9cff-9c12-43a0-ae48-6db2b0edb7d6"
3738

3839
[extensions]
@@ -41,6 +42,7 @@ DynamicPPLEnzymeCoreExt = ["EnzymeCore"]
4142
DynamicPPLForwardDiffExt = ["ForwardDiff"]
4243
DynamicPPLJETExt = ["JET"]
4344
DynamicPPLMCMCChainsExt = ["MCMCChains"]
45+
DynamicPPLMarginalLogDensitiesExt = ["MarginalLogDensities"]
4446
DynamicPPLMooncakeExt = ["Mooncake"]
4547

4648
[compat]
@@ -66,6 +68,7 @@ LinearAlgebra = "1.6"
6668
LogDensityProblems = "2"
6769
MCMCChains = "6, 7"
6870
MacroTools = "0.5.6"
71+
MarginalLogDensities = "0.4.3"
6972
Mooncake = "0.4.147"
7073
OrderedCollections = "1"
7174
Printf = "1.10"

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
[![CI](https://github.com/TuringLang/DynamicPPL.jl/workflows/CI/badge.svg?branch=main)](https://github.com/TuringLang/DynamicPPL.jl/actions?query=workflow%3ACI+branch%3Amain)
66
[![JuliaPre](https://github.com/TuringLang/DynamicPPL.jl/workflows/JuliaPre/badge.svg?branch=main)](https://github.com/TuringLang/DynamicPPL.jl/actions?query=workflow%3AJuliaPre+branch%3Amain)
77
[![IntegrationTest](https://github.com/TuringLang/DynamicPPL.jl/workflows/IntegrationTest/badge.svg?branch=main)](https://github.com/TuringLang/DynamicPPL.jl/actions?query=workflow%3AIntegrationTest+branch%3Amain)
8-
[![Coverage Status](https://coveralls.io/repos/github/TuringLang/DynamicPPL.jl/badge.svg?branch=main)](https://coveralls.io/github/TuringLang/DynamicPPL.jl?branch=main)
98
[![Codecov](https://codecov.io/gh/TuringLang/DynamicPPL.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/TuringLang/DynamicPPL.jl)
109
[![Code Style: Blue](https://img.shields.io/badge/code%20style-blue-4495d1.svg)](https://github.com/invenia/BlueStyle)
1110
[![ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://img.shields.io/badge/ColPrac-Contributor%27s%20Guide-blueviolet)](https://docs.sciml.ai/ColPrac/stable/)

benchmarks/Project.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
77
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
88
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
99
DynamicPPL = "366bfd00-2699-11ea-058f-f148b4cae6d8"
10+
Enzyme = "7da242da-08ed-463a-9acd-ee780be4f1d9"
1011
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
1112
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1213
LogDensityProblems = "6fdf6af0-433a-55f7-b3ed-c6c6e0b8df7c"
@@ -23,9 +24,10 @@ ADTypes = "1.14.0"
2324
BenchmarkTools = "1.6.0"
2425
Distributions = "0.25.117"
2526
DynamicPPL = "0.38"
27+
Enzyme = "0.13"
2628
ForwardDiff = "0.10.38, 1"
2729
LogDensityProblems = "2.1.2"
2830
Mooncake = "0.4"
2931
PrettyTables = "3"
3032
ReverseDiff = "1.15.3"
31-
StableRNGs = "1"
33+
StableRNGs = "1"

benchmarks/benchmarks.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ chosen_combinations = [
4343
("Smorgasbord", smorgasbord_instance, :simple_dict, :forwarddiff, true),
4444
("Smorgasbord", smorgasbord_instance, :typed, :reversediff, true),
4545
("Smorgasbord", smorgasbord_instance, :typed, :mooncake, true),
46+
("Smorgasbord", smorgasbord_instance, :typed, :enzyme, true),
4647
("Loop univariate 1k", loop_univariate1k, :typed, :mooncake, true),
4748
("Multivariate 1k", multivariate1k, :typed, :mooncake, true),
4849
("Loop univariate 10k", loop_univariate10k, :typed, :mooncake, true),

benchmarks/src/DynamicPPLBenchmarks.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ using StableRNGs: StableRNG
1313

1414
include("./Models.jl")
1515
using .Models: Models
16-
16+
using Enzyme: Enzyme
1717
export Models, make_suite, model_dimension
1818

1919
"""
@@ -37,6 +37,10 @@ const SYMBOL_TO_BACKEND = Dict(
3737
:reversediff => ADTypes.AutoReverseDiff(; compile=false),
3838
:reversediff_compiled => ADTypes.AutoReverseDiff(; compile=true),
3939
:mooncake => ADTypes.AutoMooncake(; config=nothing),
40+
:enzyme => ADTypes.AutoEnzyme(;
41+
mode=Enzyme.set_runtime_activity(Enzyme.Reverse),
42+
function_annotation=Enzyme.Const,
43+
),
4044
)
4145

4246
to_backend(x) = error("Unknown backend: $x")

docs/Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
1010
JET = "c3a54625-cd67-489e-a8e7-0a5a0ff4e31b"
1111
LogDensityProblems = "6fdf6af0-433a-55f7-b3ed-c6c6e0b8df7c"
1212
MCMCChains = "c7f686f2-ff18-58e9-bc7b-31028e88f75d"
13+
MarginalLogDensities = "f0c3360a-fb8d-11e9-1194-5521fd7ee392"
1314
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
1415

1516
[compat]
@@ -23,5 +24,6 @@ FillArrays = "0.13, 1"
2324
ForwardDiff = "0.10, 1"
2425
JET = "0.9, 0.10"
2526
LogDensityProblems = "2"
27+
MarginalLogDensities = "0.4"
2628
MCMCChains = "5, 6, 7"
2729
StableRNGs = "1"

docs/make.jl

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ using Distributions
1111
using DocumenterMermaid
1212
# load MCMCChains package extension to make `predict` available
1313
using MCMCChains
14+
using MarginalLogDensities: MarginalLogDensities
15+
16+
# Need this to document a method which uses a type inside the extension...
17+
DPPLMLDExt = Base.get_extension(DynamicPPL, :DynamicPPLMarginalLogDensitiesExt)
1418

1519
# Doctest setup
1620
DocMeta.setdocmeta!(
@@ -24,7 +28,11 @@ makedocs(;
2428
format=Documenter.HTML(;
2529
size_threshold=2^10 * 400, mathengine=Documenter.HTMLWriter.MathJax3()
2630
),
27-
modules=[DynamicPPL, Base.get_extension(DynamicPPL, :DynamicPPLMCMCChainsExt)],
31+
modules=[
32+
DynamicPPL,
33+
Base.get_extension(DynamicPPL, :DynamicPPLMCMCChainsExt),
34+
Base.get_extension(DynamicPPL, :DynamicPPLMarginalLogDensitiesExt),
35+
],
2836
pages=[
2937
"Home" => "index.md", "API" => "api.md", "Internals" => ["internals/varinfo.md"]
3038
],

docs/src/api.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,22 @@ When using `predict` with `MCMCChains.Chains`, you can control which variables a
136136
- `include_all=false` (default): Include only newly predicted variables
137137
- `include_all=true`: Include both parameters from the original chain and predicted variables
138138

139+
## Marginalisation
140+
141+
DynamicPPL provides the `marginalize` function to marginalise out variables from a model.
142+
This requires `MarginalLogDensities.jl` to be loaded in your environment.
143+
144+
```@docs
145+
marginalize
146+
```
147+
148+
A `MarginalLogDensity` object acts as a function which maps non-marginalised parameter values to a marginal log-probability.
149+
To retrieve a VarInfo object from it, you can use:
150+
151+
```@docs
152+
VarInfo(::MarginalLogDensities.MarginalLogDensity{<:DPPLMLDExt.LogDensityFunctionWrapper}, ::Union{AbstractVector,Nothing})
153+
```
154+
139155
## Models within models
140156

141157
One can include models and call another model inside the model function with `left ~ to_submodel(model)`.

0 commit comments

Comments
 (0)