You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This question has come up several times. I should add an example for this in the manual. Basic sketch would be something like this:
using LuxCore
struct MyCustomLuxLayer <:AbstractLuxLayer....end
LuxCore.initialparameters(....) =....
LuxCore.initialstates(....) =....function (l::MyCustomLuxLayer)(x, ps, st)
....return y, new_st
end# This part is general, doesn't need to be defined for every specific layermutable struct MyCustomFluxLayer{L <:MyCustomLuxLayer}
internal_layer::L
ps
st
endfunctionMyCustomFluxLayer(args...; kwargs...)
layer =MyCustomLuxLayer(args...; kwargs...)
returnMyCustomFluxLayer(layer, LuxCore.setup(rng, layer)...)
endfunction (l::MyCustomFluxLayer)(x)
y, st = l.internal_layer(x, l.ps, l.st)
l.st = st # Can also fmap over `st` and copy into existing buffersreturn y
end
In MyPackageFluxExt.jl
using Flux
Flux.@layer MyCustomFluxLayer (:ps,)
The text was updated successfully, but these errors were encountered:
It's pretty cool that one can do this pretty seamlessly! However, there are many helper functions in Lux that are useful when building libraries for it. So I guess that if I had using Lux and and extension with Flux, that extension would have to load both the packages with some overhead right?
Yes you would have to load both in that case. 1 thing to note is that Flux does ship with AD libraries packaged, so its load time is generally higher. Also Lux deps are a subset (for the most part) of Flux, so there isn't much additional overhead
This question has come up several times. I should add an example for this in the manual. Basic sketch would be something like this:
In
MyPackageFluxExt.jl
The text was updated successfully, but these errors were encountered: