Open CarloLucibello opened 3 years ago
Likely comes from not using the fill
different error with repeat
julia> f(x) = reshape(x, repeat([2], 2)...)
f (generic function with 1 method)
julia> gradient(x->sum(f(x)), rand(4))
ERROR: MethodError: no method matching reshape(::Tuple{Nothing,Nothing}, ::Int64, ::Colon)
Closest candidates are:
reshape(::FillArrays.AbstractFill, ::Union{Colon, Int64}...) at /home/carlo/.julia/packages/FillArrays/gPRiS/src/FillArrays.jl:211
reshape(::AbstractArray, ::Union{Colon, Int64}...) at reshapedarray.jl:117
reshape(::FillArrays.AbstractFill, ::Union{Colon, Integer}...) at /home/carlo/.julia/packages/FillArrays/gPRiS/src/FillArrays.jl:212
...
Stacktrace:
[1] (::Zygote.var"#491#492"{Array{Int64,1}})(::Tuple{Nothing,Nothing}) at /home/carlo/.julia/dev/Zygote/src/lib/array.jl:146
[2] (::Zygote.var"#2515#back#493"{Zygote.var"#491#492"{Array{Int64,1}}})(::Tuple{Nothing,Nothing}) at /home/carlo/.julia/packages/ZygoteRules/OjfTt/src/adjoint.jl:59
[3] f at ./REPL[8]:1 [inlined]
[4] (::typeof(∂(f)))(::FillArrays.Fill{Float64,2,Tuple{Base.OneTo{Int64},Base.OneTo{Int64}}}) at /home/carlo/.julia/dev/Zygote/src/compiler/interface2.jl:0
[5] #7 at ./REPL[9]:1 [inlined]
[6] (::typeof(∂(#7)))(::Float64) at /home/carlo/.julia/dev/Zygote/src/compiler/interface2.jl:0
[7] (::Zygote.var"#41#42"{typeof(∂(#7))})(::Float64) at /home/carlo/.julia/dev/Zygote/src/compiler/interface.jl:40
[8] gradient(::Function, ::Array{Float64,1}) at /home/carlo/.julia/dev/Zygote/src/compiler/interface.jl:49
[9] top-level scope at REPL[9]:1
[10] run_repl(::REPL.AbstractREPL, ::Any) at /build/julia/src/julia-1.5.3/usr/share/julia/stdlib/v1.5/REPL/src/REPL.jl:288
Likely comes from not using the fill
do you know any workaround?
I would check with https://github.com/FluxML/Zygote.jl/pull/846 to see if we hit the map adjoint.
The solution might be to retain some adjoints in Zygote rather than ChainRules for robustness. I am fairly sure we could handle these cases elegantly before.
Can you add these tests in a PR?
unfortunately, #846 doesn't help (tried both fill and repeat)
Can you add these tests in a PR?
a PR doing what? I wouldn't know how to fix this
That adds breaking tests. I don't want this to be missed
The example in the OP works now
julia> f(x) = reshape(x, fill(2, 2)...)
f (generic function with 1 method)
julia> gradient(x->sum(f(x)), rand(4))
(Fill(1.0, 4),)
The one in https://github.com/FluxML/Zygote.jl/issues/866#issuecomment-752969193 is still failing
While working at https://github.com/FluxML/NNlib.jl/pull/260 I hit a bug on Zygote master that I managed to reduce to the following
Notice that the equivalent is handled properly
I could not reduce it further to understand which one is the problematic ingredient