Skip to content
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

test: run Enzyme tests on Julia 1.11 #615

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
57 changes: 0 additions & 57 deletions .github/workflows/Documentation.yml

This file was deleted.

86 changes: 17 additions & 69 deletions .github/workflows/Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,31 @@ jobs:
- "1.10"
- "1"
group:
- Misc/Internals
- Misc/DifferentiateWith
- Misc/FromPrimitive
- Misc/SparsityDetector
- Misc/ZeroBackends
- Back/ChainRulesBackends
# - Misc/Internals
# - Misc/DifferentiateWith
# - Misc/FromPrimitive
# - Misc/SparsityDetector
# - Misc/ZeroBackends
# - Back/ChainRulesBackends
- Back/Enzyme
- Back/FiniteDiff
- Back/FiniteDifferences
- Back/ForwardDiff
- Back/Mooncake
- Back/PolyesterForwardDiff
- Back/ReverseDiff
- Back/SymbolicBackends
- Back/Tracker
- Back/Zygote
- Down/Flux
- Down/Lux
# - Back/FiniteDiff
# - Back/FiniteDifferences
# - Back/ForwardDiff
# - Back/Mooncake
# - Back/PolyesterForwardDiff
# - Back/ReverseDiff
# - Back/SymbolicBackends
# - Back/Tracker
# - Back/Zygote
# - Down/Flux
# - Down/Lux
skip_lts:
- ${{ github.event.pull_request.draft }}
exclude:
# - skip_lts: true
# version: "1.10"
- version: "1"
group: Back/ChainRulesBackends
- version: "1"
group: Back/Enzyme
env:
JULIA_DI_TEST_GROUP: ${{ matrix.group }}
steps:
Expand All @@ -83,53 +81,3 @@ jobs:
name: ${{ matrix.version }} - DI (${{ matrix.group }})
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true

test-DIT:
name: ${{ matrix.version }} - DIT (${{ matrix.group }})
runs-on: ubuntu-latest
if: ${{ !contains(github.event.pull_request.labels.*.name, 'skipci') }}
timeout-minutes: 60
permissions: # needed to allow julia-actions/cache to proactively delete old caches that it has created
actions: write
contents: read
strategy:
fail-fast: true
matrix:
version:
- "1.10"
- "1"
group:
- Formalities
- Zero
- Standard
- Weird
skip_lts:
- ${{ github.event.pull_request.draft }}
# exclude:
# - skip_lts: true
# version: "1.10"
env:
JULIA_DIT_TEST_GROUP: ${{ matrix.group }}
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
arch: x64
- uses: julia-actions/cache@v2
- name: Install dependencies & run tests
run: julia --project=./DifferentiationInterfaceTest -e '
using Pkg;
Pkg.Registry.update();
Pkg.develop(path="./DifferentiationInterface");
Pkg.test("DifferentiationInterfaceTest"; coverage=true);'
- uses: julia-actions/julia-processcoverage@v1
with:
directories: ./DifferentiationInterfaceTest/src,./DifferentiationInterfaceTest/ext,./DifferentiationInterfaceTest/test
- uses: codecov/codecov-action@v4
with:
files: lcov.info
flags: DIT
name: ${{ matrix.version }} - DIT (${{ matrix.group }})
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
40 changes: 20 additions & 20 deletions DifferentiationInterface/test/Back/Enzyme/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,14 @@ test_differentiation(
logging=LOGGING,
);

#=
# TODO: reactivate closurified tests once Enzyme#2056 is fixed

test_differentiation(
duplicated_backends,
default_scenarios(; include_normal=false, include_closurified=true);
excluded=SECOND_ORDER,
logging=LOGGING,
);
=#
if VERSION < v"1.11"
test_differentiation(
duplicated_backends,
default_scenarios(; include_normal=false, include_closurified=true);
excluded=SECOND_ORDER,
logging=LOGGING,
)
end

#=
# TODO: reactivate type stability tests
Expand Down Expand Up @@ -80,16 +78,18 @@ test_differentiation(
logging=LOGGING,
);

test_differentiation(
AutoEnzyme(; mode=Enzyme.Reverse);
excluded=vcat(FIRST_ORDER, [:second_derivative]),
logging=LOGGING,
);

test_differentiation(
SecondOrder(AutoEnzyme(; mode=Enzyme.Reverse), AutoEnzyme(; mode=Enzyme.Forward));
logging=LOGGING,
);
if VERSION <= v"1.11"
test_differentiation(
AutoEnzyme(; mode=Enzyme.Reverse);
excluded=vcat(FIRST_ORDER, [:second_derivative]),
logging=LOGGING,
)

test_differentiation(
SecondOrder(AutoEnzyme(; mode=Enzyme.Reverse), AutoEnzyme(; mode=Enzyme.Forward));
logging=LOGGING,
)
end

## Sparse

Expand Down
26 changes: 15 additions & 11 deletions DifferentiationInterfaceTest/src/scenarios/default.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,20 @@ end

## Array to number

const α = 4
const β = 6
const α = 3

arr_to_num_linalg(x::AbstractArray) = sum(vec(x .^ α) .* transpose(vec(x .^ β)))
@inline power(x) = x^α

function arr_to_num_linalg(x::AbstractArray)
a = vec(map(power, x))
return sum(a * transpose(a))
end

function arr_to_num_no_linalg(x::AbstractArray)
n = length(x)
s = zero(eltype(x))
for i in 1:n, j in 1:n
s += x[i]^α * x[j]^β
s += x[i]^α * x[j]^α
end
return s
end
Expand All @@ -188,9 +192,9 @@ function arr_to_num_gradient(x0)
g = similar(x)
for k in eachindex(g, x)
g[k] = (
α * x[k]^(α - 1) * sum(x[j]^β for j in eachindex(x) if j != k) +
β * x[k]^(β - 1) * sum(x[i]^α for i in eachindex(x) if i != k) +
(α + β) * x[k]^(α + β - 1)
α * x[k]^(α - 1) * sum(x[j]^α for j in eachindex(x) if j != k) +
α * x[k]^(α - 1) * sum(x[i]^α for i in eachindex(x) if i != k) +
* x[k]^( - 1)
)
end
return convert(typeof(x0), g)
Expand All @@ -202,12 +206,12 @@ function arr_to_num_hessian(x0)
for k in axes(H, 1), l in axes(H, 2)
if k == l
H[k, k] = (
α * (α - 1) * x[k]^(α - 2) * sum(x[j]^β for j in eachindex(x) if j != k) +
β * (β - 1) * x[k]^(β - 2) * sum(x[i]^α for i in eachindex(x) if i != k) +
(α + β) * (α + β - 1) * x[k]^(α + β - 2)
α * (α - 1) * x[k]^(α - 2) * sum(x[j]^α for j in eachindex(x) if j != k) +
α * (α - 1) * x[k]^(α - 2) * sum(x[i]^α for i in eachindex(x) if i != k) +
* (- 1) * x[k]^( - 2)
)
else
H[k, l] = α * β * (x[k]^(α - 1) * x[l]^(β - 1) + x[k]^(β - 1) * x[l]^(α - 1))
H[k, l] = α^2 * (x[k]^(α - 1) * x[l]^(α - 1) + x[k]^(α - 1) * x[l]^(α - 1))
end
end
return convert(typeof(similar(x0, length(x0), length(x0))), H)
Expand Down
Loading