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

Fix default algorithm adjoint #1031

Merged
merged 1 commit into from
Mar 11, 2024
Merged
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
1 change: 1 addition & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
- Core5
- Core6
- Core7
- DiffEq
- SDE1
- SDE2
- SDE3
Expand Down
2 changes: 1 addition & 1 deletion src/adjoint_common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function adjointdiffcache(g::G, sensealg, discrete, sol, dgdu::DG1, dgdp::DG2, f
if !needs_jac && !issemiexplicitdae && !(autojacvec isa Bool)
J = nothing
else
if SciMLBase.forwarddiffs_model_time(alg)
if alg === nothing || SciMLBase.forwarddiffs_model_time(alg)
# 1 chunk is fine because it's only t
J = dualcache(similar(u0, numindvar, numindvar),
ForwardDiff.pickchunksize(length(u0)))
Expand Down
5 changes: 5 additions & 0 deletions test/diffeq/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[deps]
DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa"

[compat]
DifferentialEquations = "7"
21 changes: 21 additions & 0 deletions test/diffeq/default_alg_diff.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using ComponentArrays, DifferentialEquations, Lux, Random, SciMLSensitivity, Zygote

function f(du, u, p, t)
du .= first(nn(u, p, st))
nothing
end

nn = Dense(8, 8, tanh)
ps, st = Lux.setup(Random.default_rng(), nn)
ps = ComponentArray(ps)

r = rand(Float32, 8, 64)

function f2(x)
prob = ODEProblem(f, r, (0.0f0, 1.0f0), x)
sol = solve(prob; sensealg = InterpolatingAdjoint(; autodiff = true, autojacvec = true))
sum(last(sol.u))
end

f2(ps)
Zygote.gradient(f2, ps)
13 changes: 13 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ function activate_gpu_env()
Pkg.instantiate()
end

function activate_diffeq_env()
Pkg.activate("diffeq")
Pkg.develop(PackageSpec(path = dirname(@__DIR__)))
Pkg.instantiate()
end

@time @testset "SciMLSensitivity" begin
if GROUP == "All" || GROUP == "Core1" || GROUP == "Downstream"
@testset "Core1" begin
Expand Down Expand Up @@ -144,6 +150,13 @@ end
end
end

if GROUP == "DiffEq"
@testset "DiffEq" begin
activate_gpu_env()
@time @safetestset "Default DiffEq Alg" include("diffeq/default_alg_diff.jl")
end
end

if GROUP == "GPU"
@testset "GPU" begin
activate_gpu_env()
Expand Down
Loading