-
-
Notifications
You must be signed in to change notification settings - Fork 211
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
Error during gradient calculation #399
Error during gradient calculation #399
Comments
I'm willing to try to work on a PR that fixes this if someone can explain what is the problem here. |
Hi @AzamatB , The reason is that the To make your example work. You can remove the type constraint in the |
Hi @findmyway thank you for pointing out the reason for the error! This is very helpful! Would replacing this method definition with something like accum(x::Union{Tuple,AbstractVector}, y::Union{Tuple,AbstractVector}) = accum.(x, y) solve the issue here then? |
I guess so. But I'm not sure is there any side effect. |
Looks like the line h = first(hs)
Hsbuffer = Buffer(h, size(h,1), size(h,2), length(hs))
for k ∈ eachindex(hs)
Hsbuffer[:,:,k] = hs[k]
end
Hs = copy(Hsbuffer) works around this issue. |
Took me a while to hunt it down, but here is the minimum reproducible example: using Zygote
julia> gradient(x -> sum(hcat(x...) * sum(x)), [rand(4,2), rand(4,2)])
ERROR: MethodError: no method matching +(::FillArrays.Fill{Array{Float64,2},1,Tuple{Base.OneTo{Int64}}}, ::Tuple{Array{Float64,2},Array{Float64,2}}) |
Further reduced to: using Zygote
julia> gradient(x -> sum(hcat(x...) * sum(x)), [rand(2), rand(2)])
ERROR: MethodError: no method matching +(::FillArrays.Fill{Array{Float64,1},1,Tuple{Base.OneTo{Int64}}}, ::Tuple{Array{Float64,1},Array{Float64,1}}) |
Further reduced to: using Zygote
julia> gradient(x -> vcat(x...)'x, rand(2))
ERROR: MethodError: no method matching +(::Array{Float64,1}, ::Tuple{Float64,Float64}) |
Any ideas on what is the problem here now? Happy to prepare PR fixing this, if I get an understanding of the underlying issue. |
Pasting @mohamed82008's comment from slack:
While julia> gradient(x -> sum(x), rand(2))
([1.0, 1.0],) returns a vector. The first one should return a vector too. |
Great to fix the splat bug. Here's another possible solution to the using LazyStack
function f(xs::AbstractVector{<:AbstractMatrix})
hs = m.listen.(xs)
Hs = stack(hs)
ψHs = m.attention_ψ.(hs)
... |
Closing this in favor of #599. |
I'm getting an error during gradient calculation and don't understand what is causing it.
My actual code, where this happens is quite large, but I was able to reduce it to the following MRE:
the error message I get is:
while
f(xs)
works.I tried to reduce the example further, but the error starts to evade.
The text was updated successfully, but these errors were encountered: