-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Closed
Labels
featureIs an improvement or enhancementIs an improvement or enhancementhelp wantedOpen to be worked onOpen to be worked onpriority: 2Low priority taskLow priority task
Milestone
Description
Python Data Classes are convenient in that they automatically generate a bunch of boilerplate code for assigning data to a class. They are particularly useful for PyTorch models that have a lot of hyperparameters and thus a lot of boilerplate.
🐛 Bug
I believe #1896 introduced a new bug: when using a data class, save_hyperparameters no longer works since it depends on init args and we instead use __post_init__ with dataclasses. Explicitly passing strings does not work either. Perhaps when passing
Code sample
import pytorch_lightning as pl
from dataclasses import dataclass
@dataclass()
class ConvDecoder(pl.LightningModule):
imageChannels:int = 3
def __post_init__(self):
super().__init__()
# both fail
# self.save_hyperparameters()
self.save_hyperparameters('imageChannels')
model = ConvDecoder()
model.hparamsExpected behavior
There should be a way to use save_hyperparameters with Data Classes
awaelchli, hadim, kolakows, kainoj and gautierdag
Metadata
Metadata
Assignees
Labels
featureIs an improvement or enhancementIs an improvement or enhancementhelp wantedOpen to be worked onOpen to be worked onpriority: 2Low priority taskLow priority task