create_lr_scheduler_with_warmup does not change init_lr to proper value
See original GitHub issueHi,
In order to get expected sequence of lr
s from create_lr_scheduler_with_warmup
’s scheduler, one must not attach it to engine on event EPOCH_COMPLETED
because it produces the lr
passed to optimizer’s constructor at the beginning and then warmup lr
s. This hurts warmup procedure. As a workaround, one could use event EPOCH_STARTED
but it might not be a good solution.
It seems there should be something like below in line 1017 of param_scheduler.py within the for loop .
param_group['lr'] = warmup_start_value
To reproduce current behaviour:
param = nn.Parameter(torch.Tensor([3.]))
optimizer = torch.optim.SGD([param], lr=1e-3)
scheduler = StepLR(optimizer, 3)
with_warmup_scheduler = create_lr_scheduler_with_warmup(scheduler, warmup_start_value=1e-5, warmup_duration=3)
def process_func(e,b):
param.grad = torch.Tensor([1.])
optimizer.step()
trainer = Engine(process_func)
@trainer.on(Events.EPOCH_COMPLETED)
def _():
print(op.param_groups[0]['lr'])
trainer.add_event_handler(Events.EPOCH_COMPLETED, with_warmup_scheduler)
output:
0.001
1e-05
0.000505
0.001
0.001
0.001
0.0001
0.0001
0.0001
1e-05
Issue Analytics
- State:
- Created 2 years ago
- Comments:10
Top Results From Across the Web
No results found
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@sadra-barikbin you can simply schedule your post-warm-up epoch-wise scheduling using iterations if possible. Otherwise, you can try to combine events as below:
By the way, our docs on
create_lr_scheduler_with_warmup
is incorrect, cc @sdesrozis . We should triggerscheduler
onITERATION_STARTED
instead ofITERATION_COMPLETED
if we would like to avoid the first iteration to take optimizer’s default value.@sadra-barikbin so basically you add example to this examples and it will rendered on the main website (the new one) and we can reference it then.
please check the contributing guide for the examples and do not hesitate to ask for the help!