# Help me pin this bug in \`Flux\`…

**URL:** <https://discourse.julialang.org/t/help-me-pin-this-bug-in-flux/81901>\
**Category:** Machine Learning\
**Tags:** bug, error, flux, zygote, autodiff\
**Created:** [May 30, 2022, 6:33am UTC](https://discourse.julialang.org/t/help-me-pin-this-bug-in-flux/81901 "2022-05-30T06:33:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jollywatt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jollywatt/32/202198_2.png) [@Jollywatt](https://discourse.julialang.org/u/Jollywatt)\
**Post date:** [May 30, 2022, 6:33am UTC](https://discourse.julialang.org/t/help-me-pin-this-bug-in-flux/81901/1 "2022-05-30T06:33:10Z")

</div>

On Julia 1.6.5 and 1.7.2, the following code gives a method error:

```julia
using Flux # v0.13.0

x = Flux.onehotbatch([1, 2], 0:9)
# x = float.(x) ###

model = zeros()
Flux.gradient(Flux.params(model)) do
	y = x
	y = reshape(y, 1, 1, :) ###
	y = repeat(y, 1) ###
	sum(y)
end

```

This seems to arise only when _all_ of these three conditions are satisfied:

- `x isa OneHotMatrix`
- the line `y = reshape(y, 1, 1, :)` is present
- the line `y = repeat(y, 1)` is present

If any of the lines marked with `###` are commented out (or in the case of the first, uncommented), then the gradient is computed without an error.

Have I found a bug? I’m a newbie so don’t know whether this should be reported to `Flux.jl` or `Zygote.jl`, etc…

---

<div class="post-metadata">

**Author:** ![albheim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albheim/32/34660_2.png) [@albheim](https://discourse.julialang.org/u/albheim)\
**Post date:** [May 30, 2022, 7:12am UTC](https://discourse.julialang.org/t/help-me-pin-this-bug-in-flux/81901/2 "2022-05-30T07:12:03Z")

</div>

Seems like a problem in Zygote to me, I would report it there to start with at least. Here is the stacktrace for anyone interested

```julia
julia> Flux.gradient(Flux.params(model)) do
               y = x
               y = reshape(y, 1, 1, :) ###
               y = repeat(y, 1) ###
               sum(y)
       end
ERROR: type Nothing has no field method
Stacktrace:
  [1] getproperty
    @ ./Base.jl:42 [inlined]
  [2] matching_cr_sig(t::IRTools.Inner.Meta, s::Nothing)
    @ Zygote ~/.julia/packages/Zygote/DkIUK/src/compiler/chainrules.jl:72
  [3] has_chain_rrule(T::Type)
    @ Zygote ~/.julia/packages/Zygote/DkIUK/src/compiler/chainrules.jl:54
  [4] #s3043#1205
    @ ~/.julia/packages/Zygote/DkIUK/src/compiler/interface2.jl:20 [inlined]
  [5] var"#s3043#1205"(::Any, ctx::Any, f::Any, args::Any)
    @ Zygote ./none:0
  [6] (::Core.GeneratedFunctionStub)(::Any, ::Vararg{Any})
    @ Core ./boot.jl:580
  [7] _pullback
    @ ./REPL[36]:4 [inlined]
  [8] _pullback(::Zygote.Context, ::var"#29#30")
    @ Zygote ~/.julia/packages/Zygote/DkIUK/src/compiler/interface2.jl:0
  [9] pullback(f::Function, ps::Params{Zygote.Buffer{Any, Vector{Any}}})
    @ Zygote ~/.julia/packages/Zygote/DkIUK/src/compiler/interface.jl:352
 [10] gradient(f::Function, args::Params{Zygote.Buffer{Any, Vector{Any}}})
    @ Zygote ~/.julia/packages/Zygote/DkIUK/src/compiler/interface.jl:75
 [11] top-level scope
    @ REPL[36]:1
 [12] macro expansion
    @ ~/.julia/packages/Infiltrator/6XXoh/src/Infiltrator.jl:616 [inlined]
 [13] top-level scope
    @ ~/.julia/packages/CUDA/GGwVa/src/initialization.jl:52

```

---

<div class="post-metadata">

**Author:** ![ToucheSir](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/touchesir/32/14411_2.png) [@ToucheSir](https://discourse.julialang.org/u/ToucheSir)\
**Post date:** [May 31, 2022, 10:34pm UTC](https://discourse.julialang.org/t/help-me-pin-this-bug-in-flux/81901/3 "2022-05-31T22:34:15Z")

</div>

Yes, this is definitely a bug so please file an issue.
