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

Colab - MethodError: no method matching (::Flux.LSTMCell{... #1563

Closed
IsaacBreen opened this issue Apr 4, 2021 · 5 comments
Closed

Colab - MethodError: no method matching (::Flux.LSTMCell{... #1563

IsaacBreen opened this issue Apr 4, 2021 · 5 comments

Comments

@IsaacBreen
Copy link

IsaacBreen commented Apr 4, 2021

When I run this, I get an error.

using Flux
LSTM(5,5)(rand(5))
ERROR: MethodError: no method matching (::Flux.LSTMCell{Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}})(::Tuple{Matrix{Float32}, Matrix{Float32}}, ::Vector{Float64})
Closest candidates are:
  (::Flux.LSTMCell{A, V, var"#s262"} where var"#s262"<:Tuple{AbstractMatrix{T}, AbstractMatrix{T}})(::Any, ::Union{AbstractVector{T}, AbstractMatrix{T}, Flux.OneHotArray}) where {A, V, T} at /root/.julia/packages/Flux/qp1gc/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{Float64})
   @ Flux ~/.julia/packages/Flux/qp1gc/src/layers/recurrent.jl:34
 [2] top-level scope
   @ REPL[3]:1

This occurs on a Google Colab instance. To reproduce, paste the following into a Colab cell and run:

!wget -q https://julialang-s3.julialang.org/bin/linux/x64/1.6/julia-1.6.0-linux-x86_64.tar.gz
!tar zxf julia-1.6.0-linux-x86_64.tar.gz
!/content/julia-1.6.0/bin/julia -e "import Pkg; Pkg.add(\"Flux\"); using Flux; LSTM(5,5)(rand(5))"
@IsaacBreen IsaacBreen changed the title MethodError: no method matching (::Flux.LSTMCell{Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}})(::Tuple{Matrix{Float32}, Matrix{Float32}}, ::Vector{Float64}) Colab - MethodError: no method matching (::Flux.LSTMCell{... Apr 4, 2021
@DhairyaLGandhi
Copy link
Member

You might want to wrap the input in an array

@IsaacBreen
Copy link
Author

IsaacBreen commented Apr 4, 2021

LSTM(5,5)([rand(5)]) produces a very similar error (below). I've also tried LSTM(5,5)(rand(5,5)) and LSTM(5,5)(rand(5,5,5)) to no avail.

using Flux
LSTM(5,5)([rand(5)])
ERROR: MethodError: no method matching (::Flux.LSTMCell{Matrix{Float32}, Vector{Float32}, Tuple{Matrix{Float32}, Matrix{Float32}}})(::Tuple{Matrix{Float32}, Matrix{Float32}}, ::Vector{Vector{Float64}})
Closest candidates are:
  (::Flux.LSTMCell{A, V, var"#s262"} where var"#s262"<:Tuple{AbstractMatrix{T}, AbstractMatrix{T}})(::Any, ::Union{AbstractVector{T}, AbstractMatrix{T}, Flux.OneHotArray}) where {A, V, T} at /root/.julia/packages/Flux/qp1gc/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{Vector{Float64}})
   @ Flux ~/.julia/packages/Flux/qp1gc/src/layers/recurrent.jl:34
 [2] top-level scope
   @ none:1

@darsnack
Copy link
Member

darsnack commented Apr 4, 2021

Try rand(Float32, 5)

@IsaacBreen
Copy link
Author

IsaacBreen commented Apr 9, 2021

That works, thanks darsnack! I'm not sure why Julia 1.5.3 on my laptop can run Flux; LSTM(5,5)(rand(5)) without issue. rand(5) still returns Vector{Float64} and param(LSTM(5,5)) returns Params([Float32[..., but I guess 1.5.3 makes an implicit conversion somewhere in there.

Oh well. Thanks!

@darsnack
Copy link
Member

darsnack commented Apr 9, 2021

Probably your laptop has an older version of Flux where we passively allowed the type promotion. The restriction was only put in with Flux v0.12.

@darsnack darsnack closed this as completed Apr 9, 2021
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

3 participants