EnzymeAD / Enzyme.jl

Julia bindings for the Enzyme automatic differentiator
https://enzyme.mit.edu
MIT License
455 stars 63 forks source link

`get` error on earlier Julia versions when assertions are enabled #993

Closed jgreener64 closed 11 months ago

jgreener64 commented 1 year ago

On Julia versions before 1.9 and Enzyme main (d7a68c407872b5d5a63a740150efedd902bd9e8b) it appears there is an error with get when LLVM assertions are enabled:

using Enzyme, Test
f12(x, k) = get(Dict(1 => 1.0, 2 => x, 3 => 3.0), k, 1.0)
@test autodiff(Reverse, f12, Active, Active(2.0),  Const(2))[1] == (1.0, nothing)
@test autodiff(Forward, f12, Duplicated(2.0, 1.0), Const(2))    == (1.0,)
@test autodiff(Reverse, f12, Active, Active(2.0),  Const(3))[1] == (0.0, nothing)
@test autodiff(Forward, f12, Duplicated(2.0, 1.0), Const(3))    == (0.0,)
@test autodiff(Reverse, f12, Active, Active(2.0),  Const(4))[1] == (0.0, nothing)
@test autodiff(Forward, f12, Duplicated(2.0, 1.0), Const(4))    == (0.0,)

Error is at https://github.com/EnzymeAD/Enzyme.jl/actions/runs/5808215994/job/15744567711?pr=969:

julia: /workspace/srcdir/llvm-project/llvm/lib/Analysis/ScalarEvolution.cpp:8150: llvm::ScalarEvolution::ExitLimit llvm::ScalarEvolution::computeExitLimitFromSingleExitSwitch(const llvm::Loop*, llvm::SwitchInst*, llvm::BasicBlock*, bool): Assertion `L->contains(Switch->getDefaultDest()) && "Default case must not exit the loop!"' failed.

signal (6): Aborted
in expression starting at /home/runner/work/Enzyme.jl/Enzyme.jl/test/runtests.jl:258
gsignal 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: 0x7f8d404d8728)
__assert_fail at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
_ZN4llvm15ScalarEvolution36computeExitLimitFromSingleExitSwitchEPKNS_4LoopEPNS_10SwitchInstEPNS_10BasicBlockEb at /home/runner/work/Enzyme.jl/Enzyme.jl/julia/usr/bin/../lib/libLLVM-13jl.so (unknown line)
computeExitLimit at /workspace/srcdir/Enzyme/enzyme/Enzyme/MustExitScalarEvolution.cpp:110
getContext at /workspace/srcdir/Enzyme/enzyme/Enzyme/CacheUtility.cpp:560
forceAugmentedReturns at /workspace/srcdir/Enzyme/enzyme/Enzyme/GradientUtils.cpp:8195
CreateAugmentedPrimal at /workspace/srcdir/Enzyme/enzyme/Enzyme/EnzymeLogic.cpp:2311
recursivelyHandleSubfunction at /workspace/srcdir/Enzyme/enzyme/Enzyme/AdjointGenerator.h:7380
visitCallInst at /workspace/srcdir/Enzyme/enzyme/Enzyme/AdjointGenerator.h:10326
delegateCallInst at /opt/x86_64-linux-gnu/x86_64-linux-gnu/sys-root/usr/local/include/llvm/IR/InstVisitor.h:302 [inlined]
visitCall at /opt/x86_64-linux-gnu/x86_64-linux-gnu/sys-root/usr/local/include/llvm/IR/Instruction.def:209 [inlined]
visit at /opt/x86_64-linux-gnu/x86_64-linux-gnu/sys-root/usr/local/include/llvm/IR/Instruction.def:209
   @ Pkg.Operations ~/work/Enzyme.jl/Enzyme.jl/julia/usr/share/julia/stdlib/v1.8/Pkg/src/Operations.jl:1813
 [3] test(ctx::Pkg.Types.Context, pkgs::Vector{Pkg.Types.PackageSpec}; coverage::Bool, test_fn::Nothing, julia_args::Vector{String}, test_args::Cmd, force_latest_compatible_version::Bool, allow_earlier_backwards_compatible_versions::Bool, allow_reresolve::Bool, kwargs::Base.Pairs{Symbol, IOContext{Base.PipeEndpoint}, Tuple{Symbol}, NamedTuple{(:io,), Tuple{IOContext{Base.PipeEndpoint}}}})
   @ Pkg.API ~/work/Enzyme.jl/Enzyme.jl/julia/usr/share/julia/stdlib/v1.8/Pkg/src/API.jl:434
 [4] test(pkgs::Vector{Pkg.Types.PackageSpec}; io::IOContext{Base.PipeEndpoint}, kwargs::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol, Symbol}, NamedTuple{(:coverage, :julia_args, :force_latest_compatible_version), Tuple{Bool, Vector{String}, Bool}}})
   @ Pkg.API ~/work/Enzyme.jl/Enzyme.jl/julia/usr/share/julia/stdlib/v1.8/Pkg/src/API.jl:156
 [5] test(; name::Nothing, uuid::Nothing, version::Nothing, url::Nothing, rev::Nothing, path::Nothing, mode::Pkg.Types.PackageMode, subdir::Nothing, kwargs::Base.Pairs{Symbol, Any, Tuple{Symbol, Symbol, Symbol}, NamedTuple{(:coverage, :julia_args, :force_latest_compatible_version), Tuple{Bool, Vector{String}, Bool}}})
   @ Pkg.API ~/work/Enzyme.jl/Enzyme.jl/julia/usr/share/julia/stdlib/v1.8/Pkg/src/API.jl:171
 [6] top-level scope
   @ ~/work/_actions/julia-actions/julia-runtest/v1/test_harness.jl:15
 [7] include(fname::String)
   @ Base.MainInclude ./client.jl:476
 [8] top-level scope
   @ none:1
in expression starting at /home/runner/work/_actions/julia-actions/julia-runtest/v1/test_harness.jl:7
Error: Process completed with exit code 1.
wsmoses commented 1 year ago

So after investigating that assertion error is unnecessary here. Nevertheless is being fixed by https://github.com/EnzymeAD/Enzyme/pull/1468 (but will require a jllbump) since it'll make it harder to find actual assertion errors otherwises.

wsmoses commented 11 months ago

Should have jll bump landed already.