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

Method error when using Flux.setup with Embedding layer #2144

Closed
egolep opened this issue Dec 28, 2022 · 2 comments · Fixed by #2145
Closed

Method error when using Flux.setup with Embedding layer #2144

egolep opened this issue Dec 28, 2022 · 2 comments · Fixed by #2145
Labels

Comments

@egolep
Copy link

egolep commented Dec 28, 2022

Whenever I try to use the Flux.setup function, if my neural network (Chain) contains an Embedding layer, I get this error:

ERROR: MethodError: no method matching Embedding(::Bool)
Closest candidates are:
  Embedding(::Integer, ::Integer; kw...) at ~/.julia/packages/Flux/kq9Et/src/deprecations.jl:67
  Embedding(::Pair{<:Integer, <:Integer}; init) at ~/.julia/packages/Flux/kq9Et/src/layers/basic.jl:694
  Embedding(::W) where W<:(AbstractMatrix) at ~/.julia/packages/Flux/kq9Et/src/layers/basic.jl:689

For example, this snippet fails:

m = Embedding(3=>1)
Flux.setup(Adam(), m)

It fails both on CPU and GPU

@mcabbott mcabbott added the bug label Dec 28, 2022
@mcabbott
Copy link
Member

That's no good, sorry.

Seems like a bug in Flux, since the supposedly equivalent Optimisers.jl functions work fine -- and can be used as a work-around for now:

julia> Optimisers.setup(Optimisers.Adam(), Embedding(3 => 1))
(weight = Leaf(Adam{Float32}(0.001, (0.9, 0.999), 1.19209f-7), (Float32[0.0 0.0 0.0], Float32[0.0 0.0 0.0], (0.9, 0.999))),)

julia> Flux.setup(Flux.Adam(), Embedding(3=>1))
ERROR: MethodError: no method matching Embedding(::Bool)
...
Stacktrace:
  [1] (::Flux.var"#222#223")(y::NamedTuple{(:weight,), Tuple{Bool}})
    @ Flux ~/.julia/packages/Functors/orBYx/src/functor.jl:20
  [2] (::Functors.DefaultWalk)(::Function, ::Embedding{Matrix{Float32}})
    @ Functors ~/.julia/packages/Functors/orBYx/src/walks.jl:62
  [3] ExcludeWalk
    @ ~/.julia/packages/Functors/orBYx/src/walks.jl:92 [inlined]
  [4] CachedWalk
    @ ~/.julia/packages/Functors/orBYx/src/walks.jl:132 [inlined]
  [5] fmap
    @ ~/.julia/packages/Functors/orBYx/src/maps.jl:1 [inlined]
  [6] #fmap#25
    @ ~/.julia/packages/Functors/orBYx/src/maps.jl:11 [inlined]
  [7] setup(rule::Optimisers.Adam{Float64}, model::Embedding{Matrix{Float32}})
    @ Flux.Train ~/.julia/packages/Flux/kq9Et/src/train.jl:51
  [8] setup(rule::Adam, model::Embedding{Matrix{Float32}})
    @ Flux ~/.julia/packages/Flux/kq9Et/src/deprecations.jl:117

@egolep
Copy link
Author

egolep commented Dec 28, 2022

Nothing to be sorry about.
Thanks for the quick reply and fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants