---
title: LearningRateFinder
description: >-
  The LearningRateFinder callback enables the user to do a range test of good
  initial learning rates, to

  reduce the amount of guesswork in picking a good starting learning rate.
canonical: >-
  https://lightning.ai/docs/pytorch/stable/optional-api/api/lightning.pytorch.callbacks.LearningRateFinder
---
# LearningRateFinder {#learningratefinder}

### `class lightning.pytorch.callbacks.LearningRateFinder(min_lr=1e-08, max_lr=1, num_training_steps=100, mode='exponential', early_stop_threshold=4.0, update_attr=True, attr_name='')` {#lightning.pytorch.callbacks.LearningRateFinder}

Bases: [`Callback`](/docs/pytorch/2.6.6/optional-api/api/lightning.pytorch.callbacks.Callback.md#lightning.pytorch.callbacks.Callback "lightning.pytorch.callbacks.callback.Callback")

The `LearningRateFinder` callback enables the user to do a range test of good initial learning rates, to reduce the amount of guesswork in picking a good starting learning rate.

Warning

This is an [experimental](/docs/pytorch/2.6.6/reference/versioning.md#experimental-api) feature.

Parameters:

*   **min\_lr** ([`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)")) – Minimum learning rate to investigate
    
*   **max\_lr** ([`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)")) – Maximum learning rate to investigate
    
*   **num\_training\_steps** ([`int`](https://docs.python.org/3/builtins/functions.html#int "(in Python v3.15)")) – Number of learning rates to test
    
*   **mode** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)")) –
    
    Search strategy to update learning rate after each batch:
    
    *   `'exponential'` (default): Increases the learning rate exponentially.
        
    *   `'linear'`: Increases the learning rate linearly.
        
    
*   **early\_stop\_threshold** ([`Optional`](https://docs.python.org/3/library/typing.html#typing.Optional "(in Python v3.15)")\[[`float`](https://docs.python.org/3/builtins/functions.html#float "(in Python v3.15)")\]) – Threshold for stopping the search. If the loss at any point is larger than early\_stop\_threshold\*best\_loss then the search is stopped. To disable, set to None.
    
*   **update\_attr** ([`bool`](https://docs.python.org/3/builtins/functions.html#bool "(in Python v3.15)")) – Whether to update the learning rate attribute or not.
    
*   **attr\_name** ([`str`](https://docs.python.org/3/builtins/stdtypes.html#str "(in Python v3.15)")) – Name of the attribute which stores the learning rate. The names ‘learning\_rate’ or ‘lr’ get automatically detected. Otherwise, set the name here.
    

Example:

```python
# Customize LearningRateFinder callback to run at different epochs.
# This feature is useful while fine-tuning models.
from lightning.pytorch.callbacks import LearningRateFinder


class FineTuneLearningRateFinder(LearningRateFinder):
    def __init__(self, milestones, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.milestones = milestones

    def on_fit_start(self, *args, **kwargs):
        return

    def on_train_epoch_start(self, trainer, pl_module):
        if trainer.current_epoch in self.milestones or trainer.current_epoch == 0:
            self.lr_find(trainer, pl_module)


trainer = Trainer(callbacks=[FineTuneLearningRateFinder(milestones=(5, 10))])
trainer.fit(...)
```

Raises:

**MisconfigurationException** – If learning rate/lr in `model` or `model.hparams` isn’t overridden, or if you are using more than one optimizer.

#### `on_fit_start(trainer, pl_module)` {#lightning.pytorch.callbacks.LearningRateFinder.on_fit_start}

Called when fit begins.

Return type:

[`None`](https://docs.python.org/3/builtins/constants.html#None "(in Python v3.15)")

---

**Navigation**

- Parent: [Api](/docs/pytorch/2.6.6/optional-api/api.md)
