mmengine icon indicating copy to clipboard operation
mmengine copied to clipboard

[Bug] `accumulative_counts` does not apply to `parameter_schedulers`

Open HAOCHENYE opened this issue 2 years ago • 4 comments

The accurate cumulative pipeline should be as follows:

    loss = model(data)
    loss.backward()
    if idx % accumulative_counts == 0:
        optimizer.step()
        scheduler.step()
        optimizer.zero_grad()

However, the condition idx % accumulative_counts is only relevant to the OptimWrapper in this context:

https://github.com/open-mmlab/mmengine/blob/a483dba9d15308f9442e87faf80c1d7279137519/mmengine/optim/optimizer/optimizer_wrapper.py#L339

Meanwhile, the schedulers continue to update the learning rate at their original frequency. In this case, the pipeline looks like this:

    loss = model(data)
    loss.backward()
    if idx % accumulative_counts == 0:
        optimizer.step()
        optimizer.zero_grad()
    scheduler.step()

We need to fix this.

HAOCHENYE avatar Aug 15 '23 04:08 HAOCHENYE

Has this been fixed?

Y-T-G avatar Oct 23 '23 09:10 Y-T-G

Does this bug apply if by_epoch=True for param_scheduler?

Y-T-G avatar Oct 23 '23 09:10 Y-T-G

Does this bug apply if by_epoch=True for param_scheduler?

Unfortunately, that's the case. We haven't identified a suitable solution yet, as tightly integrating the functions of OptimWrapper and scheduler isn't advisable.

HAOCHENYE avatar Oct 30 '23 12:10 HAOCHENYE

To modify ParamSchedulerHook?

flytocc avatar Nov 04 '23 17:11 flytocc