How to pass a type(not an object) to a class with lightningcli? #14552
Answered
by
tshu-w
calvinzhan
asked this question in
Lightning Trainer API: Trainer, LightningModule, LightningDataModule
-
I want to pass a type(not an object) to a subclass of LightningDataModule. I did the following, but it seemed lightningcli tried to initialize an object and complain required fileds were missing. How can I do that?
in yaml
|
Beta Was this translation helpful? Give feedback.
Answered by
tshu-w
Sep 6, 2022
Replies: 2 comments 1 reply
-
I don't know why I couldn't set label for my discussion. |
Beta Was this translation helpful? Give feedback.
0 replies
-
You can change Here is a demo: from typing import Type
from jsonargparse import CLI
class Class1:
def __init__(self) -> None:
print("Class1")
class Class2:
def __init__(self) -> None:
print("Class2")
def test_fn(
class_type: Type = Class1,
):
print(class_type)
class_type()
if __name__ == "__main__":
CLI(test_fn) python test.py --class_type '__main__.Class2' |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
calvinzhan
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can change
domain_dataset
type hint fromDataset
toType
:Here is a demo:
python test.py --class_type '__main__.Class2'