code-generator icon indicating copy to clipboard operation
code-generator copied to clipboard

fix lr scheduler warning in segmentation template

Open ydcjeff opened this issue 3 years ago • 0 comments

Describe the bug

Following warning is shown in the CI: step-504

/opt/hostedtoolcache/Python/3.6.13/x64/lib/python3.6/site-packages/torch/optim/lr_scheduler.py:134:

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

Reproduction

https://github.com/pytorch-ignite/code-generator/tree/main/src/templates/template-vision-segmentation

Steps to reproduce

python main.py \
  --data_path <path_to_dataset> \
  --train_batch_size 4 \
  --eval_batch_size 4 \
  --num_workers 2 \
  --max_epochs 2 \
  --train_epoch_length 4 \
  --eval_epoch_length 4

Expected result

No warning to show.

Environment info

Output of python -m torch.utils.collect_env:

OS: Linux
torch: 1.9.0
torchvision: 0.10.0
ignite: 0.4.5

If you like to tackle this issue, please comment that you want to work on and see the contributing guide.

ydcjeff avatar Jul 09 '21 07:07 ydcjeff