# Flux: no method matching ndims(::ChainRulesCore.NoTangent)

**URL:** <https://discourse.julialang.org/t/flux-no-method-matching-ndims-chainrulescore-notangent/71479>\
**Category:** Machine Learning\
**Tags:** flux, rnn\
**Created:** [November 15, 2021, 6:39am UTC](https://discourse.julialang.org/t/flux-no-method-matching-ndims-chainrulescore-notangent/71479 "2021-11-15T06:39:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shuhua](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shuhua/32/27618_2.png) [@Shuhua](https://discourse.julialang.org/u/Shuhua)\
**Post date:** [November 15, 2021, 6:39am UTC](https://discourse.julialang.org/t/flux-no-method-matching-ndims-chainrulescore-notangent/71479/1 "2021-11-15T06:39:55Z")

</div>

Consider the MWE below.

```julia
using Flux 

model = Chain(
    RNN(1, 128),
    Dense(128, 1)
);

# one feature, sequence length = 3, batch size = 6
x = [rand(Float32, 1, 6) for _ = 1:3]
y = rand(Float32, 1, 6)

function loss(x, y)
    Flux.reset!(model)
    # xi is the input at one step
    # many-to-one: we only care about the last output
    ŷ = [model(xi) for xi in x][end]
    return Flux.mse(ŷ, y)
end

# compute the gradient corresponding to (x, y)
ps = Flux.params(model)
gs = gradient(ps) do
    loss(x, y)
end

```

The above `gradient` line causes the following error:

```julia
MethodError: no method matching ndims(::ChainRulesCore.NoTangent)
Closest candidates are:
  ndims(::CUDA.CUSPARSE.CuSparseMatrix{Tv, Ti} where {Tv, Ti}) at /home/shuhua/.julia/packages/CUDA/YpW0k/lib/cusparse/array.jl:204
  ndims(::CUDA.CuSparseDeviceVector) at /home/shuhua/.julia/packages/CUDA/YpW0k/src/device/sparse.jl:23
  ndims(::AbstractChar) at char.jl:191
  ...

```

---

<div class="post-metadata">

**Author:** ![Shuhua](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shuhua/32/27618_2.png) [@Shuhua](https://discourse.julialang.org/u/Shuhua)\
**Post date:** [November 16, 2021, 2:05am UTC](https://discourse.julialang.org/t/flux-no-method-matching-ndims-chainrulescore-notangent/71479/2 "2021-11-16T02:05:22Z")

</div>

The weird behaviour disappears and everything works after I update Flux from `v0.12.7` to `v0.12.8`. 😂

---

<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:** [November 16, 2021, 5:01pm UTC](https://discourse.julialang.org/t/flux-no-method-matching-ndims-chainrulescore-notangent/71479/3 "2021-11-16T17:01:17Z")

</div>

Not much changed in Flux for that point release, so most likely a change in Zygote or ChainRules(Core) that also updated when you ran `] up` fixed things.

---

<div class="post-metadata">

**Author:** ![Shuhua](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shuhua/32/27618_2.png) [@Shuhua](https://discourse.julialang.org/u/Shuhua)\
**Post date:** [November 17, 2021, 2:06am UTC](https://discourse.julialang.org/t/flux-no-method-matching-ndims-chainrulescore-notangent/71479/4 "2021-11-17T02:06:49Z")

</div>

Yes 😃. It is probably due to the update of `ChainRulesCore`: its recent releases are mostly concerned with the `Tangent` stuff.
