Skip to content

To change WarmUp Scheduler with ConstantLR and LinearLR#64395

Closed
iramazanli wants to merge 1 commit intopytorch:masterfrom
iramazanli:warmupschedulers
Closed

To change WarmUp Scheduler with ConstantLR and LinearLR#64395
iramazanli wants to merge 1 commit intopytorch:masterfrom
iramazanli:warmupschedulers

Conversation

@iramazanli
Copy link
Contributor

@iramazanli iramazanli commented Sep 1, 2021

Partially unblocks pytorch/vision#4281

Previously we have added WarmUp Schedulers to PyTorch Core in the PR : #60836 which had two mode of execution - linear and constant depending on warming up function.

In this PR we are changing this interface to more direct form, as separating linear and constant modes to separate Schedulers. In particular

scheduler1 = WarmUpLR(optimizer, warmup_factor=0.1, warmup_iters=5, warmup_method="constant")
scheduler2 = WarmUpLR(optimizer, warmup_factor=0.1, warmup_iters=5, warmup_method="linear")

will look like

scheduler1 = ConstantLR(optimizer, warmup_factor=0.1, warmup_iters=5)
scheduler2 = LinearLR(optimizer, warmup_factor=0.1, warmup_iters=5)

correspondingly.

@facebook-github-bot
Copy link
Contributor

facebook-github-bot commented Sep 1, 2021

🔗 Helpful links

💊 CI failures summary and remediations

As of commit 93bb484 (more details on the Dr. CI page):


💚 💚 Looks good so far! There are no failures yet. 💚 💚


This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.

Please report bugs/suggestions to the (internal) Dr. CI Users group.

Click here to manually regenerate this comment.

@iramazanli iramazanli force-pushed the warmupschedulers branch 5 times, most recently from 91dd0e0 to 09b1b56 Compare September 2, 2021 14:56
@iramazanli iramazanli changed the title To change WarmUp Scheduler with Constant and Linear LR To change WarmUp Scheduler with Constant LR and Linear LR Sep 2, 2021
@iramazanli iramazanli changed the title To change WarmUp Scheduler with Constant LR and Linear LR To change WarmUp Scheduler with ConstantLR and LinearLR Sep 2, 2021
@codecov
Copy link

codecov bot commented Sep 2, 2021

Codecov Report

Merging #64395 (93bb484) into master (0c4e4e5) will increase coverage by 0.03%.
The diff coverage is 87.50%.

@@            Coverage Diff             @@
##           master   #64395      +/-   ##
==========================================
+ Coverage   66.63%   66.66%   +0.03%     
==========================================
  Files         705      707       +2     
  Lines       92193    92535     +342     
==========================================
+ Hits        61432    61690     +258     
- Misses      30761    30845      +84     

Copy link
Contributor

@datumbox datumbox left a comment

Choose a reason for hiding this comment

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

@iramazanli Thanks a lot for the fast PR.

I left a few minor comments for which I would like your input, but nothing major.

I also noticed that we don't have any tests for LinearLR that use the new end parameter. We need to adapt the tests to include it I think. Other than this it looks good.

@iramazanli iramazanli force-pushed the warmupschedulers branch 8 times, most recently from ad8ef81 to 20b5fdb Compare September 3, 2021 18:03
Copy link
Contributor

@datumbox datumbox left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the speedy changes.

@facebook-github-bot
Copy link
Contributor

@iramazanli has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@iramazanli has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

Copy link
Member

@fmassa fmassa left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the PR Ilqar!

I've made a couple of minor comments for my understanding, otherwise everything LGTM!

if (self.last_epoch > self.warmup_iters or
(self.warmup_method == "constant" and self.last_epoch != self.warmup_iters)):
if (self.last_epoch > self.total_iters):
return [group['lr'] for group in self.optimizer.param_groups]
Copy link
Member

Choose a reason for hiding this comment

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

Don't we need to multiply by end_factor now that we might have an end_factor which is different than 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually as this is the recursive definition and at the epoch number total_iters we already have multiplication with end_factor, we no more need to mention multiplication here.

Comment on lines +544 to +545
return [group['lr'] * (1. + (self.end_factor - self.start_factor) /
(self.total_iters * self.start_factor + (self.last_epoch - 1) * (self.end_factor - self.start_factor)))
Copy link
Member

Choose a reason for hiding this comment

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

Just asking to make sure this case is handled properly: can we have end_factor < start_factor (i.e., for a linear decay of the learning rate)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes it can have :)

@facebook-github-bot
Copy link
Contributor

@iramazanli has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Contributor

@iramazanli merged this pull request in f767cf6.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants