Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
f689bd8
Migrate from DifferentiationInterface to AbstractPPL evaluator interface
yebai Apr 24, 2026
79cc048
Bump AbstractPPL@0.15, add LDP+Hessian on prepared evaluators
yebai May 19, 2026
92124d6
Revert formatting-only changes pulled in by the migration
yebai May 19, 2026
6da3232
Move LDP+Hessian-on-Prepared work to a follow-up branch
yebai May 19, 2026
d106e7b
Restore Hessian support via AbstractPPL hg/hessian-order
yebai May 19, 2026
79db2fb
Drop _VIGradPrep; thread aux through AbstractPPL context
yebai May 19, 2026
451e7b7
Parameterise loglikeadj eltype; expand model_ref WHY comment
yebai May 20, 2026
23c610c
Merge branch 'main' into abstractppl-dynamicppl-migration
yebai May 20, 2026
5790cd4
Drop AbstractPPL and Bijectors source pins; restrict Bijectors compat
yebai May 21, 2026
cda0cfd
Merge branch 'main' into abstractppl-dynamicppl-migration
yebai May 25, 2026
6882db8
Repoint DynamicPPL source pin to main
yebai May 25, 2026
703b8c8
Run benchmarks and docs on Julia 1; add Julia 1 to Buildkite
yebai May 25, 2026
b7d820f
Skip prep cache for AutoReverseDiff(; compile=true)
yebai May 25, 2026
3fdf684
Drop Zygote from benchmarks; load DI in setup blocks
yebai May 25, 2026
a57188a
Tighten comments and prefer !== for type comparisons
yebai May 25, 2026
61cee75
Drop ReverseDiff from benchmarks
yebai May 25, 2026
4a170ea
Apply JuliaFormatter suggestion in bench/benchmarks.jl
yebai May 25, 2026
53a672f
Drop DynamicPPL main source pin
yebai May 26, 2026
7f24add
Switch docs and benchmarks to Mooncake
yebai May 26, 2026
4e9693e
Switch format workflow to TuringLang/actions/Format
yebai May 26, 2026
773460c
Drop LogDensityProblemsAD from docs tutorials
yebai May 26, 2026
9c2e44e
Move Mooncake overlay for Bijectors.Stacked into basic.md
yebai May 26, 2026
2fbbcdc
Use AutoMooncake in constrained.md's logdensity_and_gradient
yebai May 26, 2026
ccc45f4
Merge branch 'main' into abstractppl-dynamicppl-migration
yebai May 26, 2026
f7f8911
formatting
yebai May 26, 2026
b4b2b47
Address Xianda's review on DynamicPPL ext + restore ReverseDiff bench…
yebai May 28, 2026
4dab3e7
Tighten DynamicPPL ext design-rationale comments
yebai May 28, 2026
daf504e
Move basic.md footnotes to end of file
yebai May 28, 2026
1a982d3
Address remaining review feedback from sunxd3
yebai Jun 1, 2026
b911715
Revert benchmark workflow back to LTS Julia
yebai Jun 1, 2026
bd6160f
Drop unused test deps and clarify subsample docstring
yebai Jun 3, 2026
428d5c0
Address review feedback: hoist prep, drop Mooncake overlay, tighten ext
yebai Jun 3, 2026
8526f5e
Merge branch 'main' into abstractppl-dynamicppl-migration
yebai Jun 3, 2026
01c6b7d
Use eltype(loglikeadj_ref) for consistency
yebai Jun 4, 2026
ece02c1
Require Mooncake 0.5.31, drop docs [sources] pin
yebai Jun 4, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ steps:
setup:
julia:
- "1.10"
- "1"
2 changes: 1 addition & 1 deletion .github/workflows/Docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Build and deploy Documenter.jl docs
uses: TuringLang/actions/DocsDocumenter@main
with:
julia-version: 'lts'
julia-version: '1'

- name: Run doctests
shell: julia --project=docs --color=yes {0}
Expand Down
21 changes: 8 additions & 13 deletions .github/workflows/Format.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
name: Format suggestions
name: Format

on:
push:
branches:
- main
pull_request:

concurrency:
# Skip intermediate builds: always.
# Cancel intermediate builds: only if it is a pull request build.
Expand All @@ -12,15 +15,7 @@ concurrency:
jobs:
format:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: 1
- run: |
julia -e 'using Pkg; Pkg.add("JuliaFormatter")'
julia -e 'using JuliaFormatter; format("."; verbose=true)'
- uses: reviewdog/action-suggester@v1
with:
tool_name: JuliaFormatter
fail_on_error: true
- name: Format code
uses: TuringLang/actions/Format@main
10 changes: 5 additions & 5 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ version = "0.7.0"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
AbstractPPL = "7a57a42e-76ec-4ea3-a279-07e840d6d9cf"
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
DiffResults = "163ba53b-c6d8-5494-b064-1a9d43ac40c5"
DifferentiationInterface = "a0c0ee7d-e4b9-4e03-894e-1c5f64a51d63"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
Expand All @@ -29,23 +29,23 @@ DynamicPPL = "366bfd00-2699-11ea-058f-f148b4cae6d8"
AdvancedVIEnzymeExt = ["Enzyme", "ChainRulesCore"]
AdvancedVIMooncakeExt = ["Mooncake", "ChainRulesCore"]
AdvancedVIReverseDiffExt = ["ReverseDiff", "ChainRulesCore"]
AdvancedVIDynamicPPLExt = ["DynamicPPL", "Accessors", "Distributions", "DifferentiationInterface", "LogDensityProblems"]
AdvancedVIDynamicPPLExt = ["DynamicPPL", "Accessors", "Distributions", "LogDensityProblems"]

[compat]
ADTypes = "1"
AbstractPPL = "0.15"
Accessors = "0.1"
ChainRulesCore = "1"
DiffResults = "1"
DifferentiationInterface = "0.6, 0.7"
Distributions = "0.25.111"
DocStringExtensions = "0.8, 0.9"
DynamicPPL = "0.40, 0.41"
DynamicPPL = "0.42"
Enzyme = "0.13"
FillArrays = "1.3"
Functors = "0.4, 0.5"
LinearAlgebra = "1"
LogDensityProblems = "2"
Mooncake = "0.4, 0.5"
Mooncake = "0.5.31"
Optimisers = "0.2.16, 0.3, 0.4"
ProgressMeter = "1.6"
Random = "1"
Expand Down
4 changes: 2 additions & 2 deletions bench/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
AdvancedVI = "b5ca4192-6429-45e5-a2d9-87aec30a685c"
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
DifferentiationInterface = "a0c0ee7d-e4b9-4e03-894e-1c5f64a51d63"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
DistributionsAD = "ced4e74d-a319-5a8a-b0ac-84af2272839c"
Enzyme = "7da242da-08ed-463a-9acd-ee780be4f1d9"
Expand All @@ -15,12 +16,12 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
SimpleUnPack = "ce78b400-467f-4804-87d8-8f486da07d0a"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

[compat]
ADTypes = "1"
AdvancedVI = "0.7, 0.6"
BenchmarkTools = "1"
DifferentiationInterface = "0.6, 0.7"
Distributions = "0.25.111"
DistributionsAD = "0.6"
Enzyme = "0.13.7"
Expand All @@ -34,5 +35,4 @@ Random = "1"
ReverseDiff = "1"
SimpleUnPack = "1"
StableRNGs = "1"
Zygote = "0.6, 0.7"
julia = "1.10, 1.11.2"
6 changes: 3 additions & 3 deletions bench/benchmarks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ using AdvancedVI
using BenchmarkTools
using Distributions
using DistributionsAD
using Enzyme, ForwardDiff, ReverseDiff, Zygote, Mooncake
using DifferentiationInterface # provides AbstractPPL.prepare for non-Mooncake, non-ForwardDiff backends
using Enzyme, ForwardDiff, Mooncake, ReverseDiff
using FillArrays
using InteractiveUtils
using LinearAlgebra
Expand Down Expand Up @@ -68,9 +69,8 @@ begin
("RepGradELBO + STL", StickingTheLandingEntropy()),
],
(adname, adtype) in [
("Zygote", AutoZygote()),
("Mooncake", AutoMooncake()),
("ReverseDiff", AutoReverseDiff()),
("Mooncake", AutoMooncake(; config=Mooncake.Config())),
# ("Enzyme", AutoEnzyme(; mode=Enzyme.set_runtime_activity(Enzyme.Reverse), function_annotation=Enzyme.Const)),
Comment thread
yebai marked this conversation as resolved.
],
(familyname, family) in [
Expand Down
12 changes: 5 additions & 7 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,48 +1,46 @@
[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
AbstractPPL = "7a57a42e-76ec-4ea3-a279-07e840d6d9cf"
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
AdvancedVI = "b5ca4192-6429-45e5-a2d9-87aec30a685c"
Bijectors = "76274a88-744f-5084-9051-94815aaf08c4"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
DifferentiationInterface = "a0c0ee7d-e4b9-4e03-894e-1c5f64a51d63"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
Functors = "d9f16b24-f501-4c13-a1f2-28368ffc5196"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
LogDensityProblems = "6fdf6af0-433a-55f7-b3ed-c6c6e0b8df7c"
LogDensityProblemsAD = "996a588d-648d-4e1f-a8f0-a84b347e47b1"
Mooncake = "da2b9cff-9c12-43a0-ae48-6db2b0edb7d6"
NormalizingFlows = "50e4474d-9f12-44b7-af7a-91ab30ff6256"
OpenML = "8b6db2d4-7670-4922-a472-f9537c81ab66"
Optimisers = "3bd65402-5787-11e9-1adc-39752487f4e2"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
QuasiMonteCarlo = "8a4e6c94-4038-4cdc-81c3-7e6ffdb2a71b"
ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
StanLogDensityProblems = "a545de4d-8dba-46db-9d34-4e41d3f07807"
StatsFuns = "4c63d2b9-4356-54db-8cca-17b64c39e42c"

[compat]
ADTypes = "1"
AbstractPPL = "0.15"
Accessors = "0.1"
AdvancedVI = "0.7, 0.6"
Bijectors = "0.13.6, 0.14, 0.15"
Bijectors = "0.15, 0.16"
DataFrames = "1"
DifferentiationInterface = "0.7"
Distributions = "0.25"
Documenter = "1"
FillArrays = "1"
ForwardDiff = "0.10, 1"
Functors = "0.5"
JSON = "0.21, 1"
LogDensityProblems = "2.1.1"
LogDensityProblemsAD = "1"
Mooncake = "0.5.31"
NormalizingFlows = "0.2.2"
OpenML = "0.3"
Optimisers = "0.3, 0.4"
Plots = "1"
QuasiMonteCarlo = "0.3"
ReverseDiff = "1"
StanLogDensityProblems = "0.1"
StatsFuns = "1, 2"
julia = "1.10, 1.11.2"
5 changes: 5 additions & 0 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

# Force GR (Plots.jl's default backend) into its no-display workstation so
# `savefig` writes files but no interactive window is opened. Must be set
# before GR loads.
ENV["GKSwstype"] = "100"

using AdvancedVI
using Documenter

Expand Down
4 changes: 2 additions & 2 deletions docs/src/families.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ using LinearAlgebra
using LogDensityProblems
using Optimisers
using Plots
using ForwardDiff, ReverseDiff
using ForwardDiff, Mooncake

struct Target{D}
dist::D
Expand Down Expand Up @@ -184,7 +184,7 @@ D = ones(n_dims)
U = zeros(n_dims, 3)
q0_lr = LowRankGaussian(μ, D, U)

alg = KLMinRepGradDescent(AutoReverseDiff(); optimizer=Adam(0.01), operator=ClipScale())
alg = KLMinRepGradDescent(AutoMooncake(); optimizer=Adam(0.01), operator=ClipScale())

max_iter = 10^4

Expand Down
15 changes: 8 additions & 7 deletions docs/src/klminrepgraddescent.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ using Plots
using Random

using Optimisers
using ADTypes, ForwardDiff, ReverseDiff
using ADTypes, ForwardDiff, Mooncake
using AdvancedVI

struct Dist{D}
Expand Down Expand Up @@ -150,10 +150,7 @@ Recall that the original ADVI objective with a closed-form entropy (CFE) is give
n_montecarlo = 16;

cfe = KLMinRepGradDescent(
AutoReverseDiff();
entropy=ClosedFormEntropy(),
optimizer=Adam(1e-2),
operator=ClipScale(),
AutoMooncake(); entropy=ClosedFormEntropy(), optimizer=Adam(1e-2), operator=ClipScale()
)
nothing
```
Expand All @@ -162,7 +159,7 @@ The repgradelbo estimator can instead be created as follows:

```@example repgradelbo
stl = KLMinRepGradDescent(
AutoReverseDiff();
AutoMooncake();
entropy=StickingTheLandingEntropy(),
optimizer=Adam(1e-2),
operator=ClipScale(),
Expand Down Expand Up @@ -262,6 +259,10 @@ In this case, it suffices to override its `rand` specialization as follows:
using QuasiMonteCarlo
using StatsFuns

# QMC samples are inputs to AD, not parameters; declare them non-differentiable
# so Mooncake doesn't trace through Sobol/Owen bit-twiddling.
Mooncake.@zero_derivative Mooncake.DefaultCtx Tuple{typeof(QuasiMonteCarlo.sample),Vararg}

qmcrng = SobolSample(; R=OwenScramble(; base=2, pad=32))

function Distributions.rand(
Expand All @@ -281,7 +282,7 @@ nothing

```@setup repgradelbo
_, info_qmc, _ = AdvancedVI.optimize(
KLMinRepGradDescent(AutoReverseDiff(); n_samples=n_montecarlo, optimizer=Adam(1e-2), operator=ClipScale()),
KLMinRepGradDescent(AutoMooncake(); n_samples=n_montecarlo, optimizer=Adam(1e-2), operator=ClipScale()),
max_iter,
model,
q0;
Expand Down
26 changes: 9 additions & 17 deletions docs/src/tutorials/basic.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ nothing
For the VI algorithm, we will use `KLMinRepGradDescent`:

```@example basic
using ADTypes, ReverseDiff
using ADTypes, Mooncake
using AdvancedVI

alg = KLMinRepGradDescent(ADTypes.AutoReverseDiff(); operator=ClipScale());
alg = KLMinRepGradDescent(ADTypes.AutoMooncake(); operator=ClipScale());
nothing
```

Expand All @@ -159,19 +159,7 @@ Location-scale family distributions require the scale matrix to have strictly po
Here, the projection operator `ClipScale` ensures this.

`KLMinRepGradDescent`, in particular, assumes that the target `LogDensityProblem` is differentiable.
If the `LogDensityProblem` has a differentiation [capability](https://www.tamaspapp.eu/LogDensityProblems.jl/dev/#LogDensityProblems.capabilities) of at least first-order, we can take advantage of this.
For this example, we will use `LogDensityProblemsAD` to equip our problem with a first-order capability:

[^TL2014]: Titsias, M., & Lázaro-Gredilla, M. (2014, June). Doubly stochastic variational Bayes for non-conjugate inference. In *International Conference on Machine Learning*. PMLR.
[^RMW2014]: Rezende, D. J., Mohamed, S., & Wierstra, D. (2014, June). Stochastic backpropagation and approximate inference in deep generative models. In *International Conference on Machine Learning*. PMLR.
[^KW2014]: Kingma, D. P., & Welling, M. (2014). Auto-encoding variational bayes. In *International Conference on Learning Representations*.
```@example basic
using DifferentiationInterface: DifferentiationInterface
using LogDensityProblemsAD: LogDensityProblemsAD

prob_trans_ad = LogDensityProblemsAD.ADgradient(ADTypes.AutoForwardDiff(), prob_trans)
nothing
```
If the problem provides only a zeroth-order [capability](https://www.tamaspapp.eu/LogDensityProblems.jl/dev/#LogDensityProblems.capabilities), `AdvancedVI` will differentiate through `LogDensityProblems.logdensity` directly using the AD backend supplied to the algorithm.

For the variational family, we will consider a `FullRankGaussian` approximation:

Expand All @@ -190,7 +178,7 @@ We can now run VI:

```@example basic
max_iter = 10^4
q_out, info, _ = AdvancedVI.optimize(alg, max_iter, prob_trans_ad, q; show_progress=false)
q_out, info, _ = AdvancedVI.optimize(alg, max_iter, prob_trans, q; show_progress=false)
nothing
```

Expand Down Expand Up @@ -286,7 +274,7 @@ The `callback` can be supplied to `optimize`:
```@example basic
max_iter = 10^4
q_out, info, _ = AdvancedVI.optimize(
alg, max_iter, prob_trans_ad, q; show_progress=false, callback=callback
alg, max_iter, prob_trans, q; show_progress=false, callback=callback
)
nothing
```
Expand Down Expand Up @@ -331,3 +319,7 @@ nothing
![](basic_example_acc.svg)

Clearly, the accuracy is improving over time.

[^TL2014]: Titsias, M., & Lázaro-Gredilla, M. (2014, June). Doubly stochastic variational Bayes for non-conjugate inference. In *International Conference on Machine Learning*. PMLR.
[^RMW2014]: Rezende, D. J., Mohamed, S., & Wierstra, D. (2014, June). Stochastic backpropagation and approximate inference in deep generative models. In *International Conference on Machine Learning*. PMLR.
[^KW2014]: Kingma, D. P., & Welling, M. (2014). Auto-encoding variational bayes. In *International Conference on Learning Representations*.
Loading
Loading