FluxML/ParameterSchedulers.jl

ReduceLRonPlateau support

rejuvyesh opened this issue · 1 comments

I wasn't sure how best to include such schedulers with the current API (especially with iterate). Idea is same as PyTorch ReduceLROnPlateau.

So that type of schedule will not fit into the iteration interface, because it is inherently stateful (depends on more than the iteration index). The closest example of a schedule that fits that style is ParameterSchedulers.Stateful. It has its own interface (next!) that advances the schedule.

If we do want to include lots of stateful schedules, then maybe we should think about what that means. Another example of a stateful "schedule" is ParameterSchedulers.Scheduler. Perhaps the best approach is to divide things into schedules vs schedulers. A schedule is a stateless sequence, and a scheduler is a stateful way to iterate a schedule.


Specifically for ReduceLROnPlateau, I would think we'd want a more generic implementation than PyTorch. For example, if Flux includes utilities like early stopping with patience, then you could write something like:

plateau = Flux.early_stopping(validation, patience = 5)
schedule = ParameterSchedulers.Stateful(Exp= 0.1, γ = 0.5))
opt = Descent()

for epoch in 1:nepochs
    if plateau()
        opt.eta = next!(schedule)
    end

    # ...
end

So, a generic implementation would pull the idea of a predicate into Stateful. So you could write something like schedule = Stateful(...; advance = Flux.early_stopping(...)), and next! would only advance the state when schedule.advance() == true. By default, advance = () -> true.