LightningCLI does not overwrite optimizer defined in LightningModule #12759
Labels
bug
Something isn't working
lightningcli
pl.cli.LightningCLI
waiting on author
Waiting on user action, correction, or update
Uh oh!
There was an error while loading. Please reload this page.
🐛 Bug
Hi,
First of all, thanks for the great work creating pytorch lightning. Lately I've been using the LightningCLI functionality and it really cut down a lot of boilerplate code and made the CLI easier to use. So thanks for that!
Unfortunately I found one detail where I either don't understand the documentation well, or the behaviour is not as intended: the optimizer defined in configuration file does not seem to overwrite one defined in
LightningModule. configure_optimizers
.To Reproduce
Initially I used a hardcoded optimizer and scheduler defined in my LightningModule, like:
Then I decided I wanted to change to a different optimizer, so I added the following to the config I pass in to the LightningCLI:
A dummy example of the script I run:
When running the code
python cli.py fit --config my_config.yaml
I get the following warning:so I, incorrectly, assumed it would take the optimizer from the config, and either take the scheduler from my model's method, or no/a default scheduler. Instead, it seems to have just taken both the optimizer and the scheduler from my model's method. Is this intended? If so, should the documentation of LightningCLI regarding optimizers and schedulers be expanded to clarify this?
Small detail: the reason I assume the optimizer isn't being overwritten, is because
LearningRateMonitor
is still logging the learning rate of the optimize defined in the LightningModule, so I guess there is a chance the training is happening with the new optimizer, but the callback is logging the wrong optimizer.Expected behavior
Overwrite the optimizer and scheduler from the LightningModule with whatever is provided from the config file, even if it's only the optimizer, or only the scheduler.
Environment
conda
,pip
, source): pipThanks!
cc @carmocca @mauvilsa
The text was updated successfully, but these errors were encountered: