pytorch-forecasting icon indicating copy to clipboard operation
pytorch-forecasting copied to clipboard

ValueError: Trainer is already configured with a `LearningRateFinder` callback.Please remove it if you want to use the Tuner.

Open TristanPy opened this issue 7 months ago • 1 comments

When running the notebook "Demand forecasting with the temporal fusion transformer", I cannot run the learning rate optimization.

Notebook code is here at cell [8]: https://github.com/sktime/pytorch-forecasting/blob/main/docs/source/tutorials/stallion.ipynb

# find optimal learning rate
from lightning.pytorch.tuner import Tuner
res = Tuner(trainer).lr_find(
    tft,
    train_dataloaders=train_dataloader,
    val_dataloaders=val_dataloader,
    max_lr=10.0,
    min_lr=1e-6,
)
print(f"suggested learning rate: {res.suggestion()}")
fig = res.plot(show=True, suggest=True)
fig.show()`

I get the folowing error: "ValueError: Trainer is already configured with a LearningRateFinder callback.Please remove it if you want to use the Tuner."

Image

Same unresolved error was mentioned in this StackOverflow link : https://stackoverflow.com/questions/74574988/trainer-already-configured-error-google-tft-temporal-fusion-transformer

TristanPy avatar May 30 '25 11:05 TristanPy

Hi @TristanPy ,

I ran the following code block. It seems to be running fine.


# find optimal learning rate
from lightning.pytorch.tuner import Tuner

res = Tuner(trainer).lr_find(
    tft,
    train_dataloaders=train_dataloader,
    val_dataloaders=val_dataloader,
    max_lr=10.0,
    min_lr=1e-6,
)

print(f"suggested learning rate: {res.suggestion()}")
fig = res.plot(show=True, suggest=True)
fig.show()

Output

Image

lucifer4073 avatar Oct 21 '25 06:10 lucifer4073