Skip to content
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/helpers/optimizers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ function Optimisers.init(
return zero(x), zero(x), Utils.convert_eltype.((T,), opt.opt.beta), zero(x)
end

# Recurse through chains
function Optimisers.adjust(
chain::ReactantOptimiser{<:Optimisers.OptimiserChain},
eta::Real
)
results = Optimisers.OptimiserChain([Optimisers.adjust(opt, eta) for opt in chain.opt.opts]...)
return ReactantOptimiser(results)
end
function Optimisers.adjust(
chain::ReactantOptimiser{<:Optimisers.OptimiserChain};
kw...
)
Comment on lines +51 to +61
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will overloading _adjust work instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be done that way, but there would be more duplicated code since the implementation would end up replicating the recursion code already present in Optimisers.adjust.

results = Optimisers.OptimiserChain([Optimisers.adjust(opt; kw...) for opt in chain.opt.opts]...)
return ReactantOptimiser(results)
end

function Optimisers._adjust(opt::ReactantOptimiser, nt::NamedTuple)
dev = with_track_numbers(get_device(opt), AbstractFloat)
return ReactantOptimiser(Optimisers._adjust(opt.opt, dev(nt)))
Expand Down