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

[CodeCamp #28] support ReduceOnPlateau #819

Merged
merged 48 commits into from Jan 16, 2023
Merged

[CodeCamp #28] support ReduceOnPlateau #819

merged 48 commits into from Jan 16, 2023

Conversation

LEFTeyex
Copy link
Contributor

@LEFTeyex LEFTeyex commented Dec 13, 2022

Thanks for your contribution and we appreciate it a lot. The following instructions would make your pull request more healthy and more easily get feedback. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.

Motivation

The task to support ReduceLROnPlateau in OpenMMLab Code Camp.

Modification

Add ReduceOnPlateauParamScheduler, ReduceOnPlateauLR, ReduceOnPlateauMomentum class and add after_val_epoch hook position to support ReduceLROnPlateau.

BC-breaking (Optional)

Does the modification introduce changes that break the backward-compatibility of the downstream repos?
If so, please describe how it breaks the compatibility and how the downstream projects should modify their code to keep compatibility with this PR.

Use cases (Optional)

It will be supplemented later.

Checklist

  1. Pre-commit or other linting tools are used to fix the potential lint issues.
  2. The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  3. If the modification has potential influence on downstream projects, this PR should be tested with downstream projects, like MMDet or MMCls.
  4. The documentation has been modified accordingly, like docstring or example tutorials.

@CLAassistant
Copy link

CLAassistant commented Dec 13, 2022

CLA assistant check
All committers have signed the CLA.

@HAOCHENYE HAOCHENYE changed the title [Feature] support ReduceOnPlateau [Codecamp #28] support ReduceOnPlateau Dec 13, 2022
mmengine/hooks/param_scheduler_hook.py Show resolved Hide resolved
mmengine/hooks/param_scheduler_hook.py Show resolved Hide resolved
mmengine/hooks/param_scheduler_hook.py Outdated Show resolved Hide resolved
mmengine/hooks/param_scheduler_hook.py Outdated Show resolved Hide resolved
mmengine/hooks/param_scheduler_hook.py Outdated Show resolved Hide resolved
mmengine/optim/scheduler/param_scheduler.py Outdated Show resolved Hide resolved
mmengine/optim/scheduler/param_scheduler.py Outdated Show resolved Hide resolved
Comment on lines 1390 to 1393
self._init_is_better(
rule=self.rule,
threshold=self.threshold,
threshold_rule=self.threshold_rule)
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems not necessary to call self._init_is_better here. self.__dict__.update(state_dict) will also update its attributes.

Copy link
Contributor Author

@LEFTeyex LEFTeyex Dec 14, 2022

Choose a reason for hiding this comment

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

It is necessary when the cfg is different from cfg in state_dict.

mmengine/optim/scheduler/param_scheduler.py Outdated Show resolved Hide resolved
mmengine/optim/scheduler/param_scheduler.py Outdated Show resolved Hide resolved
@LEFTeyex LEFTeyex requested review from HAOCHENYE and removed request for RangiLyu and zhouzaida December 14, 2022 08:01
Copy link
Contributor Author

@LEFTeyex LEFTeyex left a comment

Choose a reason for hiding this comment

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

[Fix] fix small bug

@HAOCHENYE HAOCHENYE added this to the 0.5.0 milestone Dec 21, 2022
HAOCHENYE
HAOCHENYE previously approved these changes Jan 9, 2023
HAOCHENYE
HAOCHENYE previously approved these changes Jan 9, 2023
@@ -74,6 +76,72 @@ def test_after_epoch(self):
scheduler2.step = Mock()
scheduler2.by_epoch = True
runner.param_schedulers = dict(key1=[scheduler1], key2=[scheduler2])
hook.after_train_iter(runner, 0)
Copy link
Member

Choose a reason for hiding this comment

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

Is it necessary to call this method here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will del it.

scheduler.need_val_args = True
runner.param_schedulers = scheduler
hook.after_val_epoch(runner, metrics)
scheduler.step.assert_called_with(metrics)
Copy link
Member

Choose a reason for hiding this comment

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

The step method of scheduler will not be called so this line can be moved to make ut clear.

@zhouzaida
Copy link
Member

zhouzaida commented Jan 14, 2023

Hi @LEFTeyex , thanks for your contribution. This PR can be merged after resolving the above comments.

LEFTeyex and others added 3 commits January 15, 2023 11:10
Co-authored-by: Zaida Zhou <58739961+zhouzaida@users.noreply.github.com>
@LEFTeyex
Copy link
Contributor Author

Hi @zhouzaida, I have done.

@zhouzaida zhouzaida merged commit 0b59a90 into open-mmlab:main Jan 16, 2023
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.

None yet

5 participants