Skip to content
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

LightningCLI does not recognize arguments when importing annotations from __future__ #15741

Closed
rusmux opened this issue Nov 19, 2022 · 3 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists lightningcli pl.cli.LightningCLI

Comments

@rusmux
Copy link
Contributor

rusmux commented Nov 19, 2022

Bug description

I'm using Python 3.8 and to make it compatible with annotations from Python 3.9, I do an import:

from __future__ import annotations

But with this import, the LightningCLI gives me an error that my arguments are not recognized. Neither from the CLI nor from the yaml configuration files. See the minimal example below.

I've spent several days trying to figure out what the problem is.

How to reproduce the bug

"""Run ``--help`` on this script with and without commenting the import.
When importing, there is no ``path`` argument in the model section.
"""

# from __future__ import annotations

from pytorch_lightning.cli import LightningCLI
from pytorch_lightning import LightningModule


class Model(LightningModule):

    def __init__(self, path: str) -> None:
        super().__init__()


if __name__ == "__main__":
    LightningCLI(Model)

Error messages and logs

Without import:

<class '__main__.Model'>:
  --model CONFIG        Path to a configuration file.
  --model.path PATH     (required, type: str)

With import:

<class '__main__.Model'>:
  --model CONFIG        Path to a configuration file.

Environment

Lightning Component: LightningCLI
PyTorch Lightning Version: 1.8.2
PyTorch Version: 1.12.1
Python version: 3.8
OS: MacOS
How you installed Lightning: pip

More info

No response

cc @carmocca @mauvilsa

@rusmux rusmux added the needs triage Waiting to be triaged by maintainers label Nov 19, 2022
@awaelchli awaelchli added bug Something isn't working lightningcli pl.cli.LightningCLI and removed needs triage Waiting to be triaged by maintainers labels Nov 20, 2022
@awaelchli awaelchli added this to the v1.8.x milestone Nov 20, 2022
@carmocca carmocca removed this from the v1.8.x milestone Nov 20, 2022
@carmocca carmocca closed this as not planned Won't fix, can't repro, duplicate, stale Nov 20, 2022
@carmocca
Copy link
Contributor

Thanks for reporting! This is a known issue and is tracked in omni-us/jsonargparse#120 already. Closing this as a duplicate

@carmocca carmocca added the duplicate This issue or pull request already exists label Nov 20, 2022
@mauvilsa
Copy link
Contributor

mauvilsa commented Jun 6, 2023

@rusmux support for future annotations in jsonargparse has been implemented, but not yet released, see omni-us/jsonargparse#294. Can you please try it out? Just install as:

pip3 install "jsonargparse[signatures] @ https://github.com/omni-us/jsonargparse/zipball/future-annotations"

@rusmux
Copy link
Contributor Author

rusmux commented Jun 6, 2023

@mauvilsa It's working on my machine. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists lightningcli pl.cli.LightningCLI
Projects
None yet
Development

No branches or pull requests

4 participants