Lightning-AI/pytorch-lightning

Support for returning LRSchedulerConfig on LightningModule.configure_optimizers

Open

#18.870 geöffnet am 26. Okt. 2023

Auf GitHub ansehen
 (1 Kommentar) (0 Reaktionen) (0 zugewiesene Personen)Python (3.233 Forks)batch import
featurehelp wantedlightningmodulelr scheduler

Repository-Metriken

Stars
 (26.687 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 9T 15h) (3 gemergte PRs in 30 T)

Beschreibung

Description & Motivation

This is a re-proposal for #13569. At that time, this feature is considered to be discouraged since LRSchedulerConfig is supposed to be an "internal structure" (according to this comment). However, as #18463 adds type hints for the returns of configure_optimizers (also can be found in the current documentation), one of them is Tuple[Sequence[Optimizer], Sequence[Union[LRScheduler, ReduceLROnPlateau, LRSchedulerConfig]]], indicating that returning LRSchedulerConfig should be supported now.

According to my personal experience, I find returning LRSchedulerConfig handy, and I hope this feature could be supported, instead of revising the type hints. Thanks!

Pitch

The suggestion proposed in #13569 still should work, i.e., adding the following two lines to _configure_schedulers_automatic_opt:

...
elif isinstance(scheduler, LRSchedulerConfig):
    config = scheduler
...

Alternatives

No response

Additional context

No response

cc @borda @carmocca @justusschock @awaelchli

Contributor Guide