-
-
Notifications
You must be signed in to change notification settings - Fork 656
Adding Exponential Annealing to contrib handlers #443
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
base: master
Are you sure you want to change the base?
Conversation
|
The error from travis seems independent from the code. |
|
@zippeurfou can we provide a generic annealing with any scheduler ? For example, I have a basic multi-step scheduler which I would like replicate periodically with value-length scaling... |
|
Maybe something like a lambda annealing? |
|
Sorry, I do not know a lambda annealing. If you are speaking about the implementation we can do it probably like:
|
|
I am sorry I am unsure to understand the question/problem. |
|
Actually, yes you are right, I was speaking about a sort of lambda annealing, and exp annealing is a special case. |
|
Sadly, looking at the formulas I don't think we can really make something generic. |
|
@zippeurfou I tried to prototype such class quickly and it's true that this can be more complex to support all type of schedulers... Idea is something like that: class LambdaAnnealing(ParamScheduler):
def __init__(self, scheduler, cycle_size, cycle_mult=1.0, save_history=False):
super(LambdaAnnealing, self).__init__(optimizer={}, param_name="", save_history=save_history)
self.scheduler = scheduler
self.optimizer_param_groups = self.scheduler.optimizer_param_groups
self.param_name = self.scheduler.param_name
self.cycle_size = cycle_size
self.cycle_mult = cycle_mult
self.cycle = 0
def get_param(self):
if self.event_index > 0 and (self.event_index % self.cycle_size) == 0:
# Restart wrapped scheduler
# !!! THIS WONT WORK FOR EVERY SCHEDULER !!!
self.scheduler.event_index = 0
self.cycle_size *= self.cycle_mult
self.cycle += 1
value = self.scheduler.get_param()
# Maybe we could scale the value here
return value |
|
How can I help with this one? |
@zippeurfou you can go on with the prototype class scheduler = PiecewiseLinear(optimizer, "lr",
milestones_values=[(0, 0.0), (10, 0.4), (29, 0.0)])
la_scheduler = LambdaAnnealing(scheduler, cycle_size=25)
from ignite.engine import Engine, Events
lrs = []
def save_lr(engine):
lrs.append(optimizer.param_groups[0]['lr'])
trainer = Engine(lambda engine, batch: None)
trainer.add_event_handler(Events.ITERATION_STARTED, la_scheduler)
trainer.add_event_handler(Events.ITERATION_COMPLETED, save_lr)
trainer.run([0] * 10, max_epochs=5)
import numpy as np
import matplotlib.pylab as plt
plt.title("Lambda annealing")
plt.plot(lrs, label="learning rate")
plt.xlabel("events")
plt.ylabel("values")
plt.legend()After that we need also the tests to write.
I have no idea of any usefullness of this |
Fixes #
Description:
This add exponential annealing to the contrib handler. The goal being to be able to mimic fast.ai learning rate ability. The LRFinder uses annealing_exp to find the optimal learning rate.
This PR allows to do it.
Check list: