# Flux RNN training giving \`BoundsError\`

**URL:** <https://discourse.julialang.org/t/flux-rnn-training-giving-boundserror/90723>\
**Category:** Machine Learning\
**Tags:** flux\
**Created:** [November 23, 2022, 5:29pm UTC](https://discourse.julialang.org/t/flux-rnn-training-giving-boundserror/90723 "2022-11-23T17:29:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mjyshin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mjyshin/32/26449_2.png) [@mjyshin](https://discourse.julialang.org/u/mjyshin)\
**Post date:** [November 23, 2022, 5:29pm UTC](https://discourse.julialang.org/t/flux-rnn-training-giving-boundserror/90723/1 "2022-11-23T17:29:22Z")

</div>

I was originally trying to train a network with recurrence using GRUs but I kept getting this `BoundsError: attempt to access Tuple{} at index [0]`. So I gave up and tried running the [`rnn-char`](https://github.com/FluxML/model-zoo/blob/master/text/char-rnn/char-rnn.jl) example in the [`model-zoo`](https://github.com/FluxML/model-zoo), with the same results (also the code in the model zoo needs to be updated with `params(m)` → `Flux.params(m)`):

```julia
[ Info: Start Training, total 2 epochs
[ Info: Epoch 1 / 2
ERROR: LoadError: BoundsError: attempt to access Tuple{} at index [0]
Stacktrace:
  [1] getindex(t::Tuple, i::Int64)
    @ Base ./tuple.jl:29
  [2] last(a::Tuple{})
    @ Base ./abstractarray.jl:479
  [3] rrule(config::Zygote.ZygoteRuleConfig{Zygote.Context{true}}, ::typeof(foldl), op::Base.var"#57#58"{typeof(Flux.reset!)}, x::Tuple{}; init::Nothing)
    @ ChainRules ~/.julia/packages/ChainRules/hVHC4/src/rulesets/Base/mapreduce.jl:448
  [4] chain_rrule_kw
    @ ~/.julia/packages/Zygote/dABKa/src/compiler/chainrules.jl:230 [inlined]
  [5] macro expansion
    @ ~/.julia/packages/Zygote/dABKa/src/compiler/interface2.jl:0 [inlined]
  [6] _pullback(::Zygote.Context{true}, ::Base.var"#foldl##kw", ::NamedTuple{(:init,), Tuple{Nothing}}, ::typeof(foldl), ::Base.var"#57#58"{typeof(Flux.reset!)}, ::Tuple{})
    @ Zygote ~/.julia/packages/Zygote/dABKa/src/compiler/interface2.jl:9
  [7] _pullback
    @ ./tuple.jl:555 [inlined]
  [8] _pullback(::Zygote.Context{true}, ::typeof(foreach), ::typeof(Flux.reset!), ::Tuple{})
    @ Zygote ~/.julia/packages/Zygote/dABKa/src/compiler/interface2.jl:0
  [9] _pullback
    @ ~/.julia/packages/Flux/FKl3M/src/layers/recurrent.jl:180 [inlined]
 [10] _pullback(ctx::Zygote.Context{true}, f::typeof(Flux.reset!), args::Matrix{Float32})
    @ Zygote ~/.julia/packages/Zygote/dABKa/src/compiler/interface2.jl:0
 [11] _pullback
    @ ./abstractarray.jl:2774 [inlined]
 [12] _pullback(::Zygote.Context{true}, ::typeof(foreach), ::typeof(Flux.reset!), ::NamedTuple{(:weight, :bias, :σ), Tuple{Matrix{Float32}, Vector{Float32}, typeof(identity)}})
    @ Zygote ~/.julia/packages/Zygote/dABKa/src/compiler/interface2.jl:0
 [13] _pullback
    @ ~/.julia/packages/Flux/FKl3M/src/layers/recurrent.jl:180 [inlined]
 [14] _pullback
    @ ./tuple.jl:555 [inlined]
 [15] #rrule_via_ad#46
    @ ~/.julia/packages/Zygote/dABKa/src/compiler/chainrules.jl:255 [inlined]
 [16] rrule_via_ad
    @ ~/.julia/packages/Zygote/dABKa/src/compiler/chainrules.jl:243 [inlined]
 [17] #1703
    @ ~/.julia/packages/ChainRules/hVHC4/src/rulesets/Base/mapreduce.jl:444 [inlined]
 [18] BottomRF
    @ ./reduce.jl:81 [inlined]
 [19] #837
    @ ./accumulate.jl:291 [inlined]
 [20] afoldl
    @ ./operators.jl:550 [inlined]
 [21] #accumulate#836
    @ ./accumulate.jl:290 [inlined]
 [22] #rrule#1702
    @ ~/.julia/packages/ChainRules/hVHC4/src/rulesets/Base/mapreduce.jl:440 [inlined]
 [23] chain_rrule_kw
    @ ~/.julia/packages/Zygote/dABKa/src/compiler/chainrules.jl:230 [inlined]
 [24] macro expansion
    @ ~/.julia/packages/Zygote/dABKa/src/compiler/interface2.jl:0 [inlined]
 [25] _pullback
    @ ~/.julia/packages/Zygote/dABKa/src/compiler/interface2.jl:9 [inlined]
 [26] _pullback
    @ ./tuple.jl:555 [inlined]
 [27] _pullback(::Zygote.Context{true}, ::typeof(foreach), ::typeof(Flux.reset!), ::Tuple{Flux.Recur{Flux.LSTMCell{Matrix{Float32}, Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Flux.Recur{Flux.LSTMCell{Matrix{Float32}, Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Dense{typeof(identity), Matrix{Float32}, Vector{Float32}}})
    @ Zygote ~/.julia/packages/Zygote/dABKa/src/compiler/interface2.jl:0
 [28] _pullback
    @ ~/.julia/packages/Flux/FKl3M/src/layers/recurrent.jl:180 [inlined]
 [29] _pullback(ctx::Zygote.Context{true}, f::typeof(Flux.reset!), args::Tuple{Flux.Recur{Flux.LSTMCell{Matrix{Float32}, Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Flux.Recur{Flux.LSTMCell{Matrix{Float32}, Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Dense{typeof(identity), Matrix{Float32}, Vector{Float32}}})
    @ Zygote ~/.julia/packages/Zygote/dABKa/src/compiler/interface2.jl:0
 [30] _pullback
    @ ./abstractarray.jl:2774 [inlined]
 [31] _pullback(::Zygote.Context{true}, ::typeof(foreach), ::typeof(Flux.reset!), ::NamedTuple{(:layers,), Tuple{Tuple{Flux.Recur{Flux.LSTMCell{Matrix{Float32}, Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Flux.Recur{Flux.LSTMCell{Matrix{Float32}, Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Dense{typeof(identity), Matrix{Float32}, Vector{Float32}}}}})
    @ Zygote ~/.julia/packages/Zygote/dABKa/src/compiler/interface2.jl:0
 [32] _pullback
    @ ~/.julia/packages/Flux/FKl3M/src/layers/recurrent.jl:180 [inlined]
 [33] _pullback
    @ ~/Projects/model-zoo/text/char-rnn/char-rnn.jl:111 [inlined]
 [34] _pullback(::Zygote.Context{true}, ::var"#loss#9"{Chain{Tuple{Flux.Recur{Flux.LSTMCell{Matrix{Float32}, Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Flux.Recur{Flux.LSTMCell{Matrix{Float32}, Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Dense{typeof(identity), Matrix{Float32}, Vector{Float32}}}}}, ::SubArray{Vector{OneHotArrays.OneHotVector{UInt32}}, 1, Vector{Vector{OneHotArrays.OneHotVector{UInt32}}}, Tuple{UnitRange{Int64}}, true}, ::SubArray{Vector{OneHotArrays.OneHotVector{UInt32}}, 1, Vector{Vector{OneHotArrays.OneHotVector{UInt32}}}, Tuple{UnitRange{Int64}}, true})
    @ Zygote ~/.julia/packages/Zygote/dABKa/src/compiler/interface2.jl:0
 [35] _apply(::Function, ::Vararg{Any})
    @ Core ./boot.jl:816
 [36] adjoint
    @ ~/.julia/packages/Zygote/dABKa/src/lib/lib.jl:203 [inlined]
 [37] _pullback
    @ ~/.julia/packages/ZygoteRules/AIbCs/src/adjoint.jl:65 [inlined]
 [38] _pullback
    @ ~/.julia/packages/Flux/FKl3M/src/optimise/train.jl:132 [inlined]
 [39] _pullback(::Zygote.Context{true}, ::Flux.Optimise.var"#37#40"{var"#loss#9"{Chain{Tuple{Flux.Recur{Flux.LSTMCell{Matrix{Float32}, Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Flux.Recur{Flux.LSTMCell{Matrix{Float32}, Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Dense{typeof(identity), Matrix{Float32}, Vector{Float32}}}}}, Tuple{SubArray{Vector{OneHotArrays.OneHotVector{UInt32}}, 1, Vector{Vector{OneHotArrays.OneHotVector{UInt32}}}, Tuple{UnitRange{Int64}}, true}, SubArray{Vector{OneHotArrays.OneHotVector{UInt32}}, 1, Vector{Vector{OneHotArrays.OneHotVector{UInt32}}}, Tuple{UnitRange{Int64}}, true}}})
    @ Zygote ~/.julia/packages/Zygote/dABKa/src/compiler/interface2.jl:0
 [40] pullback(f::Function, ps::Zygote.Params{Zygote.Buffer{Any, Vector{Any}}})
    @ Zygote ~/.julia/packages/Zygote/dABKa/src/compiler/interface.jl:373
 [41] withgradient(f::Function, args::Zygote.Params{Zygote.Buffer{Any, Vector{Any}}})
    @ Zygote ~/.julia/packages/Zygote/dABKa/src/compiler/interface.jl:123
 [42] macro expansion
    @ ~/.julia/packages/Flux/FKl3M/src/optimise/train.jl:131 [inlined]
 [43] macro expansion
    @ ~/.julia/packages/ProgressLogging/6KXlp/src/ProgressLogging.jl:328 [inlined]
 [44] train!(loss::Function, ps::Zygote.Params{Zygote.Buffer{Any, Vector{Any}}}, data::Base.Iterators.Zip{Tuple{Vector{SubArray{Vector{OneHotArrays.OneHotVector{UInt32}}, 1, Vector{Vector{OneHotArrays.OneHotVector{UInt32}}}, Tuple{UnitRange{Int64}}, true}}, Vector{SubArray{Vector{OneHotArrays.OneHotVector{UInt32}}, 1, Vector{Vector{OneHotArrays.OneHotVector{UInt32}}}, Tuple{UnitRange{Int64}}, true}}}}, opt::Adam; cb::Flux.var"#throttled#124"{Flux.var"#throttled#120#125"{Bool, Bool, var"#8#11"{SubArray{Vector{OneHotArrays.OneHotVector{UInt32}}, 1, Vector{Vector{OneHotArrays.OneHotVector{UInt32}}}, Tuple{UnitRange{Int64}}, true}, SubArray{Vector{OneHotArrays.OneHotVector{UInt32}}, 1, Vector{Vector{OneHotArrays.OneHotVector{UInt32}}}, Tuple{UnitRange{Int64}}, true}, var"#loss#9"{Chain{Tuple{Flux.Recur{Flux.LSTMCell{Matrix{Float32}, Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Flux.Recur{Flux.LSTMCell{Matrix{Float32}, Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Dense{typeof(identity), Matrix{Float32}, Vector{Float32}}}}}}, Int64}})
    @ Flux.Optimise ~/.julia/packages/Flux/FKl3M/src/optimise/train.jl:129
 [45] train(; kws::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Main ~/Projects/model-zoo/text/char-rnn/char-rnn.jl:123
 [46] train()
    @ Main ~/Projects/model-zoo/text/char-rnn/char-rnn.jl:100
 [47] top-level scope
    @ ~/Projects/model-zoo/text/char-rnn/char-rnn.jl:168
in expression starting at /Users/mjyshin/Projects/model-zoo/text/char-rnn/char-rnn.jl:168

```

Anyone have any idea what’s going on? I have the following environment with Julia 1.8.2:

```julia
(julia) pkg> status
Status `~/Projects/test/julia/Project.toml`
  [587475ba] Flux v0.13.8
  [7073ff75] IJulia v1.23.3
  [b964fa9f] LaTeXStrings v1.3.0
  [d96e819e] Parameters v0.12.3
  [91a5bcdd] Plots v1.36.3
  [2913bbd2] StatsBase v0.33.21
  [e88e6eb3] Zygote v0.6.49

```

---

<div class="post-metadata">

**Author:** ![mcabbott](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcabbott/32/6603_2.png) [@mcabbott](https://discourse.julialang.org/u/mcabbott)\
**Post date:** [November 23, 2022, 5:53pm UTC](https://discourse.julialang.org/t/flux-rnn-training-giving-boundserror/90723/2 "2022-11-23T17:53:08Z")

</div>

This is [BoundsError calling Flux.reset! · Issue #1297 · FluxML/Zygote.jl · GitHub](https://github.com/FluxML/Zygote.jl/issues/1297) , fix from there is:

```julia
using ChainRulesCore, Zygote
ChainRulesCore.@non_differentiable foreach(f, ::Tuple{})
Zygote.refresh()

```

Could surely be added [here](https://github.com/JuliaDiff/ChainRules.jl/blob/main/src/rulesets/Base/nondiff.jl#L92).

---

<div class="post-metadata">

**Author:** ![mjyshin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mjyshin/32/26449_2.png) [@mjyshin](https://discourse.julialang.org/u/mjyshin)\
**Post date:** [November 24, 2022, 10:26am UTC](https://discourse.julialang.org/t/flux-rnn-training-giving-boundserror/90723/3 "2022-11-24T10:26:49Z")

</div>

This indeed got rid of the `BoundsError`, but the model-zoo RNN example still exits with an error:

```julia
[ Info: Start Training, total 2 epochs
[ Info: Epoch 1 / 2
ERROR: LoadError: MethodError: no method matching (::Flux.LSTMCell{Matrix{Float32}, Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}})(::Tuple{Matrix{Float32}, Matrix{Float32}}, ::Vector{OneHotArrays.OneHotVector{UInt32}})
Closest candidates are:
  (::Flux.LSTMCell{I, H, V, <:Tuple{AbstractMatrix{T}, AbstractMatrix{T}}})(::Any, ::Union{AbstractVector{T}, AbstractMatrix{T}, OneHotArrays.OneHotArray}) where {I, H, V, T} at ~/.julia/packages/Flux/FKl3M/src/layers/recurrent.jl:308
Stacktrace:
  [1] macro expansion
    @ ./compiler/interface2.jl:0 [inlined]
  [2] _pullback(::Zygote.Context{true}, ::Flux.LSTMCell{Matrix{Float32}, Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}}, ::Tuple{Matrix{Float32}, Matrix{Float32}}, ::Vector{OneHotArrays.OneHotVector{UInt32}})
    @ Zygote ./compiler/interface2.jl:9
  [3] _pullback
    @ ~/.julia/packages/Flux/FKl3M/src/layers/recurrent.jl:134 [inlined]
  [4] _pullback(ctx::Zygote.Context{true}, f::Flux.Recur{Flux.LSTMCell{Matrix{Float32}, Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Tuple{Matrix{Float32}, Matrix{Float32}}}, args::Vector{OneHotArrays.OneHotVector{UInt32}})
    @ Zygote ./compiler/interface2.jl:0
  [5] macro expansion
    @ ~/.julia/packages/Flux/FKl3M/src/layers/basic.jl:53 [inlined]
  [6] _pullback
    @ ~/.julia/packages/Flux/FKl3M/src/layers/basic.jl:53 [inlined]
  [7] _pullback(::Zygote.Context{true}, ::typeof(Flux._applychain), ::Tuple{Flux.Recur{Flux.LSTMCell{Matrix{Float32}, Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Flux.Recur{Flux.LSTMCell{Matrix{Float32}, Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Dense{typeof(identity), Matrix{Float32}, Vector{Float32}}}, ::Vector{OneHotArrays.OneHotVector{UInt32}})
    @ Zygote ./compiler/interface2.jl:0
  [8] _pullback
    @ ~/.julia/packages/Flux/FKl3M/src/layers/basic.jl:51 [inlined]
  [9] _pullback(ctx::Zygote.Context{true}, f::Chain{Tuple{Flux.Recur{Flux.LSTMCell{Matrix{Float32}, Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Flux.Recur{Flux.LSTMCell{Matrix{Float32}, Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Dense{typeof(identity), Matrix{Float32}, Vector{Float32}}}}, args::Vector{OneHotArrays.OneHotVector{UInt32}})
    @ Zygote ./compiler/interface2.jl:0
 [10] _pullback
    @ ./none:0 [inlined]
 [11] _pullback(ctx::Zygote.Context{true}, f::var"#9#12"{Chain{Tuple{Flux.Recur{Flux.LSTMCell{Matrix{Float32}, Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Flux.Recur{Flux.LSTMCell{Matrix{Float32}, Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Dense{typeof(identity), Matrix{Float32}, Vector{Float32}}}}}, args::Vector{OneHotArrays.OneHotVector{UInt32}})
    @ Zygote ./compiler/interface2.jl:0
 [12] (::Zygote.var"#467#471"{Zygote.Context{true}, var"#9#12"{Chain{Tuple{Flux.Recur{Flux.LSTMCell{Matrix{Float32}, Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Flux.Recur{Flux.LSTMCell{Matrix{Float32}, Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Dense{typeof(identity), Matrix{Float32}, Vector{Float32}}}}}})(args::Vector{OneHotArrays.OneHotVector{UInt32}})
    @ Zygote ~/.julia/packages/Zygote/dABKa/src/lib/array.jl:172
 [13] iterate
    @ ./generator.jl:47 [inlined]
 [14] _collect
    @ ./array.jl:807 [inlined]
 [15] collect_similar
    @ ./array.jl:716 [inlined]
 [16] map
    @ ./abstractarray.jl:2933 [inlined]
 [17] ∇map
    @ ~/.julia/packages/Zygote/dABKa/src/lib/array.jl:172 [inlined]
 [18] _pullback
    @ ~/.julia/packages/Zygote/dABKa/src/lib/array.jl:214 [inlined]
 [19] _pullback
    @ ~/Projects/model-zoo/text/char-rnn/char-rnn.jl:115 [inlined]
 [20] _pullback(::Zygote.Context{true}, ::var"#loss#11"{Chain{Tuple{Flux.Recur{Flux.LSTMCell{Matrix{Float32}, Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Flux.Recur{Flux.LSTMCell{Matrix{Float32}, Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Dense{typeof(identity), Matrix{Float32}, Vector{Float32}}}}}, ::SubArray{Vector{OneHotArrays.OneHotVector{UInt32}}, 1, Vector{Vector{OneHotArrays.OneHotVector{UInt32}}}, Tuple{UnitRange{Int64}}, true}, ::SubArray{Vector{OneHotArrays.OneHotVector{UInt32}}, 1, Vector{Vector{OneHotArrays.OneHotVector{UInt32}}}, Tuple{UnitRange{Int64}}, true})
    @ Zygote ./compiler/interface2.jl:0
 [21] _apply(::Function, ::Vararg{Any})
    @ Core ./boot.jl:816
 [22] adjoint
    @ ~/.julia/packages/Zygote/dABKa/src/lib/lib.jl:203 [inlined]
 [23] _pullback
    @ ~/.julia/packages/ZygoteRules/AIbCs/src/adjoint.jl:65 [inlined]
 [24] _pullback
    @ ~/.julia/packages/Flux/FKl3M/src/optimise/train.jl:132 [inlined]
 [25] _pullback(::Zygote.Context{true}, ::Flux.Optimise.var"#37#40"{var"#loss#11"{Chain{Tuple{Flux.Recur{Flux.LSTMCell{Matrix{Float32}, Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Flux.Recur{Flux.LSTMCell{Matrix{Float32}, Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Dense{typeof(identity), Matrix{Float32}, Vector{Float32}}}}}, Tuple{SubArray{Vector{OneHotArrays.OneHotVector{UInt32}}, 1, Vector{Vector{OneHotArrays.OneHotVector{UInt32}}}, Tuple{UnitRange{Int64}}, true}, SubArray{Vector{OneHotArrays.OneHotVector{UInt32}}, 1, Vector{Vector{OneHotArrays.OneHotVector{UInt32}}}, Tuple{UnitRange{Int64}}, true}}})
    @ Zygote ./compiler/interface2.jl:0
 [26] pullback(f::Function, ps::Params{Zygote.Buffer{Any, Vector{Any}}})
    @ Zygote ~/.julia/packages/Zygote/dABKa/src/compiler/interface.jl:373
 [27] withgradient(f::Function, args::Params{Zygote.Buffer{Any, Vector{Any}}})
    @ Zygote ~/.julia/packages/Zygote/dABKa/src/compiler/interface.jl:123
 [28] macro expansion
    @ ~/.julia/packages/Flux/FKl3M/src/optimise/train.jl:131 [inlined]
 [29] macro expansion
    @ ~/.julia/packages/ProgressLogging/6KXlp/src/ProgressLogging.jl:328 [inlined]
 [30] train!(loss::Function, ps::Params{Zygote.Buffer{Any, Vector{Any}}}, data::Base.Iterators.Zip{Tuple{Vector{SubArray{Vector{OneHotArrays.OneHotVector{UInt32}}, 1, Vector{Vector{OneHotArrays.OneHotVector{UInt32}}}, Tuple{UnitRange{Int64}}, true}}, Vector{SubArray{Vector{OneHotArrays.OneHotVector{UInt32}}, 1, Vector{Vector{OneHotArrays.OneHotVector{UInt32}}}, Tuple{UnitRange{Int64}}, true}}}}, opt::Adam; cb::Flux.var"#throttled#124"{Flux.var"#throttled#120#125"{Bool, Bool, var"#10#13"{SubArray{Vector{OneHotArrays.OneHotVector{UInt32}}, 1, Vector{Vector{OneHotArrays.OneHotVector{UInt32}}}, Tuple{UnitRange{Int64}}, true}, SubArray{Vector{OneHotArrays.OneHotVector{UInt32}}, 1, Vector{Vector{OneHotArrays.OneHotVector{UInt32}}}, Tuple{UnitRange{Int64}}, true}, var"#loss#11"{Chain{Tuple{Flux.Recur{Flux.LSTMCell{Matrix{Float32}, Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Flux.Recur{Flux.LSTMCell{Matrix{Float32}, Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Dense{typeof(identity), Matrix{Float32}, Vector{Float32}}}}}}, Int64}})
    @ Flux.Optimise ~/.julia/packages/Flux/FKl3M/src/optimise/train.jl:129
 [31] train(; kws::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ Main ~/Projects/model-zoo/text/char-rnn/char-rnn.jl:126
 [32] train()
    @ Main ~/Projects/model-zoo/text/char-rnn/char-rnn.jl:103
 [33] top-level scope
    @ ~/Projects/model-zoo/text/char-rnn/char-rnn.jl:171
in expression starting at /Users/mjyshin/Projects/model-zoo/text/char-rnn/char-rnn.jl:171

```

Instead of opening up another thread, could anyone help debug this example (it might be of general interest for those wanting to get a simple RNN to even run)?

---

<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 25, 2022, 3:12am UTC](https://discourse.julialang.org/t/flux-rnn-training-giving-boundserror/90723/4 "2022-11-25T03:12:01Z")

</div>

The char-rnn example in the zoo has gone through quite some bitrot and wasn’t ever the best example of how to use an RNN because of its funky data handling. If someone wants to look into this, feel free to file PRs against the model zoo and ping me.
