-
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
make DataModule compatible with Python dataclass #8272
Comments
Hi, I would like to work on this issue, could you please assign it to me? |
Hey! Yes, you can take it if you want. I haven't really had the time to look why it is not working. I don't know how difficult it would be. |
Hey, Is there any slack or discord server I could join to ask my queries? |
Yes, feel free to join the PyTorch Lightning slack: https://join.slack.com/t/pytorch-lightning/shared_invite/zt-pw5v393p-qRaDgEk24~EjiZNBpSQFgQ |
|
Oh yes, but actually we want dataclass to generate an init for us. Otherwise we don't get any great value of a dataclass here. def __post_init__(self):
super().__init__() Because the init generated by dataclass does not call |
@awaelchli @QueshAnmak For a custom datamodule should @dataclass
class MyDataModule(LightningDataModule):
x: int = 32
...
def __post_init_(self):
super().__init__()
self.save_hyperparameters() Currently, The following example demonstrates that with the from dataclasses import dataclass
import lightning as L
class Foo(L.LightningDataModule):
def __init__(self, x=1, y=2):
super().__init__()
self.y = 'hello'
self.save_hyperparameters()
@dataclass
class Bar(L.LightningDataModule):
x: int = 1
y: int = 2
def __post_init__(self):
super().__init__()
self.y = 'hello'
self.save_hyperparameters()
foo = Foo()
print(foo.hparams)
bar = Bar()
print(bar.hparams) # Output
"x": 1
"y": 2
"x": 1
"y": hello |
🚀 Feature
Support the following:
Motivation
To reduce boilerplate code is at the core of philosophy in Lightning. It should be compatible with dataclasses.
Code sample
Here is an example. It currently does not work as we have some internal attributes that don't play well with the dataclass.
Alternatives
#3792 introduces
save_hyperparameters()
for the datamodule. However, I believe the dataclass approach here is not in conflict with that because both could be useful at the same time.The text was updated successfully, but these errors were encountered: