-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate to DifferentiationInterface (#98)
* migrate to DifferentiationInterface * run formatter * tighten compat bound for ADTypes * fix compat bound for docs
- Loading branch information
1 parent
4eab1ac
commit d0efe02
Showing
22 changed files
with
97 additions
and
263 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,18 @@ | ||
steps: | ||
- label: "CUDA with julia {{matrix.julia}}" | ||
plugins: | ||
- JuliaCI/julia#v1: | ||
version: "{{matrix.julia}}" | ||
- JuliaCI/julia-test#v1: | ||
test_args: "--quickfail" | ||
agents: | ||
queue: "juliagpu" | ||
cuda: "*" | ||
timeout_in_minutes: 60 | ||
env: | ||
GROUP: "GPU" | ||
ADVANCEDVI_TEST_CUDA: "true" | ||
matrix: | ||
setup: | ||
julia: | ||
- "1.10" |
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
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 |
---|---|---|
@@ -1,42 +0,0 @@ | ||
|
||
module AdvancedVIForwardDiffExt | ||
|
||
if isdefined(Base, :get_extension) | ||
using ForwardDiff | ||
using AdvancedVI | ||
using AdvancedVI: ADTypes, DiffResults | ||
else | ||
using ..ForwardDiff | ||
using ..AdvancedVI | ||
using ..AdvancedVI: ADTypes, DiffResults | ||
end | ||
|
||
getchunksize(::ADTypes.AutoForwardDiff{chunksize}) where {chunksize} = chunksize | ||
|
||
function AdvancedVI.value_and_gradient!( | ||
ad::ADTypes.AutoForwardDiff, | ||
f, | ||
x::AbstractVector{<:Real}, | ||
out::DiffResults.MutableDiffResult, | ||
) | ||
chunk_size = getchunksize(ad) | ||
config = if isnothing(chunk_size) | ||
ForwardDiff.GradientConfig(f, x) | ||
else | ||
ForwardDiff.GradientConfig(f, x, ForwardDiff.Chunk(length(x), chunk_size)) | ||
end | ||
ForwardDiff.gradient!(out, f, x, config) | ||
return out | ||
end | ||
|
||
function AdvancedVI.value_and_gradient!( | ||
ad::ADTypes.AutoForwardDiff, | ||
f, | ||
x::AbstractVector, | ||
aux, | ||
out::DiffResults.MutableDiffResult, | ||
) | ||
return AdvancedVI.value_and_gradient!(ad, x′ -> f(x′, aux), x, out) | ||
end | ||
|
||
end | ||
Empty file.
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 |
---|---|---|
@@ -1,36 +0,0 @@ | ||
|
||
module AdvancedVIReverseDiffExt | ||
|
||
if isdefined(Base, :get_extension) | ||
using AdvancedVI | ||
using AdvancedVI: ADTypes, DiffResults | ||
using ReverseDiff | ||
else | ||
using ..AdvancedVI | ||
using ..AdvancedVI: ADTypes, DiffResults | ||
using ..ReverseDiff | ||
end | ||
|
||
# ReverseDiff without compiled tape | ||
function AdvancedVI.value_and_gradient!( | ||
ad::ADTypes.AutoReverseDiff, | ||
f, | ||
x::AbstractVector{<:Real}, | ||
out::DiffResults.MutableDiffResult, | ||
) | ||
tp = ReverseDiff.GradientTape(f, x) | ||
ReverseDiff.gradient!(out, tp, x) | ||
return out | ||
end | ||
|
||
function AdvancedVI.value_and_gradient!( | ||
ad::ADTypes.AutoReverseDiff, | ||
f, | ||
x::AbstractVector{<:Real}, | ||
aux, | ||
out::DiffResults.MutableDiffResult, | ||
) | ||
return AdvancedVI.value_and_gradient!(ad, x′ -> f(x′, aux), x, out) | ||
end | ||
|
||
end | ||
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,36 +0,0 @@ | ||
|
||
module AdvancedVIZygoteExt | ||
|
||
if isdefined(Base, :get_extension) | ||
using AdvancedVI | ||
using AdvancedVI: ADTypes, DiffResults | ||
using ChainRulesCore | ||
using Zygote | ||
else | ||
using ..AdvancedVI | ||
using ..AdvancedVI: ADTypes, DiffResults | ||
using ..ChainRulesCore | ||
using ..Zygote | ||
end | ||
|
||
function AdvancedVI.value_and_gradient!( | ||
::ADTypes.AutoZygote, f, x::AbstractVector{<:Real}, out::DiffResults.MutableDiffResult | ||
) | ||
y, back = Zygote.pullback(f, x) | ||
∇x = back(one(y)) | ||
DiffResults.value!(out, y) | ||
DiffResults.gradient!(out, only(∇x)) | ||
return out | ||
end | ||
|
||
function AdvancedVI.value_and_gradient!( | ||
ad::ADTypes.AutoZygote, | ||
f, | ||
x::AbstractVector{<:Real}, | ||
aux, | ||
out::DiffResults.MutableDiffResult, | ||
) | ||
return AdvancedVI.value_and_gradient!(ad, x′ -> f(x′, aux), x, 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
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
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
Oops, something went wrong.