mmcv
mmcv copied to clipboard
[Fix] Fix gradient cumulative optimizer when resuming
Motivation
Fix https://github.com/open-mmlab/mmcv/issues/2083
Modification
- Fix the issue
- Eliminate the calculation of
residual_itersto avoid complicated implementation ofmmcv/runner/hooks/optimizer.pyand unit tests (I think the logic has another bug becauseevery_n_itershas 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.
Thanks for your contribution! LGTM~