facebookresearch / facebookresearch/detectron2

UserWarning: Detected call of `lr_scheduler.step()` before `optimizer.step()`

Open
#4,809 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
Python
Stars
34.7k
Forks
7.9k
PR merge metrics
No merged PRs in 30d

Description

When i run the tools/lazyconfig_train_net.py code, the warning like:
···
python3.9/site-packages/torch/optim/lr_scheduler.py:131: UserWarning: Detected call of `lr_scheduler.step()` before `optimizer.step()`. In PyTorch 1.1.0 and later, you should call them in the opposite order: `optimizer.step()` before `lr_scheduler.step()`. Failure to do this will result in PyTorch skipping the first value of the learning rate schedule. See more details at https://pytorch.org/docs/stable/optim.html#how-to-adjust-learning-rate
warnings.warn("Detected call of `lr_scheduler.step()` before `optimizer.step()`. "
···

I can't find where the code is wrong.

I suspect an error in run_step() in train_loop.AMPTrainer

Contributor guide

Open the contributing guide

Research direction

Start by running tools/lazyconfig_train_net.py and reproducing the warning. Then inspect train_loop.AMPTrainer, especially run_step(), and trace where optimizer.step() and lr_scheduler.step() are called. Done means identifying the call-order source and confirming the warning is resolved without breaking the training loop.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.