-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Closed
Labels
bugSomething isn't workingSomething isn't workinglightningclipl.cli.LightningCLIpl.cli.LightningCLIver: 2.5.x
Description
Bug description
The .hparams attribute of a Lightning(Data)Module should store the hyperparameters passed for its initialization. However, when using the LightningCLI it seems that it stores a dict (config-like) object instead of the instantiated object.
What version are you seeing the problem on?
v2.5
How to reproduce the bug
# litmodel.py
import torch
import lightning as L
from collections.abc import Callable
class Model(L.LightningModule):
def __init__(self, mycallable: Callable):
super().__init__()
self.save_hyperparameters()
print(self.hparams)
exit()
def traininig_step(self, batch, batch_idx):
pass
def configure_optimizers(self):
pass
if __name__ == '__main__':
Model(torch.nn.Identity())# main.py
from lightning.pytorch.cli import LightningCLI
from litmodel import Model
from lightning.pytorch.demos.boring_classes import BoringDataModule
def cli_main():
return LightningCLI(Model, BoringDataModule)
if __name__ == '__main__':
cli_main()# config.yaml
model:
mycallable:
class_path: torch.nn.IdentityError messages and logs
$ python litmodel.py
/home/asarikas/venvir/common/lib/python3.12/site-packages/lightning/pytorch/utilities/parsing.py:209: Attribute 'mycallable' is an instance of `nn.Module` and is already saved during checkpointing. It is recommended to ignore them using `self.save_hyperparameters(ignore=['mycallable'])`.
"mycallable": Identity()
$ python main.py fit -c config.yaml
/home/asarikas/venvir/common/lib/python3.12/site-packages/lightning/fabric/utilities/seed.py:42: No seed found, seed set to 0
Seed set to 0
"_instantiator": lightning.pytorch.cli.instantiate_module
"mycallable": {'class_path': 'torch.nn.Identity'}
Environment
/home/asarikas/temp/lightning_cli_bug/collect_env_details.py:24: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
import pkg_resources
Current environment
- CUDA:
- GPU:
- NVIDIA GeForce RTX 4090
- available: True
- version: 12.4
- GPU:
- Lightning:
- lightning: 2.5.0.post0
- lightning-utilities: 0.11.9
- pytorch-lightning: 2.5.0.post0
- pytorch3d: 0.7.8
- torch: 2.5.1
- torch-geometric: 2.6.1
- torchmetrics: 1.6.1
- torchvision: 0.20.1
- Packages:
- absl-py: 2.1.0
- aenum: 3.1.15
- aidsorb: 1.0.1.dev59+g0187fc7
- aiohappyeyeballs: 2.4.4
- aiohttp: 3.11.11
- aiosignal: 1.3.2
- annotated-types: 0.7.0
- antlr4-python3-runtime: 4.9.3
- anyio: 4.7.0
- argon2-cffi: 23.1.0
- argon2-cffi-bindings: 21.2.0
- arrow: 1.3.0
- ase: 3.23.0
- astroid: 3.3.8
- asttokens: 3.0.0
- async-lru: 2.0.4
- attrs: 24.3.0
- autocommand: 2.2.2
- babel: 2.16.0
- backports.tarfile: 1.2.0
- beautifulsoup4: 4.12.3
- bleach: 6.2.0
- bokeh-sampledata: 2024.2
- certifi: 2024.12.14
- cffi: 1.17.1
- charset-normalizer: 3.4.1
- comm: 0.2.2
- contourpy: 1.3.1
- cycler: 0.12.1
- debugpy: 1.8.11
- decorator: 5.1.1
- defusedxml: 0.7.1
- dill: 0.3.9
- docstring-parser: 0.16
- et-xmlfile: 2.0.0
- executing: 2.1.0
- fastjsonschema: 2.21.1
- filelock: 3.16.1
- fire: 0.7.0
- fonttools: 4.55.3
- fqdn: 1.5.1
- frozenlist: 1.5.0
- fsspec: 2024.12.0
- grpcio: 1.70.0
- h11: 0.14.0
- httpcore: 1.0.7
- httpx: 0.28.1
- hydra-core: 1.3.2
- icalendar: 6.1.0
- idna: 3.10
- importlib-metadata: 8.0.0
- importlib-resources: 6.5.2
- inflect: 7.3.1
- iopath: 0.1.10
- ipykernel: 6.29.5
- ipython: 8.31.0
- ipywidgets: 8.1.5
- isoduration: 20.11.0
- isort: 6.0.0
- jaraco.collections: 5.1.0
- jaraco.context: 5.3.0
- jaraco.functools: 4.0.1
- jaraco.text: 3.12.1
- jedi: 0.19.2
- jinja2: 3.1.5
- joblib: 1.4.2
- json5: 0.10.0
- jsonargparse: 4.37.0
- jsonpointer: 3.0.0
- jsonschema: 4.23.0
- jsonschema-specifications: 2024.10.1
- jupyter-client: 8.6.3
- jupyter-core: 5.7.2
- jupyter-events: 0.11.0
- jupyter-lsp: 2.2.5
- jupyter-server: 2.15.0
- jupyter-server-proxy: 4.4.0
- jupyter-server-terminals: 0.5.3
- jupyterlab: 4.3.4
- jupyterlab-pygments: 0.3.0
- jupyterlab-server: 2.27.3
- jupyterlab-vim: 4.1.4
- jupyterlab-widgets: 3.0.13
- kiwisolver: 1.4.8
- latexcodec: 3.0.0
- lightly: 1.5.19
- lightly-utils: 0.0.2
- lightning: 2.5.0.post0
- lightning-utilities: 0.11.9
- llvmlite: 0.44.0
- markdown: 3.7
- markupsafe: 3.0.2
- matplotlib: 3.10.0
- matplotlib-inline: 0.1.7
- mccabe: 0.7.0
- mistune: 3.1.0
- mofdb-client: 0.10.0
- mofx2csv: 0.1.dev4+g07b461f
- monty: 2025.1.9
- more-itertools: 10.6.0
- mpmath: 1.3.0
- msgpack: 1.1.0
- multidict: 6.1.0
- nbclient: 0.10.2
- nbconvert: 7.16.5
- nbformat: 5.10.4
- nest-asyncio: 1.6.0
- networkx: 3.4.2
- notebook-shim: 0.2.4
- numba: 0.61.0
- numpy: 1.26.4
- nvidia-cublas-cu12: 12.4.5.8
- nvidia-cuda-cupti-cu12: 12.4.127
- nvidia-cuda-nvrtc-cu12: 12.4.127
- nvidia-cuda-runtime-cu12: 12.4.127
- nvidia-cudnn-cu12: 9.1.0.70
- nvidia-cufft-cu12: 11.2.1.3
- nvidia-curand-cu12: 10.3.5.147
- nvidia-cusolver-cu12: 11.6.1.9
- nvidia-cusparse-cu12: 12.3.1.170
- nvidia-nccl-cu12: 2.21.5
- nvidia-nvjitlink-cu12: 12.4.127
- nvidia-nvtx-cu12: 12.4.127
- omegaconf: 2.3.0
- openpyxl: 3.1.5
- overrides: 7.7.0
- packaging: 24.2
- palettable: 3.3.3
- pandas: 2.2.3
- pandocfilters: 1.5.1
- parso: 0.8.4
- pexpect: 4.9.0
- pillow: 11.1.0
- pip: 25.0.1
- platformdirs: 4.3.6
- plotly: 5.24.1
- pooch: 1.8.2
- portalocker: 3.1.1
- prometheus-client: 0.21.1
- prompt-toolkit: 3.0.48
- propcache: 0.2.1
- protobuf: 5.29.3
- psutil: 6.1.1
- ptyprocess: 0.7.0
- pure-eval: 0.2.3
- pybtex: 0.24.0
- pycparser: 2.22
- pycryptodome: 3.21.0
- pydantic: 2.10.6
- pydantic-core: 2.27.2
- pygments: 2.18.0
- pylint: 3.3.4
- pymatgen: 2025.1.9
- pymatviz: 0.15.0
- pymoxel: 0.4.0
- pynndescent: 0.5.13
- pyparsing: 3.2.1
- python-dateutil: 2.9.0.post0
- python-json-logger: 3.2.1
- pytorch-lightning: 2.5.0.post0
- pytorch3d: 0.7.8
- pytz: 2024.2
- pyvista: 0.44.2
- pyyaml: 6.0.2
- pyzmq: 26.2.0
- referencing: 0.35.1
- requests: 2.32.3
- retnext: 0.1.dev1+gef403b0
- rfc3339-validator: 0.1.4
- rfc3986-validator: 0.1.1
- roma: 1.5.1
- rpds-py: 0.22.3
- ruamel.yaml: 0.18.10
- ruamel.yaml.clib: 0.2.12
- scikit-learn: 1.6.1
- scipy: 1.15.0
- scooby: 0.10.0
- seaborn: 0.13.2
- send2trash: 1.8.3
- sentry-sdk: 1.45.1
- setuptools: 78.0.2
- simpervisor: 1.0.0
- six: 1.17.0
- sniffio: 1.3.1
- soupsieve: 2.6
- spglib: 2.5.0
- stack-data: 0.6.3
- stream-inflate: 0.0.41
- stream-unzip: 0.0.99
- sympy: 1.13.1
- tabulate: 0.9.0
- tenacity: 9.0.0
- tensorboard: 2.19.0
- tensorboard-data-server: 0.7.2
- termcolor: 2.5.0
- terminado: 0.18.1
- threadpoolctl: 3.5.0
- tinycss2: 1.4.0
- tomli: 2.0.1
- tomlkit: 0.13.2
- torch: 2.5.1
- torch-geometric: 2.6.1
- torchmetrics: 1.6.1
- torchvision: 0.20.1
- tornado: 6.4.2
- tqdm: 4.67.1
- traitlets: 5.14.3
- trame: 3.8.1
- trame-client: 3.6.1
- trame-server: 3.4.0
- trame-vtk: 2.8.15
- trame-vuetify: 2.9.0
- triton: 3.1.0
- typeguard: 4.3.0
- types-python-dateutil: 2.9.0.20241206
- typeshed-client: 2.7.0
- typing-extensions: 4.12.2
- tzdata: 2024.2
- umap-learn: 0.5.7
- uncertainties: 3.2.2
- uri-template: 1.3.0
- urllib3: 2.3.0
- vtk: 9.3.1
- wcwidth: 0.2.13
- webcolors: 24.11.1
- webencodings: 0.5.1
- websocket-client: 1.8.0
- werkzeug: 3.1.3
- wheel: 0.45.1
- widgetsnbextension: 4.0.13
- wslink: 2.3.3
- xyzservices: 2024.9.0
- yarl: 1.18.3
- zipp: 3.19.2
- System:
- OS: Linux
- architecture:
- 64bit
- ELF
- processor:
- python: 3.12.7
- release: 6.12.4-arch1-1
- version: Proposal for help #1 SMP PREEMPT_DYNAMIC Mon, 09 Dec 2024 14:31:57 +0000
More info
No response
cc @mauvilsa
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workinglightningclipl.cli.LightningCLIpl.cli.LightningCLIver: 2.5.x