-
Notifications
You must be signed in to change notification settings - Fork 3.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
With yaml config file for LightningCLI, self.save_hyperparameters()
behavior abnormal
#19977
Comments
We're seeing this too, this broke all of TorchGeo's tests: https://github.com/microsoft/torchgeo/actions/runs/9522133755/job/26251028463?pr=2119 |
+1 |
We are seeing this as well IBM/terratorch#26 As far as I can tell it stems from #19771 which (inadvertedly?) affects the LightningCLI parser |
Still broken in 2.3.1, still preventing TorchGeo from supporting newer versions of Lightning. |
Still broken in 2.3.2. |
I checked the commits before and after, but it's broken before and after, so I think this PR is unrelated. |
Thanks for the steps to reproduce @t4rf9! Note that I would also like to add one other file from lightning.pytorch import Trainer
from model import Model
from datamodule import DataModule
if __name__ == "__main__":
model = Model(learning_rate=1e-2)
datamodule = DataModule(data_dir='data')
trainer = Trainer()
trainer.fit(model=model, datamodule=datamodule) By running this, you'll see that the extra |
I tracked down the source of the bug as follows. config.yaml model:
class_path: model.Model
init_args:
learning_rate: 1e-2
data:
class_path: lightning.pytorch.demos.boring_classes.BoringDataModule
trainer:
fast_dev_run: true main.py from lightning.pytorch.cli import LightningCLI
def cli_main():
cli = LightningCLI()
if __name__ == '__main__':
cli_main() model.py from lightning.pytorch import LightningModule
class Model(LightningModule):
def __init__(self, learning_rate):
super().__init__()
self.save_hyperparameters()
assert 'learning_rate' in self.hparams
def training_step(*args):
pass
def configure_optimizers(*args):
pass Then run: > git bisect start
> git checkout 2.2.0
> git bisect good
> git checkout 2.3.0
> git bisect bad
> git bisect run python3 main.py fit --config config.yaml This reported that the bug first appears in #18105. Pinging everyone involved in that PR: @mauvilsa @awaelchli @carmocca @Borda |
I suppose in #18105 we didn't notice how this could potentially break things. But I think it can be easily fixed. I will create a pull request for it tomorrow. |
Created a pull request #20068. @t4rf9, @adamjstewart, please test it out. |
Bug description
With yaml config file for LightningCLI,
self.save_hyperparameters()
in__init__
of the model and datamodule mistakenly saves adict
containing keys likeclass_path
andinit_args
.This problems appears in version 2.3.0, but version 2.2.5 works correctly.
What version are you seeing the problem on?
2.3.0
How to reproduce the bug
config.yaml
model.py
datamodule.py
main.py
Run
python main.py fit --config config.yaml
#- Lightning Component (e.g. Trainer, LightningModule, LightningApp, LightningWork, LightningFlow):
#- PyTorch Lightning Version (e.g., 1.5.0):
#- Lightning App Version (e.g., 0.5.2):
#- PyTorch Version (e.g., 2.0):
#- Python version (e.g., 3.9):
#- OS (e.g., Linux):
#- CUDA/cuDNN version:
#- GPU models and configuration:
#- How you installed Lightning(
conda
,pip
, source):#- Running environment of LightningApp (e.g. local, cloud):
The text was updated successfully, but these errors were encountered: