Enzyme.jl icon indicating copy to clipboard operation
Enzyme.jl copied to clipboard

Segmentation fault when puting a complex number to power 0

Open gaspardbb opened this issue 2 years ago • 2 comments

Hi,

I've encountered a bug with Enzyme which took me a while to localize. Basically, the following code results in a segmentation fault:

using Enzyme

function aux(f, μ)
    result = 0.0im

    z = exp(im)
    result += z^μ   #  Bug here

    result
end

g = 1.0
μ = 0
loss(g, μ) = sum(abs.(aux(g, μ)))

@show loss(g, μ)
autodiff(Reverse, loss, Active, Active(g), μ)

Having non-zero power or a float power or a real number in z does not cause the segfault.

I have Enzyme v0.10.4 and Julia 1.7. Obviously I don't fancy optimizing such functions but I can provide context if needed! :)

gaspardbb avatar Jul 19 '22 12:07 gaspardbb

Can you paste whatever you see in a log/backtrace?

I'm not able to reproduce it from your code snippet on main.

julia> using Enzyme


julia>

julia> function aux(f, μ)
           result = 0.0im

           z = exp(im)
           result += z^μ   #  Bug here

           result
       end
aux (generic function with 1 method)

julia>

julia> g = 1.0
1.0

julia> μ = 0
0

julia> loss(g, μ) = sum(abs.(aux(g, μ)))
loss (generic function with 1 method)

julia>

julia> @show loss(g, μ)
loss(g, μ) = 1.0
1.0

julia> autodiff(Reverse, loss, Active, Active(g), μ)

(0.0,)

wsmoses avatar Jul 19 '22 16:07 wsmoses

Sure, here it is

signal (11): Segmentation fault: 11
in expression starting at REPL[20]:1
unknown function (ip: 0x10e7d7c6c)
Allocations: 33515273 (Pool: 33500453; Big: 14820); GC: 40

I'm on Mac M1 with an intel build (Rosetta). So that may be a problem.

gaspardbb avatar Jul 19 '22 19:07 gaspardbb

@gaspardbb does this still reproduce for you?

vchuravy avatar Oct 11 '22 01:10 vchuravy

Just tried with Enzyme v0.10.11 and Julia 1.8 (M1 build) and this does not reproduce! We can close the issue.

gaspardbb avatar Oct 11 '22 08:10 gaspardbb