using Lux, Random
nn = Lux.Dense(10, 10, tanh)
ps, st = Lux.setup(Xoshiro(2024), nn)
nn_st = Lux.StatefulLuxLayer{true}(nn, nothing, st, nothing)
input_data = rand(10)
Lux.apply(nn_st, input_data, ps) # do not work on Luxv1.21.0 but worked on Luxv1.18.0
# ERROR: MethodError: no method matching apply(::StatefulLuxLayer{…}, ::Vector{…}, ::@NamedTuple{…})
# The function `apply` exists, but no method is defined for this combination of argument types.
# Closest candidates are:
# apply(::AbstractLuxLayer, ::Any, ::Any, ::Any)
nn_st(input_data, ps) # works in both cases
Since v1.19 StatefulLuxLayer
have been moved to LuxCore and documentation says this is not an AbstractLuxLayer
.
Since that update, the apply
do no longer work. Only nn_st(x, ps)
works, but I thought it was better to use apply
(see docs).
Since I just want to use StatefulLuxLayer
to keep the state while changing parameters, Lux.StatefulLuxLayer{true}(nn, nothing, st, nothing)
with apply seemed like the best option.
What is the best post-Luxv1.19 way to do that?
BTW I don’t know what the 2nd nothing
refers to (it is a code from one of my old student) in the StatefullLuxlayer
def .