Lightning-AI/pytorch-lightning

`lr_finder` fails when called after training for 1 or more epochs

Open

#4 846 ouverte le 25 nov. 2020

Voir sur GitHub
 (15 commentaires) (0 réactions) (0 assignés)Python (3 233 forks)batch import
bughelp wantedpriority: 1tuner

Métriques du dépôt

Stars
 (26 687 stars)
Métriques de merge PR
 (Merge moyen 9j 15h) (3 PRs mergées en 30 j)

Description

🐛 Bug

Calling lr_finder on the model after trainer.fit() has been called will fail with:

LR finder stopped early due to diverging loss.
Failed to compute suggesting for `lr`. There might not be enough points.

, even when the default value of min_lr=1e-08 has been changed to 1e-30.

Please reproduce using the BoringModel and post here

To Reproduce

Add the following callback (as demonstrated with the BoringModel):

# Call Learning Rate finder after X epochs
class LRFinderXEpoch(Callback):
    def __init__(self, epoch=1):
        super().__init__()
        
        self.epoch = epoch
    
    def on_train_epoch_start(self, trainer, pl_module):
        if trainer.current_epoch == self.epoch:
            print("Calling learning rate finder!")
            trainer.tune(pl_module)
            # trainer.tuner.lr_find(pl_module, min_lr=1e-30)

Expected behavior

Find the best learning rate after a few epochs of training (e.g. when doing Transfer Learning).

Environment

* CUDA:
	- GPU:
		- Tesla T4
	- available:         True
	- version:           10.1
* Packages:
	- numpy:             1.18.5
	- pyTorch_debug:     True
	- pyTorch_version:   1.7.0+cu101
	- pytorch-lightning: 1.0.8
	- tqdm:              4.41.1
* System:
	- OS:                Linux
	- architecture:
		- 64bit
		- 
	- processor:         x86_64
	- python:            3.6.9
	- version:           #1 SMP Thu Jul 23 08:00:38 PDT 2020

Additional context

Issue came from the following discussion: https://forums.pytorchlightning.ai/t/train-2-epochs-head-unfreeze-learning-rate-finder-continue-training-fit-one-cycle/366/4

Potentially related issues:

Guide contributeur