-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backport of some features to v0.2 (#56)
* added Turing integration tests * added weakdeps * fixed Project.toml * added extensions * moved to usage of extensions + ADTypes.jl * added test toml * added Flux and Enzyme as weakdeps * added Enzyme ext * fixed accidental includes * fix requires and disa le Enzyme tests * bump patch version * fixed Requires usage * another Project.toml fix * more toml fixing * maybe now
- Loading branch information
Showing
11 changed files
with
306 additions
and
131 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
name: IntegrationTest | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
merge_group: | ||
types: [checks_requested] | ||
pull_request: | ||
branches: [v0.2-backport] | ||
|
||
jobs: | ||
test: | ||
name: ${{ matrix.package.repo }} | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
package: | ||
- {user: TuringLang, repo: Turing.jl} | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: julia-actions/setup-julia@v1 | ||
with: | ||
version: 1 | ||
arch: x64 | ||
- uses: julia-actions/julia-buildpkg@latest | ||
- name: Clone Downstream | ||
uses: actions/checkout@v2 | ||
with: | ||
repository: ${{ matrix.package.user }}/${{ matrix.package.repo }} | ||
path: downstream | ||
- name: Load this and run the downstream tests | ||
shell: julia --color=yes --project=downstream {0} | ||
run: | | ||
using Pkg | ||
try | ||
# force it to use this PR's version of the package | ||
Pkg.develop(PackageSpec(path=".")) # resolver may fail with main deps | ||
Pkg.update() | ||
Pkg.test(julia_args=["--depwarn=no"]) # resolver may fail with test time deps | ||
catch err | ||
err isa Pkg.Resolve.ResolverError || rethrow() | ||
# If we can't resolve that means this is incompatible by SemVer and this is fine | ||
# It means we marked this as a breaking change, so we don't need to worry about | ||
# Mistakenly introducing a breaking change, as we have intentionally made one | ||
@info "Not compatible with this release. No problem." exception=err | ||
exit(0) # Exit immediately, as a success | ||
end |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
module AdvancedVIEnzymeExt | ||
|
||
if isdefined(Base, :get_extension) | ||
using AdvancedVI: AdvancedVI, ADTypes, DiffResults, Distributions | ||
using Enzyme: Enzyme | ||
else | ||
using ..AdvancedVI: AdvancedVI, ADTypes, DiffResults, Distributions | ||
using ..Enzyme: Enzyme | ||
end | ||
|
||
AdvancedVI.ADBackend(::Val{:enzyme}) = ADTypes.AutoEnzyme() | ||
function AdvancedVI.setadbackend(::Val{:enzyme}) | ||
Base.depwarn("`setadbackend` is deprecated. Please pass a `ADTypes.AbstractADType` as a keyword argument to the VI algorithm.", :setadbackend) | ||
AdvancedVI.ADBACKEND[] = :enzyme | ||
end | ||
|
||
function AdvancedVI.grad!( | ||
vo, | ||
alg::AdvancedVI.VariationalInference{<:ADTypes.AutoEnzyme}, | ||
q, | ||
model, | ||
θ::AbstractVector{<:Real}, | ||
out::DiffResults.MutableDiffResult, | ||
args... | ||
) | ||
f(θ) = | ||
if (q isa Distributions.Distribution) | ||
-vo(alg, AdvancedVI.update(q, θ), model, args...) | ||
else | ||
-vo(alg, q(θ), model, args...) | ||
end | ||
# Use `Enzyme.ReverseWithPrimal` once it is released: | ||
# https://github.com/EnzymeAD/Enzyme.jl/pull/598 | ||
y = f(θ) | ||
DiffResults.value!(out, y) | ||
dy = DiffResults.gradient(out) | ||
fill!(dy, 0) | ||
Enzyme.autodiff(Enzyme.ReverseWithPrimal, f, Enzyme.Active, Enzyme.Duplicated(θ, dy)) | ||
return out | ||
end | ||
|
||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module AdvancedVIFluxExt | ||
|
||
if isdefined(Base, :get_extension) | ||
using AdvancedVI: AdvancedVI | ||
using Flux: Flux | ||
else | ||
using ..AdvancedVI: AdvancedVI | ||
using ..Flux: Flux | ||
end | ||
|
||
AdvancedVI.apply!(o::Flux.Optimise.AbstractOptimiser, x, Δ) = Flux.Optimise.apply!(o, x, Δ) | ||
|
||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module AdvancedVIReverseDiffExt | ||
|
||
if isdefined(Base, :get_extension) | ||
using AdvancedVI: AdvancedVI, ADTypes, DiffResults, Distributions | ||
using ReverseDiff: ReverseDiff | ||
else | ||
using ..AdvancedVI: AdvancedVI, ADTypes, DiffResults, Distributions | ||
using ..ReverseDiff: ReverseDiff | ||
end | ||
|
||
AdvancedVI.ADBackend(::Val{:reversediff}) = ADTypes.AutoReverseDiff() | ||
|
||
function AdvancedVI.setadbackend(::Val{:reversediff}) | ||
Base.depwarn("`setadbackend` is deprecated. Please pass a `ADTypes.AbstractADType` as a keyword argument to the VI algorithm.", :setadbackend) | ||
AdvancedVI.ADBACKEND[] = :reversediff | ||
end | ||
|
||
tape(f, x) = ReverseDiff.GradientTape(f, x) | ||
|
||
function AdvancedVI.grad!( | ||
vo, | ||
alg::AdvancedVI.VariationalInference{<:ADTypes.AutoReverseDiff}, | ||
q, | ||
model, | ||
θ::AbstractVector{<:Real}, | ||
out::DiffResults.MutableDiffResult, | ||
args... | ||
) | ||
f(θ) = | ||
if (q isa Distributions.Distribution) | ||
-vo(alg, AdvancedVI.update(q, θ), model, args...) | ||
else | ||
-vo(alg, q(θ), model, args...) | ||
end | ||
tp = tape(f, θ) | ||
ReverseDiff.gradient!(out, tp, θ) | ||
return out | ||
end | ||
|
||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module AdvancedVIZygoteExt | ||
|
||
if isdefined(Base, :get_extension) | ||
using AdvancedVI: AdvancedVI, ADTypes, DiffResults, Distributions | ||
using Zygote: Zygote | ||
else | ||
using ..AdvancedVI: AdvancedVI, ADTypes, DiffResults, Distributions | ||
using ..Zygote: Zygote | ||
end | ||
|
||
AdvancedVI.ADBackend(::Val{:zygote}) = ADTypes.AutoZygote() | ||
function AdvancedVI.setadbackend(::Val{:zygote}) | ||
Base.depwarn("`setadbackend` is deprecated. Please pass a `ADTypes.AbstractADType` as a keyword argument to the VI algorithm.", :setadbackend) | ||
AdvancedVI.ADBACKEND[] = :zygote | ||
end | ||
|
||
function AdvancedVI.grad!( | ||
vo, | ||
alg::AdvancedVI.VariationalInference{<:ADTypes.AutoZygote}, | ||
q, | ||
model, | ||
θ::AbstractVector{<:Real}, | ||
out::DiffResults.MutableDiffResult, | ||
args... | ||
) | ||
f(θ) = | ||
if (q isa Distributions.Distribution) | ||
-vo(alg, AdvancedVI.update(q, θ), model, args...) | ||
else | ||
-vo(alg, q(θ), model, args...) | ||
end | ||
y, back = Zygote.pullback(f, θ) | ||
dy = first(back(1.0)) | ||
DiffResults.value!(out, y) | ||
DiffResults.gradient!(out, dy) | ||
return out | ||
end | ||
|
||
end |
Oops, something went wrong.
150a35a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
150a35a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Registration pull request created: JuliaRegistries/General/105634
Tip: Release Notes
Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.
To add them here just re-invoke and the PR will be updated.
Tagging
After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.
This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via: