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

Implement Cyclic Learning Rate and Step-wise Learning Rate Scheduler #213

Merged
merged 9 commits into from
Nov 18, 2024

Conversation

Franklalalala
Copy link
Collaborator

As mentioned in [issue 211], this PR aims to Implement Cyclic Learning Rate and Step-wise Learning Rate Scheduler.

Major changes include:

  1. add a Cyclic Learning Rate in tool.py and corresponding args.
  2. add step-wise lr update scheme in trainer.py and base_trainer.py.
  3. unit test, here I implemented 4 cases, which are mesh test on two lr scheme, exp and clr, and w/wo iteration-wise lr update

Minor change:

  1. docs have been updated in argcheck.py
  2. use the 'display_freq' as the tensorboard log interval (per-iteration), instead of using a fixed 25 iteration interval.

@Franklalalala
Copy link
Collaborator Author

The code has been cleaned. It is now the same with the upstream.

@QG-phy QG-phy requested a review from floatingCatty November 12, 2024 05:49
@Franklalalala
Copy link
Collaborator Author

the test example has been updated:
the dataset size was reduced from 5MB to 68KB

Copy link
Member

Choose a reason for hiding this comment

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

这个file可以再小一点吗?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done

@@ -30,6 +30,7 @@ def __init__(
self.model = model.to(self.device)
self.optimizer = get_optimizer(model_param=self.model.parameters(), **train_options["optimizer"])
self.lr_scheduler = get_lr_scheduler(optimizer=self.optimizer, **train_options["lr_scheduler"]) # add optmizer
self.update_lr_per_step_flag = train_options["update_lr_per_step_flag"]
Copy link
Member

Choose a reason for hiding this comment

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

如果这个flag为false就不更新LR了?

@@ -129,6 +130,11 @@ def iteration(self, batch, ref_batch=None):
loss.backward()
#TODO: add clip large gradient
self.optimizer.step()
if self.update_lr_per_step_flag:
Copy link
Member

Choose a reason for hiding this comment

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

没太理解这个开关的作用

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

学习率更新需要显式的使用 self.lr_scheduler.step()。添加这个开关可以在每个 iteration 里调用,否则是每个 epoch 调用一次

@floatingCatty floatingCatty merged commit 8b241f5 into deepmodeling:main Nov 18, 2024
2 checks passed
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 this pull request may close these issues.

3 participants