Idea
Idea

Reputation: 1

The Pytorch lightning finds no tuner in lr_find_results=trainer.tuner.lr_find

I'm working on using PyTorch Lightning to train a neural network with a DataLoader. I have installed PyTorch and PyTorch Lightning successfully. However, I am encountering an issue with the learning rate finder (lr_find).

Here's an inline link to google collab [https://colab.research.google.com/drive/1nZDozOXunlibCmQfRHw1JSDHSTYEmdoC?authuser=0#scrollTo=5no2Y6ngEcjT]

model= BasicLightningTrain()
trainer=L.Trainer(max_epochs=34)

lr_find_results=trainer.tuner.lr_find(model,
                                  train_dataloaders=dataloader,
                                  min_lr=0.001,
                                  max_lr=1.0,
                                  early_stop_threshold=None)

Here's an inline link to google collab [https://colab.research.google.com/drive/1nZDozOXunlibCmQfRHw1JSDHSTYEmdoC?authuser=0#scrollTo=5no2Y6ngEcjT]

model= BasicLightningTrain()
trainer=L.Trainer(max_epochs=34)

lr_find_results=trainer.tuner.lr_find(model,
                                  train_dataloaders=dataloader,
                                  min_lr=0.001,
                                  max_lr=1.0,
                                  early_stop_threshold=None)

Error:

AttributeError: 'Trainer' object has no attribute 'tuner'

I am getting an AttributeError: 'Trainer' object has no attribute 'tuner'. How can I resolve this issue and correctly use the learning rate finder with PyTorch Lightning?

Upvotes: 0

Views: 229

Answers (1)

Soumyadip Ghorai
Soumyadip Ghorai

Reputation: 11

With the release of Lightning 2.0, the approach to accessing the learning rate tuner has been updated. Here's how you can use the new API:

model = BasicLightningTrain()
trainer = L.Trainer(max_epochs=34)
 
tuner = L.pytorch_tuner.Tuner(trainer)
lr_find_results = tuner.lr_find(
    model, train_dataloaders = dataloader, min_lr = 0.001,
    max_lr = 1.0, early_stop_threshold = None
)

# Optionally, you can visualize the learning rate finder results
fig = lr_find_results.plot()
fig.show()

Key Points:

  • Tuner Setup: Use L.pytorch_tuner.Tuner to initialize the tuner.
  • Visualization: Use the plot() method to visualize the results if needed.

Feel free to ask if you have any questions or need further assistance!

Upvotes: 1

Related Questions