Enzyme.jl
Enzyme.jl copied to clipboard
Captured `x` breaks autodiff
let
function loadsin(xp)
x = @inbounds xp[1]
@inbounds xp[1] = 0.0
sin(x)
end
global invsin
function invsin(xp)
xp = Base.invokelatest(convert, Vector{Float64}, xp)
loadsin(xp)
end
x = [2.0]
end
x = [2.0]
dx = [0.0]
Enzyme.autodiff(invsin, Active, Duplicated(x, dx))
The particular bug:
ERROR: UndefRefError: access to undefined reference
Stacktrace:
[1] unsafe_convert
@ ~/.julia/packages/Enzyme/di3zM/src/compiler.jl:4277 [inlined]
[2] macro expansion
@ ~/.julia/packages/Enzyme/di3zM/src/compiler.jl:4520 [inlined]
[3] enzyme_call
@ ~/.julia/packages/Enzyme/di3zM/src/compiler.jl:4316 [inlined]
[4] AugmentedForwardThunk
@ ~/.julia/packages/Enzyme/di3zM/src/compiler.jl:4307 [inlined]
[5] autodiff
@ ~/.julia/packages/Enzyme/di3zM/src/Enzyme.jl:272 [inlined]
[6] autodiff(f::typeof(invsin), #unused#::Type{Active}, args::Duplicated{Vector{Float64}})
@ Enzyme ~/.julia/packages/Enzyme/di3zM/src/Enzyme.jl:411
[7] top-level scope
@ REPL[74]:1
Present duplicate of https://github.com/EnzymeAD/Enzyme.jl/issues/293
Fixed by #408
On 1.6:
truct return: Error During Test at /home/runner/work/Enzyme.jl/Enzyme.jl/test/runtests.jl:257
Test threw exception
Expression: Enzyme.autodiff(invsin, Active, Duplicated(x, dx)) == ()
TypeError: in typeassert, expected Enzyme.Compiler.Tape, got a value of type Tuple{Core.Compiler.Pair{Core.Compiler.Pair{Int64, Int64}, Any}, Tuple{Int64, Int64}}
Struct return: Test Failed at /home/runner/work/Enzyme.jl/Enzyme.jl/test/runtests.jl:258
Expression: dx[1] == -0.4161468365471424
Evaluated: 0.0 == -0.4161468365471424
Stacktrace:
[1] macro expansion
@ ~/work/Enzyme.jl/Enzyme.jl/test/runtests.jl:258 [inlined]
[2] macro expansion
@ /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.6/Test/src/Test.jl:1151 [inlined]
[3] top-level scope
@ ~/work/Enzyme.jl/Enzyme.jl/test/runtests.jl:255
Test Summary: | Fail Error Total
Struct return | 1 1 2