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

StackOverflow in forward mode #1330

Closed
gdalle opened this issue Mar 6, 2024 · 5 comments
Closed

StackOverflow in forward mode #1330

gdalle opened this issue Mar 6, 2024 · 5 comments

Comments

@gdalle
Copy link
Contributor

gdalle commented Mar 6, 2024

julia> using Enzyme

julia> g(x::Number) = [sin(x) cos(x); sin(2x) cos(2x)]
g (generic function with 1 method)

julia> autodiff(Forward, g, Duplicated, Duplicated(1.0, 1.0))
ERROR: StackOverflowError:
Stacktrace:
     [1] hvcat
       @ ~/.julia/juliaup/julia-1.10.2+0.x64.linux.gnu/share/julia/stdlib/v1.10/SparseArrays/src/sparsevector.jl:1269 [inlined]
     [2] hvcat
       @ ~/.julia/juliaup/julia-1.10.2+0.x64.linux.gnu/share/julia/stdlib/v1.10/SparseArrays/src/sparsevector.jl:0 [inlined]
     [3] fwddiffejulia_hvcat_6909_inner_1wrap
       @ ~/.julia/juliaup/julia-1.10.2+0.x64.linux.gnu/share/julia/stdlib/v1.10/SparseArrays/src/sparsevector.jl:0
     [4] macro expansion
       @ ~/.julia/packages/Enzyme/wR2t7/src/compiler.jl:5378 [inlined]
     [5] enzyme_call
       @ ~/.julia/packages/Enzyme/wR2t7/src/compiler.jl:5056 [inlined]
     [6] ForwardModeThunk
       @ ~/.julia/packages/Enzyme/wR2t7/src/compiler.jl:5001 [inlined]
     [7] runtime_generic_fwd(activity::Type{…}, width::Val{…}, RT::Val{…}, f::typeof(hvcat), df::Nothing, primal_1::Tuple{…}, shadow_1_1::Nothing, primal_2::Float64, shadow_2_1::Float64, primal_3::Float64, shadow_3_1::Float64, primal_4::Float64, shadow_4_1::Float64, primal_5::Float64, shadow_5_1::Float64)
       @ Enzyme.Compiler ~/.julia/packages/Enzyme/wR2t7/src/rules/jitrules.jl:116
--- the last 7 lines are repeated 5630 more times ---
 [39418] hvcat
       @ ~/.julia/juliaup/julia-1.10.2+0.x64.linux.gnu/share/julia/stdlib/v1.10/SparseArrays/src/sparsevector.jl:1269 [inlined]
 [39419] g
       @ ~/Work/GitHub/Julia/DifferentiationInterface.jl/test/enzyme.jl:18 [inlined]
 [39420] fwddiffejulia_g_9702wrap
       @ ~/Work/GitHub/Julia/DifferentiationInterface.jl/test/enzyme.jl:0
 [39421] macro expansion
       @ ~/.julia/packages/Enzyme/wR2t7/src/compiler.jl:5378 [inlined]
 [39422] enzyme_call
       @ ~/.julia/packages/Enzyme/wR2t7/src/compiler.jl:5056 [inlined]
 [39423] ForwardModeThunk
       @ ~/.julia/packages/Enzyme/wR2t7/src/compiler.jl:5001 [inlined]
 [39424] autodiff(::ForwardMode{FFIABI}, f::Const{typeof(g)}, ::Type{Duplicated}, args::Duplicated{Float64})
       @ Enzyme ~/.julia/packages/Enzyme/wR2t7/src/Enzyme.jl:324
 [39425] autodiff(::ForwardMode{FFIABI}, ::typeof(g), ::Type, ::Duplicated{Float64})
       @ Enzyme ~/.julia/packages/Enzyme/wR2t7/src/Enzyme.jl:224
Some type information was truncated. Use `show(err)` to see complete types.
@gdalle
Copy link
Contributor Author

gdalle commented Mar 6, 2024

@adrhill this makes our tests fail

@wsmoses
Copy link
Member

wsmoses commented Mar 6, 2024

Duplicate of #1134

Unfortunately this is introduced in Julia 1.10 by JuliaSparse/SparseArrays.jl@c402d09. In interim the recommendation is to not use hvcat (which unfortunately can be generated by type unstable matrix syntax). If you have time a custom rule for hvcat to work around this in the interim would be appreciated (or poking SparseArrays to revert/fix)

@wsmoses
Copy link
Member

wsmoses commented Mar 6, 2024

Closing as duplicate

@wsmoses wsmoses closed this as not planned Won't fix, can't repro, duplicate, stale Mar 6, 2024
@gdalle
Copy link
Contributor Author

gdalle commented Mar 6, 2024

Sorry what is this a duplicate of? You linked to the present issue

@wsmoses
Copy link
Member

wsmoses commented Mar 6, 2024

Oh whoops, edited comment above.

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