Closed AzamatB closed 4 years ago
Looks like this has to do with broadcating as replacing
restack(xs) = vcat.(xs[1:2:end], xs[2:2:end])
with
restack(xs) = [vcat(xs[i-1], xs[i]) for i ∈ 2:2:lastindex(xs)]
works around this issue
exact same problem, same workaround
#pepsline = peps[i,:] # doesn't work
T = typeof(peps[1,1])
pepsline = Zygote.Buffer(T[])
for t = 1:size(peps,2)
push!(pepsline,peps[i,t])
end
Here is the MRE:
using Zygote
vs = [rand(2,3) for _ ∈ 1:4]
julia> gradient(xs -> sum(sum(vcat.(xs[1:2:end], xs[2:2:end]))), vs)
ERROR: MethodError: no method matching +(::Nothing, ::Array{Float64,2})
Can someone advise what is the problem here?
Further reduced to:
using Zygote
julia> gradient(xs -> sum(sum(vcat.(xs[:], xs))), [rand(2), rand(2)])
ERROR: MethodError: no method matching +(::Nothing, ::FillArrays.Fill{Float64,1,Tuple{Base.OneTo{Int64}}})
Looks like a bug in the custom adjoint for sum, I haven’t looked at the code, but from my logic.
This would not happen if Zygote was using ChainRules.jl’s differential types.
Since it would use Zero()
rather than nothing
and `Zero has + defined on it.
But right now that custom adjoint need to be written to know some args might be nothing
(which represents strong zero).
This issue is affecting me gravely. Any suggestions on how to fix it?
Type pirate +(:: Nothing, x) = x
+(x, :: Nothing) = x
and +(:: Nothing, ::Nothing) = nothing
I've been hitting this also, and @oxinabox's type piracy hack is working for now. Thanks.
Seems fixed on master, so will close.
I'm trying to implement pyramidal BLSTM in Flux with Zygote backend and getting an error I cannot comprehend. Here is MWE:
where the call to
gradient
at the end throws:Any advice on what is the problem here and how to fix it? I'm happy to prepare PR fixing it