I am using Julia 1.6 and Flux v0.12.6
I am having issues using the recurrent layers LSTM and RNN in Flux.jl and it does not make sense why this is happening. hopefully someone can see where it is going wrong?
I define the model as:
julia> my_model = LSTM(1,1)
Recur(
LSTMCell(1, 1), # 14 parameters
) # Total: 5 trainable arrays, 14 parameters,
# plus 2 non-trainable, 2 parameters, summarysize 384 bytes.
I test it with
julia> eval = my_model.([1,2,3])
And it returns the error
ERROR: MethodError: no method matching (::Flux.LSTMCell{Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}})(::Tuple{Matrix{Float32}, Matrix{Float32}}, ::Int64)
Closest candidates are:
(::Flux.LSTMCell{A, V, var"#s318"} where var"#s318"<:Tuple{AbstractMatrix{T}, AbstractMatrix{T}})(::Any, ::Union{AbstractVector{T}, AbstractMatrix{T}, Flux.OneHotArray}) where {A, V, T} at /home/shindler/.julia/packages/Flux/Zz9RI/src/layers/recurrent.jl:137
Stacktrace:
[1] (::Flux.Recur{Flux.LSTMCell{Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Tuple{Matrix{Float32}, Matrix{Float32}}})(x::Int64)
@ Flux ~/.julia/packages/Flux/Zz9RI/src/layers/recurrent.jl:34
[2] _broadcast_getindex_evalf
@ ./broadcast.jl:648 [inlined]
[3] _broadcast_getindex
@ ./broadcast.jl:621 [inlined]
[4] getindex
@ ./broadcast.jl:575 [inlined]
[5] copy
@ ./broadcast.jl:922 [inlined]
[6] materialize(bc::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{1}, Nothing, Flux.Recur{Flux.LSTMCell{Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Tuple{Vector{Int64}}})
@ Base.Broadcast ./broadcast.jl:883
[7] top-level scope
@ REPL[31]:1
[8] top-level scope
@ ~/.julia/packages/CUDA/9T5Sq/src/initialization.jl:66
I get the same issue when I run the model without the .
julia> my_model = LSTM(3,1)
Recur(LSTMCell(3, 1))
julia> my_model([3,2,1])
ERROR: MethodError: no method matching (::Flux.LSTMCell{Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}})(::Tuple{Matrix{Float32}, Matrix{Float32}}, ::Vector{Int64})
Closest candidates are:
(::Flux.LSTMCell{A, V, var"#s268"} where var"#s268"<:Tuple{AbstractMatrix{T}, AbstractMatrix{T}})(::Any, ::Union{AbstractVector{T}, AbstractMatrix{T}, Flux.OneHotArray}) where {A, V, T} at /home/shindler/.julia/packages/Flux/0c9kI/src/layers/recurrent.jl:137
Stacktrace:
[1] (::Flux.Recur{Flux.LSTMCell{Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}}, Tuple{Matrix{Float32}, Matrix{Float32}}})(x::Vector{Int64})
@ Flux ~/.julia/packages/Flux/0c9kI/src/layers/recurrent.jl:34
[2] top-level scope
@ REPL[40]:1
[3] top-level scope
@ ~/.julia/packages/CUDA/fRSUT/src/initialization.jl:52
I have the issue with a RNN as well
julia> my_model = RNN(3,1)
Recur(RNNCell(3, 1, tanh))
julia> my_model([3,2,1])
ERROR: MethodError: no method matching (::Flux.RNNCell{typeof(tanh), Matrix{Float32}, Vector{Float32}, Matrix{Float32}})(::Matrix{Float32}, ::Vector{Int64})
Closest candidates are:
(::Flux.RNNCell{F, A, V, var"#s269"} where var"#s269"<:AbstractMatrix{T})(::Any, ::Union{AbstractVector{T}, AbstractMatrix{T}, Flux.OneHotArray}) where {F, A, V, T} at /home/shindler/.julia/packages/Flux/0c9kI/src/layers/recurrent.jl:83
Stacktrace:
[1] (::Flux.Recur{Flux.RNNCell{typeof(tanh), Matrix{Float32}, Vector{Float32}, Matrix{Float32}}, Matrix{Float32}})(x::Vector{Int64})
@ Flux ~/.julia/packages/Flux/0c9kI/src/layers/recurrent.jl:34
[2] top-level scope
@ REPL[42]:1
[3] top-level scope
@ ~/.julia/packages/CUDA/fRSUT/src/initialization.jl:52
But a Dense layer seems to work fine
julia> my_model = Dense(3,1)
Dense(3, 1)
julia> my_model([3,2,1])
1-element Vector{Float32}:
-1.0215458