-
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. |
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: