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

Segfault on calling `gradient`

Open stromberger opened this issue 6 months ago • 1 comments

I get a segmentation fault when calling gradient on the following (rather cursed) function using Julia 1.11.5 (macOS, arm64) and Zygote 0.7.7.

Minimal Workable Example

using Zygote

f2(in0,in1,in2) = ((1 * (1 * ((((false && (true && (false && false))) && (! (! (((! false) && (! ((! (true && true)) || ((! true) || (! true))))) && (true && (true && true)))))) && ((false && false) && (((false || ((! (((! true) || (! true)) || false)) && true)) && true) && ((((! (false || (((! true) || (! true)) || (! true)))) && true) || false) && true)))) ? (in2 + (((1 - 32) * in2) + ((- (0 + (- in2))) * (32 + ((- (1 * 46)) + 46))))) : ((((44 * 1) + (in2 * 1)) + ((((((0 - ((44 - 42) + (42 + 0))) + (- (- (- 31)))) - 43) + 43) + 31) * 1)) + ((0 * 1) + 0))))) * 1)

gradient(f2, 1, 2, 3)

Stacktrace


[2682] signal 11 (2): Segmentation fault: 11
in expression starting at /Users/alex/Desktop/juliadiff/repro.jl:5
ijl_apply_generic at /opt/homebrew/Cellar/julia/1.11.5/lib/julia/libjulia-internal.1.11.5.dylib (unknown line)
f2 at /Users/alex/Desktop/juliadiff/repro.jl:3 [inlined]
Pullback at /Users/alex/.julia/packages/Zygote/wfLOG/src/compiler/interface2.jl:0
#88 at /Users/alex/.julia/packages/Zygote/wfLOG/src/compiler/interface.jl:97
unknown function (ip: 0x1170080a3)
gradient at /Users/alex/.julia/packages/Zygote/wfLOG/src/compiler/interface.jl:154
do_call at /opt/homebrew/Cellar/julia/1.11.5/lib/julia/libjulia-internal.1.11.5.dylib (unknown line)
eval_stmt_value at /opt/homebrew/Cellar/julia/1.11.5/lib/julia/libjulia-internal.1.11.5.dylib (unknown line)
eval_body at /opt/homebrew/Cellar/julia/1.11.5/lib/julia/libjulia-internal.1.11.5.dylib (unknown line)
jl_interpret_toplevel_thunk at /opt/homebrew/Cellar/julia/1.11.5/lib/julia/libjulia-internal.1.11.5.dylib (unknown line)
jl_toplevel_eval_flex at /opt/homebrew/Cellar/julia/1.11.5/lib/julia/libjulia-internal.1.11.5.dylib (unknown line)
jl_toplevel_eval_flex at /opt/homebrew/Cellar/julia/1.11.5/lib/julia/libjulia-internal.1.11.5.dylib (unknown line)
ijl_toplevel_eval_in at /opt/homebrew/Cellar/julia/1.11.5/lib/julia/libjulia-internal.1.11.5.dylib (unknown line)
japi1_include_string_72160.1 at /opt/homebrew/Cellar/julia/1.11.5/lib/julia/sys.dylib (unknown line)
japi1__include_72169.1 at /opt/homebrew/Cellar/julia/1.11.5/lib/julia/sys.dylib (unknown line)
julia_include_46882.1 at /opt/homebrew/Cellar/julia/1.11.5/lib/julia/sys.dylib (unknown line)
jfptr_include_46883.1 at /opt/homebrew/Cellar/julia/1.11.5/lib/julia/sys.dylib (unknown line)
julia_exec_options_73410.1 at /opt/homebrew/Cellar/julia/1.11.5/lib/julia/sys.dylib (unknown line)
julia__start_73550.1 at /opt/homebrew/Cellar/julia/1.11.5/lib/julia/sys.dylib (unknown line)
jfptr__start_73551.1 at /opt/homebrew/Cellar/julia/1.11.5/lib/julia/sys.dylib (unknown line)
true_main at /opt/homebrew/Cellar/julia/1.11.5/lib/julia/libjulia-internal.1.11.5.dylib (unknown line)
jl_repl_entrypoint at /opt/homebrew/Cellar/julia/1.11.5/lib/julia/libjulia-internal.1.11.5.dylib (unknown line)
Allocations: 7421913 (Pool: 7421688; Big: 225); GC: 12
zsh: segmentation fault  julia repro.jl

stromberger avatar May 28 '25 21:05 stromberger

Can reproduce.

On Julia 1.10, a different error:

julia> gradient(f2, 1, 2, 3)
ERROR: UndefRefError: access to undefined reference
Stacktrace:
 [1] getindex
   @ ./essentials.jl:13 [inlined]
 [2] pop!(stk::Zygote.Stack{Any})
   @ Zygote ~/.julia/packages/Zygote/wfLOG/src/compiler/emit.jl:14
 [3] f2
   @ ./REPL[3]:1 [inlined]
 [4] (::Zygote.Pullback{Tuple{typeof(f2), Int64, Int64, Int64}, Any})(Δ::Int64)
   @ Zygote ~/.julia/packages/Zygote/wfLOG/src/compiler/interface2.jl:0
 [5] (::Zygote.var"#88#89"{Zygote.Pullback{Tuple{typeof(f2), Int64, Int64, Int64}, Any}})(Δ::Int64)
   @ Zygote ~/.julia/packages/Zygote/wfLOG/src/compiler/interface.jl:97
 [6] gradient(::Function, ::Int64, ::Vararg{Int64})
   @ Zygote ~/.julia/packages/Zygote/wfLOG/src/compiler/interface.jl:154
 [7] top-level scope
   @ REPL[4]:1

(@v1.10) pkg> st Zygote  # same error with Zygote v0.6.77 instead
Status `~/.julia/environments/v1.10/Project.toml`
  [e88e6eb3] Zygote v0.7.7

julia> VERSION
v"1.10.9"

mcabbott avatar May 30 '25 00:05 mcabbott