Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ReduceLRonPlateau support #11

Closed
rejuvyesh opened this issue Apr 5, 2021 · 1 comment · Fixed by #12
Closed

ReduceLRonPlateau support #11

rejuvyesh opened this issue Apr 5, 2021 · 1 comment · Fixed by #12

Comments

@rejuvyesh
Copy link
Contributor

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

@darsnack
Copy link
Member

darsnack commented Apr 8, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants