Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions docs/source-pytorch/cli/lightning_cli_intermediate_2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,10 @@ If the scheduler you want needs other arguments, add them via the CLI (no need t

.. code:: bash

python main.py fit --optimizer=Adam --lr_scheduler=ReduceLROnPlateau --lr_scheduler.monitor=epoch
python main.py fit --optimizer=Adam --lr_scheduler=ReduceLROnPlateau --lr_scheduler.monitor=train_loss

Furthermore, any custom subclass of ``torch.optim.lr_scheduler.LRScheduler`` can be used as learning rate scheduler:
(assuming you have a ``train_loss`` metric logged). Furthermore, any custom subclass of
``torch.optim.lr_scheduler.LRScheduler`` can be used as learning rate scheduler:

.. code:: python

Expand All @@ -212,7 +213,6 @@ Furthermore, any custom subclass of ``torch.optim.lr_scheduler.LRScheduler`` can
from lightning.pytorch.cli import LightningCLI
from lightning.pytorch.demos.boring_classes import DemoModel, BoringDataModule


class LitLRScheduler(torch.optim.lr_scheduler.CosineAnnealingLR):
def step(self):
print("⚡", "using LitLRScheduler", "⚡")
Expand Down
7 changes: 7 additions & 0 deletions src/lightning/pytorch/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@


class ReduceLROnPlateau(torch.optim.lr_scheduler.ReduceLROnPlateau):
"""Custom ReduceLROnPlateau scheduler that extends PyTorch's ReduceLROnPlateau.

This class adds a `monitor` attribute to the standard PyTorch ReduceLROnPlateau to specify which metric should be
tracked for learning rate adjustment.

"""

def __init__(self, optimizer: Optimizer, monitor: str, *args: Any, **kwargs: Any) -> None:
super().__init__(optimizer, *args, **kwargs)
self.monitor = monitor
Expand Down
Loading