Lightning-AI / Lightning-AI/pytorch-lightning

Learning Rate finder too strong loss smoothing

Open
#14,167 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

feature tuner
Dominant language
Python
Stars
31.4k
Forks
3.8k
Avg merge
6d 7h
Merged PRs (30d)
6

Description

### Discussed in https://github.com/Lightning-AI/lightning/discussions/13404

Originally posted by **hcgasser** June 24, 2022
The learning rate finder slowly increases the learning rate during its search process and records how the loss reacts to it. My understanding is that in theory, it is supposed to stay quite constant at the beginning and then decrease before a too high learning rate leads to divergence.

However, in the callback method _LRCallback.on_batch_end, a smoothed loss is calculated (link below). The problem here is in my opinion, that the smoothing starts with an initial self.avg_loss of zero. This leads to the counterintuitive behavior that the loss increases at first with learning rate. if the number of tested learning rates is low, this can actually be the case for a wide range of learning rate values - in particular as the standard beta value is set very high (high weight to past).

I think, the self.avg_loss value should be set to the initial value of the un-smoothed loss at the beginning instead of zero. What do you think?

Thank you for looking into this

https://github.com/Lightning-AI/lightning/blob/b84b02400a312240a6429c186cc63514eeb45a82/pytorch_lightning/trainer/lr_finder.py#L374

cc @borda @akihironitta @rohitgr7

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read the _LRCallback.on_batch_end implementation in pytorch_lightning/trainer/lr_finder.py around the linked line, focusing on how avg_loss is initialized and updated. Reproduce the learning-rate finder behavior with a small range of tested rates, then verify that loss smoothing no longer introduces an initial artificial increase.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.