-
Notifications
You must be signed in to change notification settings - Fork 63
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
Inactive declaration ignored #2016
Comments
Note that this should be the final stage of SciML/OrdinaryDiffEq.jl#2282 |
Are you able to reduce this to a MWE without the sciml stack as dependencies? The fact that the type isn't deduced is odd and we should be able to fix it where the inactive isn't needed at all (but requires debugging on a simpler example) |
I don't know how to reduce this. It's the same thing as what was originally #1636 . In Enzyme v0.12 I just worked around it by moving the pieces that were weird out to a function an inactiviting them, though I could never isolate why it acted so weird there. |
I mean worst case you can splat in the defn's of all functions/structs in the imported packages used in the above and try to delete some of the struct elements |
I now get a segfault on main: julia> Enzyme.autodiff(Reverse, f, Duplicated(y, dy), Duplicated(u0, d_u0));
{[0]:Pointer, [0,-1]:Float@double, [8]:Integer, [9]:Integer, [10]:Integer, [11]:Integer, [12]:Integer, [13]:Integer, [14]:Integer, [15]:Integer, [16]:Integer, [17]:Integer, [18]:Integer, [19]:Integer, [20]:Integer, [21]:Integer, [22]:Integer, [23]:Integer, [24]:Integer, [25]:Integer, [26]:Integer, [27]:Integer, [28]:Integer, [29]:Integer, [30]:Integer, [31]:Integer, [32]:Integer, [33]:Integer, [34]:Integer, [35]:Integer, [36]:Integer, [37]:Integer, [38]:Integer, [39]:Integer}
canonicalizing 8
Assertion failed: ((size_t)pair.first[0] < len), function CanonicalizeInPlace, file /workspace/srcdir/Enzyme/enzyme/Enzyme/TypeAnalysis/TypeTree.h, line 700.
[6731] signal (6): Abort trap: 6
in expression starting at REPL[9]:1
__pthread_kill at /usr/lib/system/libsystem_kernel.dylib (unknown line)
Allocations: 81945743 (Pool: 81832412; Big: 113331); GC: 78 |
**** assertion error In any case can you minimize and post the whole error log? |
That is the whole error log:
|
Note this is as minimal as I've been able to get it. Removing the big OrdinaryDiffEq type and using SimpleDiffEq makes it go away: using SimpleDiffEq, Enzyme, StaticArrays
function lorenz!(du, u, p, t)
du[1] = 10.0(u[2] - u[1])
du[2] = u[1] * (28.0 - u[3]) - u[2]
du[3] = u[1] * u[2] - (8 / 3) * u[3]
end
const _saveat = SA[0.0,0.25,0.5,0.75,1.0,1.25,1.5,1.75,2.0,2.25,2.5,2.75,3.0]
function f(y::Array{Float64}, u0::Array{Float64})
tspan = (0.0, 3.0)
prob = ODEProblem{true, SciMLBase.FullSpecialize}(lorenz!, u0, tspan)
sol = DiffEqBase.solve(prob, SimpleATsit5())
y .= sol[1,1:13]
return nothing
end;
u0 = [1.0; 0.0; 0.0]
d_u0 = zeros(3)
y = zeros(13)
dy = zeros(13)
Enzyme.autodiff(Reverse, f, Duplicated(y, dy), Duplicated(u0, d_u0)); #works fine |
There is one small minimization here, which is that I can trigger the segfault by just building the integrator: using OrdinaryDiffEq, Enzyme, StaticArrays
function lorenz!(du, u, p, t)
du[1] = 10.0(u[2] - u[1])
du[2] = u[1] * (28.0 - u[3]) - u[2]
du[3] = u[1] * u[2] - (8 / 3) * u[3]
end
const _saveat = SA[0.0,0.25,0.5,0.75,1.0,1.25,1.5,1.75,2.0,2.25,2.5,2.75,3.0]
function f(y::Array{Float64}, u0::Array{Float64})
tspan = (0.0, 3.0)
prob = ODEProblem{true, SciMLBase.FullSpecialize}(lorenz!, u0, tspan)
integ = DiffEqBase.__init(prob, Tsit5(), saveat = _saveat, sensealg = DiffEqBase.SensitivityADPassThrough())
y[1:3] .= integ.u
return nothing
end;
u0 = [1.0; 0.0; 0.0]
d_u0 = zeros(3)
y = zeros(13)
dy = zeros(13)
Enzyme.autodiff(Reverse, f, Duplicated(y, dy), Duplicated(u0, d_u0)); Which means I don't need to run the stepping to trigger it. |
Note I just saw this same segfault mysteriously show up in a completely unrelated test failure. This issue is all about direct differentiation, but it looks like this adjoint rule is seeing something similar after the last patch: |
|
Note I can confirm that the comment element of the prob construction is fine though: using OrdinaryDiffEq, Enzyme, StaticArrays
function lorenz!(du, u, p, t)
du[1] = 10.0(u[2] - u[1])
du[2] = u[1] * (28.0 - u[3]) - u[2]
du[3] = u[1] * u[2] - (8 / 3) * u[3]
end
const _saveat = SA[0.0,0.25,0.5,0.75,1.0,1.25,1.5,1.75,2.0,2.25,2.5,2.75,3.0]
function f(y::Array{Float64}, u0::Array{Float64})
tspan = (0.0, 3.0)
prob = ODEProblem{true, SciMLBase.FullSpecialize}(lorenz!, u0, tspan)
y[1:3] .= prob.u0
return nothing
end;
u0 = [1.0; 0.0; 0.0]
d_u0 = zeros(3)
y = zeros(13)
dy = zeros(13)
Enzyme.autodiff(Reverse, f, Duplicated(y, dy), Duplicated(u0, d_u0)); # is successful which means that Enzyme is only having difficulty when it's hitting the OrdinaryDiffEq integrator type. |
should be fixed on main |
On main I get a new error: julia> Enzyme.autodiff(Reverse, f, Duplicated(y, dy), Duplicated(u0, d_u0));
ERROR:
No augmented forward pass found for jl_genericmemory_copyto
at context: call void @jl_genericmemory_copyto({} addrspace(10)* nonnull %26, i64 %39, {} addrspace(10)* %283, i64 %292, i64 %23) #308, !dbg !586
Stacktrace:
[1] unsafe_copyto!
@ ./genericmemory.jl:117
[2] unsafe_copyto!
@ ./array.jl:284
[3] getindex
@ ./array.jl:941
[4] _getindex
@ ~/.julia/packages/RecursiveArrayTools/4pI6w/src/vector_of_array.jl:335
[5] getindex
@ ~/.julia/packages/RecursiveArrayTools/4pI6w/src/vector_of_array.jl:404
[6] f
@ ./REPL[4]:5
Stacktrace:
[1] unsafe_copyto!
@ ./genericmemory.jl:117 [inlined]
[2] unsafe_copyto!
@ ./array.jl:284 [inlined]
[3] getindex
@ ./array.jl:941 [inlined]
[4] _getindex
@ ~/.julia/packages/RecursiveArrayTools/4pI6w/src/vector_of_array.jl:335 [inlined]
[5] getindex
@ ~/.julia/packages/RecursiveArrayTools/4pI6w/src/vector_of_array.jl:404 [inlined]
[6] f
@ ./REPL[4]:5 [inlined]
[7] diffejulia_f_20621wrap
@ ./REPL[4]:0
[8] macro expansion
@ ~/.julia/packages/Enzyme/RvNgp/src/compiler.jl:8305 [inlined]
[9] enzyme_call
@ ~/.julia/packages/Enzyme/RvNgp/src/compiler.jl:7868 [inlined]
[10] CombinedAdjointThunk
@ ~/.julia/packages/Enzyme/RvNgp/src/compiler.jl:7641 [inlined]
[11] autodiff
@ ~/.julia/packages/Enzyme/RvNgp/src/Enzyme.jl:491 [inlined]
[12] autodiff
@ ~/.julia/packages/Enzyme/RvNgp/src/Enzyme.jl:537 [inlined]
[13] autodiff(::ReverseMode{…}, ::typeof(f), ::Duplicated{…}, ::Duplicated{…})
@ Enzyme ~/.julia/packages/Enzyme/RvNgp/src/Enzyme.jl:504
[14] top-level scope
@ REPL[9]:1
Some type information was truncated. Use `show(err)` to see complete types. |
This is a distinct issue from above [which is resolved on main, and confirmed on 1.10]. Can you open a new issue for the jl_genericmemory_copyto |
Are you sure this is fixed? This is what I get on master: chrisrackauckas@Chriss-MBP-2 ~ % julia
_
_ _ _(_)_ | Documentation: https://docs.julialang.org
(_) | (_) (_) |
_ _ _| |_ __ _ | Type "?" for help, "]?" for Pkg help.
| | | | | | |/ _` | |
| | |_| | | | (_| | | Version 1.10.6 (2024-10-28)
_/ |\__'_|_|_|\__'_| | Official https://julialang.org/ release
|__/ |
(@v1.10) pkg> st
Status `~/.julia/environments/v1.10/Project.toml`
[7da242da] Enzyme v0.13.13 `https://github.com/EnzymeAD/Enzyme.jl.git#main`
[f151be2c] EnzymeCore v0.8.6 `https://github.com/EnzymeAD/Enzyme.jl.git:lib/EnzymeCore#main`
[98e50ef6] JuliaFormatter v1.0.62
[1dea7af3] OrdinaryDiffEq v6.89.0
[4722fa14] PkgAuthentication v2.0.3
[90137ffa] StaticArrays v1.9.8
julia> using OrdinaryDiffEq, Enzyme, StaticArrays
julia> function lorenz!(du, u, p, t)
du[1] = 10.0(u[2] - u[1])
du[2] = u[1] * (28.0 - u[3]) - u[2]
du[3] = u[1] * u[2] - (8 / 3) * u[3]
end
lorenz! (generic function with 1 method)
julia> const _saveat = SA[0.0,0.25,0.5,0.75,1.0,1.25,1.5,1.75,2.0,2.25,2.5,2.75,3.0]
13-element SVector{13, Float64} with indices SOneTo(13):
0.0
0.25
0.5
0.75
1.0
1.25
1.5
1.75
2.0
2.25
2.5
2.75
3.0
julia> function f(y::Array{Float64}, u0::Array{Float64})
tspan = (0.0, 3.0)
prob = ODEProblem{true, SciMLBase.FullSpecialize}(lorenz!, u0, tspan)
sol = DiffEqBase.solve(prob, Tsit5(), saveat = _saveat, sensealg = DiffEqBase.SensitivityADPassThrough())
y .= sol[1,:]
return nothing
end;
julia> u0 = [1.0; 0.0; 0.0]
3-element Vector{Float64}:
1.0
0.0
0.0
julia> d_u0 = zeros(3)
3-element Vector{Float64}:
0.0
0.0
0.0
julia> y = zeros(13)
13-element Vector{Float64}:
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
julia> dy = zeros(13)
13-element Vector{Float64}:
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
julia> Enzyme.autodiff(Reverse, f, Duplicated(y, dy), Duplicated(u0, d_u0));
{[0]:Pointer, [0,-1]:Float@double, [8]:Integer, [9]:Integer, [10]:Integer, [11]:Integer, [12]:Integer, [13]:Integer, [14]:Integer, [15]:Integer, [16]:Integer, [17]:Integer, [18]:Integer, [19]:Integer, [20]:Integer, [21]:Integer, [22]:Integer, [23]:Integer, [24]:Integer, [25]:Integer, [26]:Integer, [27]:Integer, [28]:Integer, [29]:Integer, [30]:Integer, [31]:Integer, [32]:Integer, [33]:Integer, [34]:Integer, [35]:Integer, [36]:Integer, [37]:Integer, [38]:Integer, [39]:Integer}
canonicalizing 8
Assertion failed: ((size_t)pair.first[0] < len), function CanonicalizeInPlace, file /workspace/srcdir/Enzyme/enzyme/Enzyme/TypeAnalysis/TypeTree.h, line 700.
[56101] signal (6): Abort trap: 6
in expression starting at REPL[10]:1
__pthread_kill at /usr/lib/system/libsystem_kernel.dylib (unknown line)
Allocations: 85708382 (Pool: 85577671; Big: 130711); GC: 55
zsh: abort julia |
julia> using OrdinaryDiffEq, Enzyme, StaticArrays
julia> function lorenz!(du, u, p, t)
du[1] = 10.0(u[2] - u[1])
du[2] = u[1] * (28.0 - u[3]) - u[2]
du[3] = u[1] * u[2] - (8 / 3) * u[3]
end
lorenz! (generic function with 1 method)
julia> const _saveat = SA[0.0,0.25,0.5,0.75,1.0,1.25,1.5,1.75,2.0,2.25,2.5,2.75,3.0]
13-element SVector{13, Float64} with indices SOneTo(13):
0.0
0.25
0.5
0.75
1.0
1.25
1.5
1.75
2.0
2.25
2.5
2.75
3.0
julia> function f(y::Array{Float64}, u0::Array{Float64})
tspan = (0.0, 3.0)
prob = ODEProblem{true, SciMLBase.FullSpecialize}(lorenz!, u0, tspan)
sol = DiffEqBase.solve(prob, Tsit5(), saveat = _saveat, sensealg = DiffEqBase.SensitivityADPassThrough())
y .= sol[1,:]
return nothing
end;
julia> u0 = [1.0; 0.0; 0.0]
3-element Vector{Float64}:
1.0
0.0
0.0
julia> d_u0 = zeros(3)
3-element Vector{Float64}:
0.0
0.0
0.0
julia> y = zeros(13)
13-element Vector{Float64}:
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
julia> dy = zeros(13)
13-element Vector{Float64}:
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
0.0
julia> Enzyme.autodiff(Reverse, f, Duplicated(y, dy), Duplicated(u0, d_u0));
┌ Warning: TODO reverse jl_array_del_end zero-set used memset rather than runtime type of (false, nothing) in %48 = load {} addrspace(10)*, {} addrspace(10)* addrspace(11)* %47, align 8, !dbg !215, !tbaa !219, !alias.scope !223, !noalias !226, !enzyme_type !231
│ Caused by:
│ Stacktrace:
│ [1] _deleteend!
│ @ ./array.jl:1081
│ [2] resize!
│ @ ./array.jl:1320
│ [3] _postamble!
│ @ ~/.julia/packages/OrdinaryDiffEqCore/Hp3EU/src/integrators/integrator_utils.jl:155
└ @ Enzyme.Compiler ~/.julia/packages/GPUCompiler/GnbhK/src/utils.jl:59
┌ Warning: TODO reverse jl_array_del_end zero-set used memset rather than runtime type of (false, nothing) in %getfield90 = load atomic {} addrspace(10)*, {} addrspace(10)* addrspace(11)* %281 unordered, align 8, !dbg !470, !tbaa !222, !alias.scope !226, !noalias !229, !nonnull !0, !dereferenceable !263, !align !264, !enzyme_type !324
│ Caused by:
│ Stacktrace:
│ [1] _deleteend!
│ @ ./array.jl:1081
│ [2] resize!
│ @ ./array.jl:1320
│ [3] _savevalues!
│ @ ~/.julia/packages/OrdinaryDiffEqCore/Hp3EU/src/integrators/integrator_utils.jl:145
└ @ Enzyme.Compiler ~/.julia/packages/GPUCompiler/GnbhK/src/utils.jl:59
┌ Warning: TODO reverse jl_array_del_end zero-set used memset rather than runtime type of (false, nothing) in %getfield7 = load atomic {} addrspace(10)*, {} addrspace(10)* addrspace(11)* %24 unordered, align 8, !dbg !274, !tbaa !222, !alias.scope !226, !noalias !229, !nonnull !0, !dereferenceable !241, !align !242, !enzyme_type !276
│ Caused by:
│ Stacktrace:
│ [1] _deleteend!
│ @ ./array.jl:1081
│ [2] resize!
│ @ ./array.jl:1320
│ [3] #reeval_internals_due_to_modification!#29
│ @ ~/.julia/packages/OrdinaryDiffEqCore/Hp3EU/src/integrators/integrator_interface.jl:49
└ @ Enzyme.Compiler ~/.julia/packages/GPUCompiler/GnbhK/src/utils.jl:59
┌ Warning: TODO reverse jl_array_del_end zero-set used memset rather than runtime type of (false, nothing) in %getfield = load atomic {} addrspace(10)*, {} addrspace(10)* addrspace(11)* %7 unordered, align 8, !dbg !235, !tbaa !221, !alias.scope !225, !noalias !239, !nonnull !0, !dereferenceable !240, !align !241, !enzyme_type !242
│ Caused by:
│ Stacktrace:
│ [1] _deleteend!
│ @ ./array.jl:1081
│ [2] resize!
│ @ ./array.jl:1320
│ [3] initialize!
│ @ ~/.julia/packages/OrdinaryDiffEqTsit5/DHYtz/src/tsit_perform_step.jl:166
└ @ Enzyme.Compiler ~/.julia/packages/GPUCompiler/GnbhK/src/utils.jl:59
julia>
julia>
julia> st
ERROR: UndefVarError: `st` not defined
(tmp) pkg> st
Status `~/git/OrdinaryDiffEq.jl/tmp/Project.toml`
[7da242da] Enzyme v0.13.14
[1dea7af3] OrdinaryDiffEq v6.90.1
[90137ffa] StaticArrays v1.9.8 so idk what's happening on your end |
but it does look like you were on an old version of enzyme |
MWE:
gives:
but that function is already marked as inactive
Full stack trace: enzyme.txt
The text was updated successfully, but these errors were encountered: