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

error in summation of product iterator #1490

Closed
lxvm opened this issue Jan 2, 2024 · 2 comments
Closed

error in summation of product iterator #1490

lxvm opened this issue Jan 2, 2024 · 2 comments

Comments

@lxvm
Copy link
Contributor

lxvm commented Jan 2, 2024

Hi,

I've been working on #1489 and I can't figure out where the following code breaks

using Zygote, Test
@test Zygote.gradient(p -> sum(prod(x) for x in Iterators.product(p, 1:3)), fill(1.0)) == (fill(6.0),)
Stacktrace
Error During Test at REPL[20]:1
  Test threw exception
  Expression: Zygote.gradient((p->begin
            #= REPL[20]:1 =#
            sum((prod(x) for x = Iterators.product(p, 1:3)))
        end), fill(1.0))
  MethodError: no method matching +(::Float64, ::Array{Float64, 0})
  For element-wise addition, use broadcasting with dot syntax: scalar .+ array
  
  Closest candidates are:
    +(::Any, ::Any, ::Any, ::Any...)
     @ Base operators.jl:587
    +(::ChainRulesCore.NotImplemented, ::Any)
     @ ChainRulesCore ~/.julia/packages/ChainRulesCore/zoCjl/src/tangent_arithmetic.jl:24
    +(::Any, ::ChainRulesCore.NotImplemented)
     @ ChainRulesCore ~/.julia/packages/ChainRulesCore/zoCjl/src/tangent_arithmetic.jl:25
    ...
  
  Stacktrace:
    [1] accum(x::Float64, y::Array{Float64, 0})
      @ Zygote ~/.julia/dev/Zygote/src/lib/lib.jl:17
    [2] map
      @ ./tuple.jl:319 [inlined]
    [3] accum(x::Tuple{Float64, Nothing}, ys::Tuple{Array{Float64, 0}, Nothing})
      @ Zygote ~/.julia/dev/Zygote/src/lib/lib.jl:24
    [4] macro expansion
      @ ~/.julia/dev/Zygote/src/lib/lib.jl:27 [inlined]
    [5] accum(x::@NamedTuple{iterators::Tuple{Float64, Nothing}}, y::@NamedTuple{iterators::Tuple{Array{Float64, 0}, Nothing}})
      @ Zygote ~/.julia/dev/Zygote/src/lib/lib.jl:27
    [6] _foldl_impl
      @ ./reduce.jl:56 [inlined]
    [7] (::Zygote.Pullback{Tuple{typeof(Base._foldl_impl), Base.MappingRF{var"#120#122", Base.BottomRF{typeof(Base.add_sum)}}, Base._InitialValue, Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}}, Any})(Δ::Float64)
      @ Zygote ~/.julia/dev/Zygote/src/compiler/interface2.jl:0
    [8] foldl_impl
      @ ./reduce.jl:48 [inlined]
    [9] (::Zygote.Pullback{Tuple{typeof(Base.foldl_impl), Base.MappingRF{var"#120#122", Base.BottomRF{typeof(Base.add_sum)}}, Base._InitialValue, Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}}, Any})(Δ::Float64)
      @ Zygote ~/.julia/dev/Zygote/src/compiler/interface2.jl:0
   [10] mapfoldl_impl
      @ ./reduce.jl:44 [inlined]
   [11] (::Zygote.Pullback{Tuple{typeof(Base.mapfoldl_impl), typeof(identity), typeof(Base.add_sum), Base._InitialValue, Base.Generator{Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}, var"#120#122"}}, Tuple{Zygote.var"#back#245"{Zygote.var"#2029#back#213"{Zygote.var"#back#211"{2, 1, Zygote.Context{false}, Base.MappingRF{var"#120#122", Base.BottomRF{typeof(Base.add_sum)}}}}}, Zygote.Pullback{Tuple{typeof(Base._xfadjoint), Base.BottomRF{typeof(Base.add_sum)}, Base.Generator{Base.Generator{Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}, var"#120#122"}, typeof(identity)}}, Tuple{Zygote.var"#2013#back#204"{typeof(identity)}, Zygote.var"#back#246"{Zygote.var"#2029#back#213"{Zygote.var"#back#211"{2, 2, Zygote.Context{false}, ComposedFunction{typeof(identity), Base.Fix1{Type{Base.MappingRF}, var"#120#122"}}}}}, Zygote.var"#back#245"{Zygote.var"#2029#back#213"{Zygote.var"#back#211"{2, 1, Zygote.Context{false}, Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}}}}, Zygote.var"#2029#back#213"{Zygote.var"#back#211"{2, 1, Zygote.Context{false}, Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}}}, Zygote.Pullback{Tuple{typeof(Base._xfadjoint_unwrap), Base.Generator{Base.Generator{Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}, var"#120#122"}, typeof(identity)}}, Any}, Zygote.var"#2029#back#213"{Zygote.var"#back#211"{2, 2, Zygote.Context{false}, Int64}}, Zygote.var"#2029#back#213"{Zygote.var"#back#211"{2, 1, Zygote.Context{false}, ComposedFunction{typeof(identity), Base.Fix1{Type{Base.MappingRF}, var"#120#122"}}}}, Zygote.Pullback{Tuple{ComposedFunction{typeof(identity), Base.Fix1{Type{Base.MappingRF}, var"#120#122"}}, Base.BottomRF{typeof(Base.add_sum)}}, Tuple{Zygote.var"#2366#back#419"{Zygote.var"#pairs_namedtuple_pullback#418"{(), @NamedTuple{}}}, Zygote.Pullback{Tuple{Type{NamedTuple}}, Tuple{}}, Zygote.var"#2013#back#204"{typeof(identity)}, Zygote.var"#2169#back#293"{Zygote.var"#291#292"{Tuple{Tuple{Nothing, Nothing}, Tuple{Nothing}}, Zygote.Pullback{Tuple{Base.var"##_#103", @Kwargs{}, ComposedFunction{typeof(identity), Base.Fix1{Type{Base.MappingRF}, var"#120#122"}}, Base.BottomRF{typeof(Base.add_sum)}}, Tuple{Zygote.Pullback{Tuple{typeof(Base.unwrap_composed), ComposedFunction{typeof(identity), Base.Fix1{Type{Base.MappingRF}, var"#120#122"}}}, Tuple{Zygote.Pullback{Tuple{typeof(Base.unwrap_composed), typeof(identity)}, Tuple{Zygote.Pullback{Tuple{typeof(Base.maybeconstructor), typeof(identity)}, Tuple{}}, Zygote.var"#2013#back#204"{typeof(identity)}}}, Zygote.Pullback{Tuple{typeof(Base.unwrap_composed), Base.Fix1{Type{Base.MappingRF}, var"#120#122"}}, Tuple{Zygote.Pullback{Tuple{typeof(Base.maybeconstructor), Base.Fix1{Type{Base.MappingRF}, var"#120#122"}}, Tuple{}}, Zygote.var"#2013#back#204"{typeof(identity)}}}, Zygote.var"#2180#back#303"{Zygote.var"#back#302"{:inner, Zygote.Context{false}, ComposedFunction{typeof(identity), Base.Fix1{Type{Base.MappingRF}, var"#120#122"}}, Base.Fix1{Type{Base.MappingRF}, var"#120#122"}}}, Zygote.var"#2180#back#303"{Zygote.var"#back#302"{:outer, Zygote.Context{false}, ComposedFunction{typeof(identity), Base.Fix1{Type{Base.MappingRF}, var"#120#122"}}, typeof(identity)}}, Zygote.var"#2169#back#293"{Zygote.var"#291#292"{Tuple{Tuple{Nothing}, Tuple{Nothing}}, Zygote.var"#2013#back#204"{typeof(identity)}}}}}, Zygote.Pullback{Tuple{typeof(Base.call_composed), Tuple{typeof(identity), Base.Fix1{Type{Base.MappingRF}, var"#120#122"}}, Tuple{Base.BottomRF{typeof(Base.add_sum)}}, @Kwargs{}}, Tuple{Zygote.var"#2141#back#281"{Zygote.var"#277#280"}, Zygote.Pullback{Tuple{typeof(Base.call_composed), Tuple{Base.Fix1{Type{Base.MappingRF}, var"#120#122"}}, Tuple{Base.BottomRF{typeof(Base.add_sum)}}, @Kwargs{}}, Any}, Zygote.var"#2029#back#213"{Zygote.var"#back#211"{2, 1, Zygote.Context{false}, typeof(identity)}}, Zygote.ZBack{ChainRules.var"#identity_pullback#1219"}}}}}}}}}}}, Zygote.Pullback{Tuple{Type{Base.BottomRF}, typeof(Base.add_sum)}, Tuple{Zygote.var"#2210#back#313"{Zygote.Jnew{Base.BottomRF{typeof(Base.add_sum)}, Nothing, false}}}}, Zygote.Pullback{Tuple{typeof(Base.foldl_impl), Base.MappingRF{var"#120#122", Base.BottomRF{typeof(Base.add_sum)}}, Base._InitialValue, Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}}, Any}, Zygote.var"#back#246"{Zygote.var"#2029#back#213"{Zygote.var"#back#211"{2, 2, Zygote.Context{false}, Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}}}}, Zygote.var"#2029#back#213"{Zygote.var"#back#211"{2, 1, Zygote.Context{false}, Base.MappingRF{var"#120#122", Base.BottomRF{typeof(Base.add_sum)}}}}, Zygote.Pullback{Tuple{Type{Base.Generator}, typeof(identity), Base.Generator{Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}, var"#120#122"}}, Tuple{Zygote.var"#2210#back#313"{Zygote.Jnew{Base.Generator{Base.Generator{Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}, var"#120#122"}, typeof(identity)}, Nothing, false}}}}, Zygote.var"#2029#back#213"{Zygote.var"#back#211"{2, 1, Zygote.Context{false}, Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}}}, Zygote.var"#2029#back#213"{Zygote.var"#back#211"{2, 2, Zygote.Context{false}, Int64}}}})(Δ::Float64)
      @ Zygote ~/.julia/dev/Zygote/src/compiler/interface2.jl:0
   [12] mapfoldl
      @ ./reduce.jl:175 [inlined]
   [13] (::Zygote.Pullback{Tuple{typeof(mapfoldl), typeof(identity), typeof(Base.add_sum), Base.Generator{Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}, var"#120#122"}}, Tuple{Zygote.Pullback{Tuple{Type{Base._InitialValue}}, Tuple{}}, Zygote.Pullback{Tuple{Base.var"##mapfoldl#298", Base._InitialValue, typeof(mapfoldl), typeof(identity), typeof(Base.add_sum), Base.Generator{Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}, var"#120#122"}}, Tuple{Zygote.Pullback{Tuple{typeof(Base.mapfoldl_impl), typeof(identity), typeof(Base.add_sum), Base._InitialValue, Base.Generator{Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}, var"#120#122"}}, Tuple{Zygote.var"#back#245"{Zygote.var"#2029#back#213"{Zygote.var"#back#211"{2, 1, Zygote.Context{false}, Base.MappingRF{var"#120#122", Base.BottomRF{typeof(Base.add_sum)}}}}}, Zygote.Pullback{Tuple{typeof(Base._xfadjoint), Base.BottomRF{typeof(Base.add_sum)}, Base.Generator{Base.Generator{Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}, var"#120#122"}, typeof(identity)}}, Tuple{Zygote.var"#2013#back#204"{typeof(identity)}, Zygote.var"#back#246"{Zygote.var"#2029#back#213"{Zygote.var"#back#211"{2, 2, Zygote.Context{false}, ComposedFunction{typeof(identity), Base.Fix1{Type{Base.MappingRF}, var"#120#122"}}}}}, Zygote.var"#back#245"{Zygote.var"#2029#back#213"{Zygote.var"#back#211"{2, 1, Zygote.Context{false}, Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}}}}, Zygote.var"#2029#back#213"{Zygote.var"#back#211"{2, 1, Zygote.Context{false}, Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}}}, Zygote.Pullback{Tuple{typeof(Base._xfadjoint_unwrap), Base.Generator{Base.Generator{Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}, var"#120#122"}, typeof(identity)}}, Any}, Zygote.var"#2029#back#213"{Zygote.var"#back#211"{2, 2, Zygote.Context{false}, Int64}}, Zygote.var"#2029#back#213"{Zygote.var"#back#211"{2, 1, Zygote.Context{false}, ComposedFunction{typeof(identity), Base.Fix1{Type{Base.MappingRF}, var"#120#122"}}}}, Zygote.Pullback{Tuple{ComposedFunction{typeof(identity), Base.Fix1{Type{Base.MappingRF}, var"#120#122"}}, Base.BottomRF{typeof(Base.add_sum)}}, Tuple{Zygote.var"#2366#back#419"{Zygote.var"#pairs_namedtuple_pullback#418"{(), @NamedTuple{}}}, Zygote.Pullback{Tuple{Type{NamedTuple}}, Tuple{}}, Zygote.var"#2013#back#204"{typeof(identity)}, Zygote.var"#2169#back#293"{Zygote.var"#291#292"{Tuple{Tuple{Nothing, Nothing}, Tuple{Nothing}}, Zygote.Pullback{Tuple{Base.var"##_#103", @Kwargs{}, ComposedFunction{typeof(identity), Base.Fix1{Type{Base.MappingRF}, var"#120#122"}}, Base.BottomRF{typeof(Base.add_sum)}}, Tuple{Zygote.Pullback{Tuple{typeof(Base.unwrap_composed), ComposedFunction{typeof(identity), Base.Fix1{Type{Base.MappingRF}, var"#120#122"}}}, Tuple{Zygote.Pullback{Tuple{typeof(Base.unwrap_composed), typeof(identity)}, Tuple{Zygote.Pullback{Tuple{typeof(Base.maybeconstructor), typeof(identity)}, Tuple{}}, Zygote.var"#2013#back#204"{typeof(identity)}}}, Zygote.Pullback{Tuple{typeof(Base.unwrap_composed), Base.Fix1{Type{Base.MappingRF}, var"#120#122"}}, Tuple{Zygote.Pullback{Tuple{typeof(Base.maybeconstructor), Base.Fix1{Type{Base.MappingRF}, var"#120#122"}}, Tuple{}}, Zygote.var"#2013#back#204"{typeof(identity)}}}, Zygote.var"#2180#back#303"{Zygote.var"#back#302"{:inner, Zygote.Context{false}, ComposedFunction{typeof(identity), Base.Fix1{Type{Base.MappingRF}, var"#120#122"}}, Base.Fix1{Type{Base.MappingRF}, var"#120#122"}}}, Zygote.var"#2180#back#303"{Zygote.var"#back#302"{:outer, Zygote.Context{false}, ComposedFunction{typeof(identity), Base.Fix1{Type{Base.MappingRF}, var"#120#122"}}, typeof(identity)}}, Zygote.var"#2169#back#293"{Zygote.var"#291#292"{Tuple{Tuple{Nothing}, Tuple{Nothing}}, Zygote.var"#2013#back#204"{typeof(identity)}}}}}, Zygote.Pullback{Tuple{typeof(Base.call_composed), Tuple{typeof(identity), Base.Fix1{Type{Base.MappingRF}, var"#120#122"}}, Tuple{Base.BottomRF{typeof(Base.add_sum)}}, @Kwargs{}}, Tuple{Zygote.var"#2141#back#281"{Zygote.var"#277#280"}, Zygote.Pullback{Tuple{typeof(Base.call_composed), Tuple{Base.Fix1{Type{Base.MappingRF}, var"#120#122"}}, Tuple{Base.BottomRF{typeof(Base.add_sum)}}, @Kwargs{}}, Any}, Zygote.var"#2029#back#213"{Zygote.var"#back#211"{2, 1, Zygote.Context{false}, typeof(identity)}}, Zygote.ZBack{ChainRules.var"#identity_pullback#1219"}}}}}}}}}}}, Zygote.Pullback{Tuple{Type{Base.BottomRF}, typeof(Base.add_sum)}, Tuple{Zygote.var"#2210#back#313"{Zygote.Jnew{Base.BottomRF{typeof(Base.add_sum)}, Nothing, false}}}}, Zygote.Pullback{Tuple{typeof(Base.foldl_impl), Base.MappingRF{var"#120#122", Base.BottomRF{typeof(Base.add_sum)}}, Base._InitialValue, Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}}, Any}, Zygote.var"#back#246"{Zygote.var"#2029#back#213"{Zygote.var"#back#211"{2, 2, Zygote.Context{false}, Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}}}}, Zygote.var"#2029#back#213"{Zygote.var"#back#211"{2, 1, Zygote.Context{false}, Base.MappingRF{var"#120#122", Base.BottomRF{typeof(Base.add_sum)}}}}, Zygote.Pullback{Tuple{Type{Base.Generator}, typeof(identity), Base.Generator{Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}, var"#120#122"}}, Tuple{Zygote.var"#2210#back#313"{Zygote.Jnew{Base.Generator{Base.Generator{Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}, var"#120#122"}, typeof(identity)}, Nothing, false}}}}, Zygote.var"#2029#back#213"{Zygote.var"#back#211"{2, 1, Zygote.Context{false}, Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}}}, Zygote.var"#2029#back#213"{Zygote.var"#back#211"{2, 2, Zygote.Context{false}, Int64}}}}}}}})(Δ::Float64)
      @ Zygote ~/.julia/dev/Zygote/src/compiler/interface2.jl:0
   [14] #mapreduce#302
      @ ./reduce.jl:307 [inlined]
   [15] (::Zygote.Pullback{Tuple{Base.var"##mapreduce#302", @Kwargs{}, typeof(mapreduce), typeof(identity), typeof(Base.add_sum), Base.Generator{Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}, var"#120#122"}}, Any})(Δ::Float64)
      @ Zygote ~/.julia/dev/Zygote/src/compiler/interface2.jl:0
   [16] mapreduce
      @ ./reduce.jl:307 [inlined]
   [17] (::Zygote.Pullback{Tuple{typeof(mapreduce), typeof(identity), typeof(Base.add_sum), Base.Generator{Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}, var"#120#122"}}, Tuple{Zygote.Pullback{Tuple{Base.var"##mapreduce#302", @Kwargs{}, typeof(mapreduce), typeof(identity), typeof(Base.add_sum), Base.Generator{Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}, var"#120#122"}}, Any}, Zygote.Pullback{Tuple{Type{NamedTuple}}, Tuple{}}, Zygote.var"#2366#back#419"{Zygote.var"#pairs_namedtuple_pullback#418"{(), @NamedTuple{}}}}})(Δ::Float64)
      @ Zygote ~/.julia/dev/Zygote/src/compiler/interface2.jl:0
   [18] #sum#305
      @ ./reduce.jl:535 [inlined]
   [19] (::Zygote.Pullback{Tuple{Base.var"##sum#305", @Kwargs{}, typeof(sum), typeof(identity), Base.Generator{Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}, var"#120#122"}}, Any})(Δ::Float64)
      @ Zygote ~/.julia/dev/Zygote/src/compiler/interface2.jl:0
   [20] sum
      @ ./reduce.jl:535 [inlined]
   [21] (::Zygote.Pullback{Tuple{typeof(sum), typeof(identity), Base.Generator{Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}, var"#120#122"}}, Tuple{Zygote.var"#2366#back#419"{Zygote.var"#pairs_namedtuple_pullback#418"{(), @NamedTuple{}}}, Zygote.Pullback{Tuple{Type{NamedTuple}}, Tuple{}}, Zygote.Pullback{Tuple{Base.var"##sum#305", @Kwargs{}, typeof(sum), typeof(identity), Base.Generator{Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}, var"#120#122"}}, Any}}})(Δ::Float64)
      @ Zygote ~/.julia/dev/Zygote/src/compiler/interface2.jl:0
   [22] #sum#306
      @ ./reduce.jl:564 [inlined]
   [23] (::Zygote.Pullback{Tuple{Base.var"##sum#306", @Kwargs{}, typeof(sum), Base.Generator{Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}, var"#120#122"}}, Any})(Δ::Float64)
      @ Zygote ~/.julia/dev/Zygote/src/compiler/interface2.jl:0
   [24] sum
      @ ./reduce.jl:564 [inlined]
   [25] (::Zygote.Pullback{Tuple{typeof(sum), Base.Generator{Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}, var"#120#122"}}, Tuple{Zygote.Pullback{Tuple{Base.var"##sum#306", @Kwargs{}, typeof(sum), Base.Generator{Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}, var"#120#122"}}, Any}, Zygote.Pullback{Tuple{Type{NamedTuple}}, Tuple{}}, Zygote.var"#2366#back#419"{Zygote.var"#pairs_namedtuple_pullback#418"{(), @NamedTuple{}}}}})(Δ::Float64)
      @ Zygote ~/.julia/dev/Zygote/src/compiler/interface2.jl:0
   [26] #119
      @ ./REPL[20]:1 [inlined]
   [27] (::Zygote.Pullback{Tuple{var"#119#121", Array{Float64, 0}}, Tuple{Zygote.ZBack{ChainRules.var"#:_pullback#276"{Tuple{Int64, Int64}}}, Zygote.Pullback{Tuple{typeof(sum), Base.Generator{Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}, var"#120#122"}}, Tuple{Zygote.Pullback{Tuple{Base.var"##sum#306", @Kwargs{}, typeof(sum), Base.Generator{Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}, var"#120#122"}}, Any}, Zygote.Pullback{Tuple{Type{NamedTuple}}, Tuple{}}, Zygote.var"#2366#back#419"{Zygote.var"#pairs_namedtuple_pullback#418"{(), @NamedTuple{}}}}}, Zygote.var"#1434#back#2380"{Zygote.var"#back#2377"{Tuple{Array{Float64, 0}, UnitRange{Int64}}}}, Zygote.var"#2210#back#313"{Zygote.Jnew{var"#120#122", Nothing, false}}, Zygote.Pullback{Tuple{Type{Base.Generator}, var"#120#122", Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}}, Tuple{Zygote.var"#2210#back#313"{Zygote.Jnew{Base.Generator{Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}, var"#120#122"}, Nothing, false}}}}}})(Δ::Float64)
      @ Zygote ~/.julia/dev/Zygote/src/compiler/interface2.jl:0
   [28] (::Zygote.var"#75#76"{Zygote.Pullback{Tuple{var"#119#121", Array{Float64, 0}}, Tuple{Zygote.ZBack{ChainRules.var"#:_pullback#276"{Tuple{Int64, Int64}}}, Zygote.Pullback{Tuple{typeof(sum), Base.Generator{Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}, var"#120#122"}}, Tuple{Zygote.Pullback{Tuple{Base.var"##sum#306", @Kwargs{}, typeof(sum), Base.Generator{Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}, var"#120#122"}}, Any}, Zygote.Pullback{Tuple{Type{NamedTuple}}, Tuple{}}, Zygote.var"#2366#back#419"{Zygote.var"#pairs_namedtuple_pullback#418"{(), @NamedTuple{}}}}}, Zygote.var"#1434#back#2380"{Zygote.var"#back#2377"{Tuple{Array{Float64, 0}, UnitRange{Int64}}}}, Zygote.var"#2210#back#313"{Zygote.Jnew{var"#120#122", Nothing, false}}, Zygote.Pullback{Tuple{Type{Base.Generator}, var"#120#122", Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}}, Tuple{Zygote.var"#2210#back#313"{Zygote.Jnew{Base.Generator{Base.Iterators.ProductIterator{Tuple{Array{Float64, 0}, UnitRange{Int64}}}, var"#120#122"}, Nothing, false}}}}}}})(Δ::Float64)
      @ Zygote ~/.julia/dev/Zygote/src/compiler/interface.jl:45
   [29] gradient(f::Function, args::Array{Float64, 0})
      @ Zygote ~/.julia/dev/Zygote/src/compiler/interface.jl:97
   [30] macro expansion
      @ REPL[20]:1 [inlined]
   [31] macro expansion
      @ /local/home/lxvm/.julia/juliaup/julia-1.10.0+0.x64.linux.gnu/share/julia/stdlib/v1.10/Test/src/Test.jl:669 [inlined]
   [32] top-level scope
      @ REPL[20]:1
ERROR: There was an error during testing

In particular I don't know where Zygote generates an adjoint for the `mapreduce` machinery, since there is no custom adjoint, and where it calls `accum` and would appreciate help finding out where.

However, all of the following work on my pr branch, so there is something strange about using a range / generic iterator with shape in the MWE

Zygote.gradient(p -> sum(prod(x) for x in Iterators.product(p, p)), fill(1.0))
Zygote.gradient(p -> sum(prod(x) for x in Iterators.product(p, 1.0)), fill(1.0))
Zygote.gradient(p -> sum(prod(x) for x in Iterators.product(p, [1.0])), fill(1.0))

I know that Zygote performs better with arrays than iterators, since iterators can contain arbitrary code and are hard to optimize, but I would like to try helping make the generic code work.

@lxvm
Copy link
Contributor Author

lxvm commented Jan 3, 2024

Aha, it's probably because of the following definition of accum, which is reminiscent of the behavior of an old Julia bug. This is fixed by #1489 and #1491 together and I will keep the issue open until those are resolved.

@lxvm
Copy link
Contributor Author

lxvm commented Jan 19, 2024

Closed by #1489 and #1491

@lxvm lxvm closed this as completed Jan 19, 2024
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

1 participant