Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
Add stateless_apply
Browse files Browse the repository at this point in the history
This calls `apply` and only returns the first argument.
  • Loading branch information
SebastianM-C committed Feb 23, 2024
1 parent 62f52f3 commit 29f2c2a
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/LuxCore.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,21 @@ Simply calls `model(x, ps, st)`
"""
apply(model::AbstractExplicitLayer, x, ps, st) = model(x, ps, st)

"""
stateless_apply(model, x, ps, st)
Calls `apply` and only returns the first argument.
"""
function stateless_apply(model::AbstractExplicitLayer, x, ps, st)
u, st = apply(model, x, ps, st)
@assert isempty(st) "Model is not stateless. Use `apply` instead."
return u
end

function stateless_apply(::StatefulLuxLayer, x, ps, st)
return error("Model is not stateless. Use `apply` instead.")
end

"""
display_name(layer::AbstractExplicitLayer)
Expand Down

0 comments on commit 29f2c2a

Please sign in to comment.