Skip to content

Test against Enzyme #2636

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ See the [AD guide](https://turinglang.org/docs/tutorials/docs-10-using-turing-au

| Exported symbol | Documentation | Description |
|:----------------- |:------------------------------------ |:---------------------- |
| `AutoEnzyme` | [`ADTypes.AutoEnzyme`](@extref) | Enzyme.jl backend |
| `AutoForwardDiff` | [`ADTypes.AutoForwardDiff`](@extref) | ForwardDiff.jl backend |
| `AutoReverseDiff` | [`ADTypes.AutoReverseDiff`](@extref) | ReverseDiff.jl backend |
| `AutoMooncake` | [`ADTypes.AutoMooncake`](@extref) | Mooncake.jl backend |
| `AutoReverseDiff` | [`ADTypes.AutoReverseDiff`](@extref) | ReverseDiff.jl backend |

### Debugging

Expand Down
3 changes: 2 additions & 1 deletion src/Turing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ using Printf: Printf
using Random: Random
using LinearAlgebra: I

using ADTypes: ADTypes, AutoForwardDiff, AutoReverseDiff, AutoMooncake
using ADTypes: ADTypes, AutoForwardDiff, AutoReverseDiff, AutoMooncake, AutoEnzyme

const DEFAULT_ADTYPE = ADTypes.AutoForwardDiff()

Expand Down Expand Up @@ -123,6 +123,7 @@ export
AutoForwardDiff,
AutoReverseDiff,
AutoMooncake,
AutoEnzyme,
# Debugging - Turing
setprogress!,
# Distributions
Expand Down
29 changes: 28 additions & 1 deletion test/ad.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,19 @@ if INCLUDE_MOONCAKE
using Mooncake: Mooncake
end

const INCLUDE_ENZYME = !IS_PRERELEASE

if INCLUDE_ENZYME
import Pkg
Pkg.add("Enzyme")
using Enzyme: Enzyme
end

"""Element types that are always valid for a VarInfo regardless of ADType."""
const always_valid_eltypes = (AbstractFloat, AbstractIrrational, Integer, Rational)

"""A dictionary mapping ADTypes to the element types they use."""
eltypes_by_adtype = Dict(
eltypes_by_adtype = Dict{Type,Tuple}(
AutoForwardDiff => (ForwardDiff.Dual,),
AutoReverseDiff => (
ReverseDiff.TrackedArray,
Expand All @@ -39,6 +47,9 @@ eltypes_by_adtype = Dict(
if INCLUDE_MOONCAKE
eltypes_by_adtype[AutoMooncake] = (Mooncake.CoDual,)
end
if INCLUDE_ENZYME
eltypes_by_adtype[AutoEnzyme] = ()
end

"""
AbstractWrongADBackendError
Expand Down Expand Up @@ -193,6 +204,22 @@ ADTYPES = [AutoForwardDiff(), AutoReverseDiff(; compile=false)]
if INCLUDE_MOONCAKE
push!(ADTYPES, AutoMooncake(; config=nothing))
end
if INCLUDE_ENZYME
push!(
ADTYPES,
AutoEnzyme(;
mode=Enzyme.set_runtime_activity(Enzyme.Forward),
function_annotation=Enzyme.Const,
),
)
push!(
ADTYPES,
AutoEnzyme(;
mode=Enzyme.set_runtime_activity(Enzyme.Reverse),
function_annotation=Enzyme.Const,
),
)
end

# Check that ADTypeCheckContext itself works as expected.
@testset "ADTypeCheckContext" begin
Expand Down
Loading