File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed
src/lightning/pytorch/utilities Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -167,7 +167,14 @@ def save_hyperparameters(
167167 if given_hparams is not None :
168168 init_args = given_hparams
169169 elif is_dataclass (obj ):
170- init_args = {f .name : getattr (obj , f .name ) for f in fields (obj )}
170+ obj_fields = fields (obj )
171+ init_args = {f .name : getattr (obj , f .name ) for f in obj_fields if f .init }
172+ if any (not f .init for f in obj_fields ):
173+ rank_zero_warn (
174+ "Detected a dataclass with fields with `init=False`. This is not supported by `save_hyperparameters`"
175+ " and will not save those fields. Consider removing `init=False` and just re-initialize the attributes"
176+ " in the `__post_init__` method of the dataclass."
177+ )
171178 else :
172179 init_args = {}
173180
You can’t perform that action at this time.
0 commit comments