mmcv icon indicating copy to clipboard operation
mmcv copied to clipboard

[Fix] Fix gradient cumulative optimizer when resuming

Open shinya7y opened this issue 3 years ago • 1 comments

Motivation

Fix https://github.com/open-mmlab/mmcv/issues/2083

Modification

  • Fix the issue
  • Eliminate the calculation of residual_iters to avoid complicated implementation of mmcv/runner/hooks/optimizer.py and unit tests (I think the logic has another bug because every_n_iters has not been modified for it.)
  • Put the same code into _get_loss_factor

BC-breaking (Optional)

Since the bug causes wrong loss, models trained by simultaneous use of GradientCumulativeOptimizerHook and resume will show different results before and after this PR.

Checklist

Before PR:

  • [x] I have read and followed the workflow indicated in the CONTRIBUTING.md to create this PR.
  • [x] Pre-commit or linting tools indicated in CONTRIBUTING.md are used to fix the potential lint issues.
  • [x] Bug fixes are covered by unit tests, the case that causes the bug should be added in the unit tests.
  • [x] New functionalities are covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  • [x] The documentation has been modified accordingly, including docstring or example tutorials.

After PR:

  • [x] If the modification has potential influence on downstream or other related projects, this PR should be tested with some of those projects, like MMDet or MMCls.
  • [x] CLA has been signed and all committers have signed the CLA in this PR.

shinya7y avatar Jul 01 '22 18:07 shinya7y

Thanks for your contribution! LGTM~

HAOCHENYE avatar Jul 02 '22 16:07 HAOCHENYE