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

Zygote derivative wrt chain input x returns StackOverflowError #108

Open
axsk opened this issue Sep 23, 2022 · 2 comments
Open

Zygote derivative wrt chain input x returns StackOverflowError #108

axsk opened this issue Sep 23, 2022 · 2 comments

Comments

@axsk
Copy link

axsk commented Sep 23, 2022

using SimpleChains, Zygote
sc = SimpleChain(
                static(2),
                Activation(x -> x.^3),
                TurboDense{true}(tanh, static(50)),
                TurboDense{true}(identity, static(2))
            )

p_nn = SimpleChains.init_params(sc)

Zygote.gradient([2.,2.]) do x 
    sc(x, p_nn) |> sum
end

returns

ERROR: StackOverflowError:
Stacktrace:
 [1] pullback!(pg::Ptr{Float32}, td::TurboDense{true, Static.StaticInt{2}, typeof(identity)}, C̄::FillArrays.Fill{Float32, 1, Tuple{Base.OneTo{Int64}}}, B::StrideArraysCore.PtrArray{Tuple{Static.StaticInt{50}}, (true,), Float32, 1, 1, 0, (1,), Tuple{Static.StaticInt{4}}, Tuple{Static.StaticInt{1}}}, p::Ptr{Float32}, pu::Ptr{UInt8}, pu2::Ptr{UInt8}) (repeats 79984 times)
   @ SimpleChains ~/.julia/packages/SimpleChains/HhLUa/src/dense.jl:904

using Julia 1.8.1 and SimpleChains 0.3.1

@axsk
Copy link
Author

axsk commented Sep 26, 2022

The problem seems to be with sum and not the derivative wrt. x

sum(abs2, sc(x, p_nn) instead of the simple sum works

However exchanging the gradient to be wrt. the parameters leads to the same StackOverflow

Zygote.gradient(p_nn) do p 
    sum(sc(rand(2), p))
end

@chriselrod
Copy link
Contributor

The solution here will be to add a few methods that support Fill arrays.

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