Skip to content

Commit 0699d42

Browse files
committed
Reorganize the tests with CUDA, Enzyme and Zygote
1 parent e6eb171 commit 0699d42

File tree

6 files changed

+175
-154
lines changed

6 files changed

+175
-154
lines changed

.buildkite/pipeline.yml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,32 @@ steps:
77
queue: "juliagpu"
88
cuda: "*"
99
command: |
10-
julia --color=yes --project -e 'using Pkg; Pkg.add("CUDA"); Pkg.add("NLPModels"); Pkg.add("NLPModelsTest"); Pkg.instantiate()'
11-
julia --color=yes --project -e 'include("test/gpu.jl")'
10+
julia --color=yes --project=test -e 'using Pkg; Pkg.add("CUDA"); Pkg.instantiate()'
11+
julia --color=yes --project=test -e 'include("test/gpu.jl")'
12+
timeout_in_minutes: 30
13+
14+
- label: "CPUs -- Enzyme.jl"
15+
plugins:
16+
- JuliaCI/julia#v1:
17+
version: "1.10"
18+
agents:
19+
queue: "juliaecosystem"
20+
os: "linux"
21+
arch: "x86_64"
22+
command: |
23+
julia --color=yes --project=test -e 'using Pkg; Pkg.add("Enzyme"); Pkg.instantiate()'
24+
julia --color=yes --project=test -e 'include("test/enzyme.jl")'
25+
timeout_in_minutes: 30
26+
27+
- label: "CPUs -- Zygote.jl"
28+
plugins:
29+
- JuliaCI/julia#v1:
30+
version: "1.10"
31+
agents:
32+
queue: "juliaecosystem"
33+
os: "linux"
34+
arch: "x86_64"
35+
command: |
36+
julia --color=yes --project=test -e 'using Pkg; Pkg.add("Zygote"); Pkg.instantiate()'
37+
julia --color=yes --project=test -e 'include("test/zygote.jl")'
1238
timeout_in_minutes: 30

test/Project.toml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
[deps]
2-
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
3-
Enzyme = "7da242da-08ed-463a-9acd-ee780be4f1d9"
42
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
53
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
64
ManualNLPModels = "30dfa513-9b2f-4fb3-9796-781eabac1617"
@@ -11,16 +9,12 @@ ReverseDiff = "37e2e3b7-166d-5795-8a7a-e32c996b4267"
119
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1210
SparseMatrixColorings = "0a514795-09f3-496d-8182-132a7b665d35"
1311
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
14-
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"
1512

1613
[compat]
17-
CUDA = "4, 5"
18-
Enzyme = "0.10, 0.11, 0.12"
1914
ForwardDiff = "0.10"
2015
ManualNLPModels = "0.1"
2116
NLPModels = "0.21"
2217
NLPModelsModifiers = "0.7"
2318
NLPModelsTest = "0.10"
2419
ReverseDiff = "1"
2520
SparseMatrixColorings = "0.4.0"
26-
Zygote = "0.6"

test/enzyme.jl

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
using Enzyme
2+
3+
#=
4+
ADNLPModels.EmptyADbackend(args...; kwargs...) = ADNLPModels.EmptyADbackend()
5+
6+
names = OptimizationProblems.meta[!, :name]
7+
list_excluded_enzyme = [
8+
"brybnd",
9+
"clplatea",
10+
"clplateb",
11+
"clplatec",
12+
"curly",
13+
"curly10",
14+
"curly20",
15+
"curly30",
16+
"elec",
17+
"fminsrf2",
18+
"hs101",
19+
"hs117",
20+
"hs119",
21+
"hs86",
22+
"integreq",
23+
"ncb20",
24+
"ncb20b",
25+
"palmer1c",
26+
"palmer1d",
27+
"palmer2c",
28+
"palmer3c",
29+
"palmer4c",
30+
"palmer5c",
31+
"palmer5d",
32+
"palmer6c",
33+
"palmer7c",
34+
"palmer8c",
35+
"sbrybnd",
36+
"tetra",
37+
"tetra_duct12",
38+
"tetra_duct15",
39+
"tetra_duct20",
40+
"tetra_foam5",
41+
"tetra_gear",
42+
"tetra_hook",
43+
"threepk",
44+
"triangle",
45+
"triangle_deer",
46+
"triangle_pacman",
47+
"triangle_turtle",
48+
"watson",
49+
]
50+
for pb in names
51+
@info pb
52+
(pb in list_excluded_enzyme) && continue
53+
nlp = eval(Meta.parse(pb))(
54+
gradient_backend = ADNLPModels.EnzymeADGradient,
55+
jacobian_backend = ADNLPModels.EmptyADbackend,
56+
hessian_backend = ADNLPModels.EmptyADbackend,
57+
)
58+
grad(nlp, get_x0(nlp))
59+
end
60+
=#
61+
62+
#=
63+
ERROR: Duplicated Returns not yet handled
64+
Stacktrace:
65+
[1] autodiff
66+
@.julia\packages\Enzyme\DIkTv\src\Enzyme.jl:209 [inlined]
67+
[2] autodiff(mode::EnzymeCore.ReverseMode, f::OptimizationProblems.ADNLPProblems.var"#f#254"{OptimizationProblems.ADNLPProblems.var"#f#250#255"}, args::Duplicated{Vector{Float64}})
68+
@ Enzyme.julia\packages\Enzyme\DIkTv\src\Enzyme.jl:248
69+
[3] gradient!(#unused#::ADNLPModels.EnzymeADGradient, g::Vector{Float64}, f::Function, x::Vector{Float64})
70+
@ ADNLPModelsDocuments\cvs\ADNLPModels.jl\src\enzyme.jl:17
71+
[4] grad!(nlp::ADNLPModel{Float64, Vector{Float64}, Vector{Int64}}, x::Vector{Float64}, g::Vector{Float64})
72+
@ ADNLPModelsDocuments\cvs\ADNLPModels.jl\src\nlp.jl:542
73+
[5] grad(nlp::ADNLPModel{Float64, Vector{Float64}, Vector{Int64}}, x::Vector{Float64})
74+
@ NLPModels.julia\packages\NLPModels\XBcWL\src\nlp\api.jl:31
75+
[6] top-level scope
76+
@ .\REPL[7]:5
77+
=#

test/runtests.jl

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using CUDA, LinearAlgebra, SparseArrays, Test
1+
using LinearAlgebra, SparseArrays, Test
22
using SparseMatrixColorings
33
using ADNLPModels, ManualNLPModels, NLPModels, NLPModelsModifiers, NLPModelsTest
44
using ADNLPModels:
@@ -40,25 +40,6 @@ for problem in NLPModelsTest.nls_problems
4040
include("nls/problems/$(lowercase(problem)).jl")
4141
end
4242

43-
# Additional backends used for tests
44-
push!(
45-
ADNLPModels.predefined_backend,
46-
:zygote_backend => Dict(
47-
:gradient_backend => ADNLPModels.ZygoteADGradient,
48-
:jprod_backend => ADNLPModels.ZygoteADJprod,
49-
:jtprod_backend => ADNLPModels.ZygoteADJtprod,
50-
:hprod_backend => ADNLPModels.ForwardDiffADHvprod,
51-
:jacobian_backend => ADNLPModels.ZygoteADJacobian,
52-
:hessian_backend => ADNLPModels.ZygoteADHessian,
53-
:ghjvprod_backend => ADNLPModels.ForwardDiffADGHjvprod,
54-
:jprod_residual_backend => ADNLPModels.ZygoteADJprod,
55-
:jtprod_residual_backend => ADNLPModels.ZygoteADJtprod,
56-
:hprod_residual_backend => ADNLPModels.ForwardDiffADHvprod,
57-
:jacobian_residual_backend => ADNLPModels.ZygoteADJacobian,
58-
:hessian_residual_backend => ADNLPModels.ZygoteADHessian,
59-
),
60-
)
61-
6243
ReverseDiffAD(nvar, f) = ADNLPModels.ADModelBackend(
6344
nvar,
6445
f,
@@ -96,53 +77,6 @@ function test_getter_setter(nlp)
9677
@test typeof(get_adbackend(nlp).hessian_backend) <: ADNLPModels.ReverseDiffADHessian
9778
end
9879

99-
ZygoteAD() = ADNLPModels.ADModelBackend(
100-
ADNLPModels.ZygoteADGradient(),
101-
ADNLPModels.GenericForwardDiffADHvprod(),
102-
ADNLPModels.ZygoteADJprod(),
103-
ADNLPModels.ZygoteADJtprod(),
104-
ADNLPModels.ZygoteADJacobian(0),
105-
ADNLPModels.ZygoteADHessian(0),
106-
ADNLPModels.ForwardDiffADGHjvprod(),
107-
ADNLPModels.EmptyADbackend(),
108-
ADNLPModels.EmptyADbackend(),
109-
ADNLPModels.EmptyADbackend(),
110-
ADNLPModels.EmptyADbackend(),
111-
ADNLPModels.EmptyADbackend(),
112-
)
113-
114-
function test_autodiff_backend_error()
115-
@testset "Error without loading package - $backend" for backend in [:ZygoteAD]
116-
adbackend = eval(backend)()
117-
@test_throws ArgumentError gradient(adbackend.gradient_backend, sum, [1.0])
118-
@test_throws ArgumentError gradient!(adbackend.gradient_backend, [1.0], sum, [1.0])
119-
@test_throws ArgumentError jacobian(adbackend.jacobian_backend, identity, [1.0])
120-
@test_throws ArgumentError hessian(adbackend.hessian_backend, sum, [1.0])
121-
@test_throws ArgumentError Jprod!(
122-
adbackend.jprod_backend,
123-
[1.0],
124-
[1.0],
125-
identity,
126-
[1.0],
127-
Val(:c),
128-
)
129-
@test_throws ArgumentError Jtprod!(
130-
adbackend.jtprod_backend,
131-
[1.0],
132-
[1.0],
133-
identity,
134-
[1.0],
135-
Val(:c),
136-
)
137-
end
138-
end
139-
140-
# Test the argument error without loading the packages
141-
test_autodiff_backend_error()
142-
143-
# Automatically loads the code for Zygote with Requires
144-
import Zygote
145-
14680
include("nlp/basic.jl")
14781
include("nls/basic.jl")
14882
include("nlp/nlpmodelstest.jl")

test/script_OP.jl

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
# script that tests ADNLPModels over OptimizationProblems.jl problems
22

3-
# optional deps
4-
# using Enzyme
5-
63
# AD deps
74
using ForwardDiff, ReverseDiff
85

@@ -55,79 +52,3 @@ for pb in names
5552
continue
5653
end
5754
end
58-
59-
#=
60-
ADNLPModels.EmptyADbackend(args...; kwargs...) = ADNLPModels.EmptyADbackend()
61-
62-
names = OptimizationProblems.meta[!, :name]
63-
list_excluded_enzyme = [
64-
"brybnd",
65-
"clplatea",
66-
"clplateb",
67-
"clplatec",
68-
"curly",
69-
"curly10",
70-
"curly20",
71-
"curly30",
72-
"elec",
73-
"fminsrf2",
74-
"hs101",
75-
"hs117",
76-
"hs119",
77-
"hs86",
78-
"integreq",
79-
"ncb20",
80-
"ncb20b",
81-
"palmer1c",
82-
"palmer1d",
83-
"palmer2c",
84-
"palmer3c",
85-
"palmer4c",
86-
"palmer5c",
87-
"palmer5d",
88-
"palmer6c",
89-
"palmer7c",
90-
"palmer8c",
91-
"sbrybnd",
92-
"tetra",
93-
"tetra_duct12",
94-
"tetra_duct15",
95-
"tetra_duct20",
96-
"tetra_foam5",
97-
"tetra_gear",
98-
"tetra_hook",
99-
"threepk",
100-
"triangle",
101-
"triangle_deer",
102-
"triangle_pacman",
103-
"triangle_turtle",
104-
"watson",
105-
]
106-
for pb in names
107-
@info pb
108-
(pb in list_excluded_enzyme) && continue
109-
nlp = eval(Meta.parse(pb))(
110-
gradient_backend = ADNLPModels.EnzymeADGradient,
111-
jacobian_backend = ADNLPModels.EmptyADbackend,
112-
hessian_backend = ADNLPModels.EmptyADbackend,
113-
)
114-
grad(nlp, get_x0(nlp))
115-
end
116-
=#
117-
118-
#=
119-
ERROR: Duplicated Returns not yet handled
120-
Stacktrace:
121-
[1] autodiff
122-
@.julia\packages\Enzyme\DIkTv\src\Enzyme.jl:209 [inlined]
123-
[2] autodiff(mode::EnzymeCore.ReverseMode, f::OptimizationProblems.ADNLPProblems.var"#f#254"{OptimizationProblems.ADNLPProblems.var"#f#250#255"}, args::Duplicated{Vector{Float64}})
124-
@ Enzyme.julia\packages\Enzyme\DIkTv\src\Enzyme.jl:248
125-
[3] gradient!(#unused#::ADNLPModels.EnzymeADGradient, g::Vector{Float64}, f::Function, x::Vector{Float64})
126-
@ ADNLPModelsDocuments\cvs\ADNLPModels.jl\src\enzyme.jl:17
127-
[4] grad!(nlp::ADNLPModel{Float64, Vector{Float64}, Vector{Int64}}, x::Vector{Float64}, g::Vector{Float64})
128-
@ ADNLPModelsDocuments\cvs\ADNLPModels.jl\src\nlp.jl:542
129-
[5] grad(nlp::ADNLPModel{Float64, Vector{Float64}, Vector{Int64}}, x::Vector{Float64})
130-
@ NLPModels.julia\packages\NLPModels\XBcWL\src\nlp\api.jl:31
131-
[6] top-level scope
132-
@ .\REPL[7]:5
133-
=#

test/zygote.jl

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
ZygoteAD() = ADNLPModels.ADModelBackend(
2+
ADNLPModels.ZygoteADGradient(),
3+
ADNLPModels.GenericForwardDiffADHvprod(),
4+
ADNLPModels.ZygoteADJprod(),
5+
ADNLPModels.ZygoteADJtprod(),
6+
ADNLPModels.ZygoteADJacobian(0),
7+
ADNLPModels.ZygoteADHessian(0),
8+
ADNLPModels.ForwardDiffADGHjvprod(),
9+
ADNLPModels.EmptyADbackend(),
10+
ADNLPModels.EmptyADbackend(),
11+
ADNLPModels.EmptyADbackend(),
12+
ADNLPModels.EmptyADbackend(),
13+
ADNLPModels.EmptyADbackend(),
14+
)
15+
16+
function test_autodiff_backend_error()
17+
@testset "Error without loading package - $backend" for backend in [:ZygoteAD]
18+
adbackend = eval(backend)()
19+
@test_throws ArgumentError gradient(adbackend.gradient_backend, sum, [1.0])
20+
@test_throws ArgumentError gradient!(adbackend.gradient_backend, [1.0], sum, [1.0])
21+
@test_throws ArgumentError jacobian(adbackend.jacobian_backend, identity, [1.0])
22+
@test_throws ArgumentError hessian(adbackend.hessian_backend, sum, [1.0])
23+
@test_throws ArgumentError Jprod!(
24+
adbackend.jprod_backend,
25+
[1.0],
26+
[1.0],
27+
identity,
28+
[1.0],
29+
Val(:c),
30+
)
31+
@test_throws ArgumentError Jtprod!(
32+
adbackend.jtprod_backend,
33+
[1.0],
34+
[1.0],
35+
identity,
36+
[1.0],
37+
Val(:c),
38+
)
39+
end
40+
end
41+
42+
# Test the argument error without loading the packages
43+
test_autodiff_backend_error()
44+
45+
# Additional backends used for tests
46+
ADNLPModels.predefined_backend = Dict(
47+
:zygote_backend => Dict(
48+
:gradient_backend => ADNLPModels.ZygoteADGradient,
49+
:jprod_backend => ADNLPModels.ZygoteADJprod,
50+
:jtprod_backend => ADNLPModels.ZygoteADJtprod,
51+
:hprod_backend => ADNLPModels.ForwardDiffADHvprod,
52+
:jacobian_backend => ADNLPModels.ZygoteADJacobian,
53+
:hessian_backend => ADNLPModels.ZygoteADHessian,
54+
:ghjvprod_backend => ADNLPModels.ForwardDiffADGHjvprod,
55+
:jprod_residual_backend => ADNLPModels.ZygoteADJprod,
56+
:jtprod_residual_backend => ADNLPModels.ZygoteADJtprod,
57+
:hprod_residual_backend => ADNLPModels.ForwardDiffADHvprod,
58+
:jacobian_residual_backend => ADNLPModels.ZygoteADJacobian,
59+
:hessian_residual_backend => ADNLPModels.ZygoteADHessian,
60+
),
61+
)
62+
63+
# Automatically loads the code for Zygote with Requires
64+
import Zygote
65+
66+
include("nlp/basic.jl")
67+
include("nls/basic.jl")
68+
include("nlp/nlpmodelstest.jl")
69+
include("nls/nlpmodelstest.jl")

0 commit comments

Comments
 (0)