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

Enzyme v0.13.13 asserts for Duplicated function #2056

Closed
gdalle opened this issue Nov 4, 2024 · 5 comments
Closed

Enzyme v0.13.13 asserts for Duplicated function #2056

gdalle opened this issue Nov 4, 2024 · 5 comments

Comments

@gdalle
Copy link
Contributor

gdalle commented Nov 4, 2024

Enzyme v0.13.13 fails the DI test suite on Julia 1.10, while v0.13.12 didn't. Do you know what could have caused it?

CI log: https://github.com/JuliaDiff/DifferentiationInterface.jl/actions/runs/11669117341/job/32490363602?pr=606

MWE with DifferentiationInterfaceTest (the first failing test):

using DifferentiationInterface, DifferentiationInterfaceTest
import Enzyme

backend = AutoEnzyme(mode=Enzyme.Forward; function_annotation=Enzyme.Duplicated)

scen = default_scenarios(; include_normal=false, include_closurified=true)[6]
test_differentiation(backend, [scen])

Standalone MWE:

using DifferentiationInterface
import Enzyme

backend = AutoEnzyme(mode=Enzyme.Forward; function_annotation=Enzyme.Duplicated)

struct BufferedMap!{F,X,Y}
    f::F
    x_buffer::Vector{X}
    y_buffer::Vector{Y}
end

function (bc::BufferedMap!)(y, x)
    (; f, x_buffer, y_buffer) = bc
    x_buffer[1] = x
    y_buffer[1] = y
    map!(f, y_buffer[1], x_buffer[1])
    return copy(y_buffer[1])
end

x, y, dx = zeros(1), zeros(1), ones(1)
f! = BufferedMap!(sin, [copy(x)], [copy(y)])

value_and_pushforward(f!, y, backend, x, (dx,))

Stacktrace of the pure MWE:

{[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
julia: /workspace/srcdir/Enzyme/enzyme/Enzyme/TypeAnalysis/TypeTree.h:700: void TypeTree::CanonicalizeInPlace(size_t, const llvm::DataLayout&): Assertion `(size_t)pair.first[0] < len' failed.

[53662] signal (6.-6): Aborted
in expression starting at /home/guillaume/Work/GitHub/Julia/DifferentiationInterface.jl/DifferentiationInterface/test/Back/Enzyme/playground.jl:23
pthread_kill at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
raise at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
abort at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: 0x723acb02871a)
__assert_fail at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
CanonicalizeInPlace at /workspace/srcdir/Enzyme/enzyme/Enzyme/TypeAnalysis/TypeTree.h:700
updateAnalysis at /workspace/srcdir/Enzyme/enzyme/Enzyme/TypeAnalysis/TypeAnalysis.cpp:1095
considerTBAA at /workspace/srcdir/Enzyme/enzyme/Enzyme/TypeAnalysis/TypeAnalysis.cpp:1229
analyzeFunction at /workspace/srcdir/Enzyme/enzyme/Enzyme/TypeAnalysis/TypeAnalysis.cpp:5925
CreateFromClone at /workspace/srcdir/Enzyme/enzyme/Enzyme/DiffeGradientUtils.cpp:158
CreateForwardDiff at /workspace/srcdir/Enzyme/enzyme/Enzyme/EnzymeLogic.cpp:4655
EnzymeCreateForwardDiff at /workspace/srcdir/Enzyme/enzyme/Enzyme/CApi.cpp:605
EnzymeCreateForwardDiff at /home/guillaume/.julia/packages/Enzyme/VSRgT/src/api.jl:319
unknown function (ip: 0x723aca9d08c9)
_jl_invoke at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2895 [inlined]
ijl_apply_generic at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:3077
enzyme! at /home/guillaume/.julia/packages/Enzyme/VSRgT/src/compiler.jl:4079
unknown function (ip: 0x723aca9cecc8)
_jl_invoke at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2895 [inlined]
ijl_apply_generic at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:3077
#codegen#19016 at /home/guillaume/.julia/packages/Enzyme/VSRgT/src/compiler.jl:7156
codegen at /home/guillaume/.julia/packages/Enzyme/VSRgT/src/compiler.jl:5972 [inlined]
_thunk at /home/guillaume/.julia/packages/Enzyme/VSRgT/src/compiler.jl:8267
_thunk at /home/guillaume/.julia/packages/Enzyme/VSRgT/src/compiler.jl:8267 [inlined]
cached_compilation at /home/guillaume/.julia/packages/Enzyme/VSRgT/src/compiler.jl:8308 [inlined]
thunkbase at /home/guillaume/.julia/packages/Enzyme/VSRgT/src/compiler.jl:8440
unknown function (ip: 0x723aca936ec0)
_jl_invoke at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2895 [inlined]
ijl_apply_generic at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:3077
#s2080#19075 at /home/guillaume/.julia/packages/Enzyme/VSRgT/src/compiler.jl:8577 [inlined]
#s2080#19075 at ./none:0
_jl_invoke at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2895 [inlined]
ijl_apply_generic at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:3077
GeneratedFunctionStub at ./boot.jl:602
_jl_invoke at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2895 [inlined]
ijl_apply_generic at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:3077
jl_call_staged at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/method.c:540
ijl_code_for_staged at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/method.c:593
get_staged at ./compiler/utilities.jl:123
retrieve_code_info at ./compiler/utilities.jl:135 [inlined]
InferenceState at ./compiler/inferencestate.jl:430
typeinf_edge at ./compiler/typeinfer.jl:920
abstract_call_method at ./compiler/abstractinterpretation.jl:629
abstract_call_gf_by_type at ./compiler/abstractinterpretation.jl:95
abstract_call_known at ./compiler/abstractinterpretation.jl:2087
abstract_call at ./compiler/abstractinterpretation.jl:2169
abstract_call at ./compiler/abstractinterpretation.jl:2162
abstract_call at ./compiler/abstractinterpretation.jl:2354
abstract_eval_call at ./compiler/abstractinterpretation.jl:2370
abstract_eval_statement_expr at ./compiler/abstractinterpretation.jl:2380
abstract_eval_statement at ./compiler/abstractinterpretation.jl:2624
abstract_eval_basic_statement at ./compiler/abstractinterpretation.jl:2889
typeinf_local at ./compiler/abstractinterpretation.jl:3098
typeinf_nocycle at ./compiler/abstractinterpretation.jl:3186
_typeinf at ./compiler/typeinfer.jl:247
typeinf at ./compiler/typeinfer.jl:216
typeinf_edge at ./compiler/typeinfer.jl:930
abstract_call_method at ./compiler/abstractinterpretation.jl:629
abstract_call_gf_by_type at ./compiler/abstractinterpretation.jl:95
abstract_call_known at ./compiler/abstractinterpretation.jl:2087
abstract_call at ./compiler/abstractinterpretation.jl:2169
abstract_apply at ./compiler/abstractinterpretation.jl:1612
abstract_call_known at ./compiler/abstractinterpretation.jl:2004
abstract_call at ./compiler/abstractinterpretation.jl:2169
abstract_call at ./compiler/abstractinterpretation.jl:2162
abstract_call at ./compiler/abstractinterpretation.jl:2354
abstract_eval_call at ./compiler/abstractinterpretation.jl:2370
abstract_eval_statement_expr at ./compiler/abstractinterpretation.jl:2380
abstract_eval_statement at ./compiler/abstractinterpretation.jl:2624
abstract_eval_basic_statement at ./compiler/abstractinterpretation.jl:2913
typeinf_local at ./compiler/abstractinterpretation.jl:3098
typeinf_nocycle at ./compiler/abstractinterpretation.jl:3186
_typeinf at ./compiler/typeinfer.jl:247
typeinf at ./compiler/typeinfer.jl:216
typeinf_edge at ./compiler/typeinfer.jl:930
abstract_call_method at ./compiler/abstractinterpretation.jl:629
abstract_call_gf_by_type at ./compiler/abstractinterpretation.jl:95
abstract_call_known at ./compiler/abstractinterpretation.jl:2087
abstract_call at ./compiler/abstractinterpretation.jl:2169
abstract_apply at ./compiler/abstractinterpretation.jl:1612
abstract_call_known at ./compiler/abstractinterpretation.jl:2004
abstract_call at ./compiler/abstractinterpretation.jl:2169
abstract_call at ./compiler/abstractinterpretation.jl:2162
abstract_call at ./compiler/abstractinterpretation.jl:2354
abstract_eval_call at ./compiler/abstractinterpretation.jl:2370
abstract_eval_statement_expr at ./compiler/abstractinterpretation.jl:2380
abstract_eval_statement at ./compiler/abstractinterpretation.jl:2624
abstract_eval_basic_statement at ./compiler/abstractinterpretation.jl:2913
typeinf_local at ./compiler/abstractinterpretation.jl:3098
typeinf_nocycle at ./compiler/abstractinterpretation.jl:3186
_typeinf at ./compiler/typeinfer.jl:247
typeinf at ./compiler/typeinfer.jl:216
typeinf_ext at ./compiler/typeinfer.jl:1051
typeinf_ext_toplevel at ./compiler/typeinfer.jl:1082
typeinf_ext_toplevel at ./compiler/typeinfer.jl:1078
jfptr_typeinf_ext_toplevel_35741.1 at /home/guillaume/.julia/juliaup/julia-1.10.6+0.x64.linux.gnu/lib/julia/sys.so (unknown line)
_jl_invoke at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2895 [inlined]
ijl_apply_generic at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:3077
jl_apply at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/julia.h:1982 [inlined]
jl_type_infer at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:394
jl_generate_fptr_impl at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/jitlayers.cpp:504
jl_compile_method_internal at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2481 [inlined]
jl_compile_method_internal at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2368
_jl_invoke at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2887 [inlined]
ijl_apply_generic at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:3077
jl_apply at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/julia.h:1982 [inlined]
do_call at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/interpreter.c:126
eval_value at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/interpreter.c:223
eval_stmt_value at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/interpreter.c:174 [inlined]
eval_body at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/interpreter.c:617
jl_interpret_toplevel_thunk at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/interpreter.c:775
jl_toplevel_eval_flex at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/toplevel.c:934
jl_toplevel_eval_flex at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/toplevel.c:877
ijl_toplevel_eval_in at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/toplevel.c:985
eval at ./boot.jl:385 [inlined]
include_string at ./loading.jl:2076
_jl_invoke at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2895 [inlined]
ijl_apply_generic at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:3077
_include at ./loading.jl:2136
include at ./Base.jl:495
jfptr_include_46489.1 at /home/guillaume/.julia/juliaup/julia-1.10.6+0.x64.linux.gnu/lib/julia/sys.so (unknown line)
_jl_invoke at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2895 [inlined]
ijl_apply_generic at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:3077
exec_options at ./client.jl:323
_start at ./client.jl:557
jfptr__start_82944.1 at /home/guillaume/.julia/juliaup/julia-1.10.6+0.x64.linux.gnu/lib/julia/sys.so (unknown line)
_jl_invoke at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:2895 [inlined]
ijl_apply_generic at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/gf.c:3077
jl_apply at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/julia.h:1982 [inlined]
true_main at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/jlapi.c:582
jl_repl_entrypoint at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/src/jlapi.c:731
main at /cache/build/builder-amdci5-5/julialang/julia-release-1-dot-10/cli/loader_exe.c:58
unknown function (ip: 0x723acb029d8f)
__libc_start_main at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: 0x4010b8)
Allocations: 16741145 (Pool: 16708324; Big: 32821); GC: 26
Aborted (core dumped)
@wsmoses
Copy link
Member

wsmoses commented Nov 4, 2024

can you create a mwe and confirm it on main (we're about to release a new patch)

@wsmoses
Copy link
Member

wsmoses commented Nov 4, 2024

a mwe without DI***

@gdalle
Copy link
Contributor Author

gdalle commented Nov 4, 2024

sure

@gdalle
Copy link
Contributor Author

gdalle commented Nov 4, 2024

Here is a pure Enzyme MWE, which still segfaults on main:

using Enzyme

struct BufferedMap!{F,X,Y}
    f::F
    x_buffer::Vector{X}
    y_buffer::Vector{Y}
end

function (bc::BufferedMap!)(y, x)
    (; f, x_buffer, y_buffer) = bc
    x_buffer[1] = x
    y_buffer[1] = y
    map!(f, y_buffer[1], x_buffer[1])
    return copy(y_buffer[1])
end

x, y, dx = zeros(1), zeros(1), ones(1)
f! = BufferedMap!(sin, [copy(x)], [copy(y)])

function my_value_and_pushforward(f!, y, x, dx)
    f!_and_df! = Duplicated(f!, make_zero(f!))  # is this the right annotation? it used to work
    dx_sametype = convert(typeof(x), dx)
    dy_sametype = make_zero(y)
    x_and_dx = Duplicated(x, dx_sametype)
    y_and_dy = Duplicated(y, dy_sametype)
    autodiff(Forward, f!_and_df!, Const, y_and_dy, x_and_dx)
    return y, dy_sametype
end

my_value_and_pushforward(f!, y, x, dx)

Maybe Duplicated is the wrong annotation for f!, but it used to work until the latest release of Enzyme so 🤷

@gdalle gdalle changed the title Enzyme v0.13.13 breaks DI testing on Julia 1.10 Enzyme v0.13.13 segfaults for Duplicated function Nov 4, 2024
@wsmoses wsmoses changed the title Enzyme v0.13.13 segfaults for Duplicated function Enzyme v0.13.13 asserts for Duplicated function Nov 5, 2024
@wsmoses
Copy link
Member

wsmoses commented Nov 5, 2024

Fixed on main

@wsmoses wsmoses closed this as completed Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants