Skip to content

Commit 4272b98

Browse files
committed
fix based on feedback
1 parent 82dba6f commit 4272b98

File tree

2 files changed

+1
-8
lines changed

2 files changed

+1
-8
lines changed

src/lightning/pytorch/utilities/parsing.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,6 @@ def save_hyperparameters(
169169
elif is_dataclass(obj):
170170
obj_fields = fields(obj)
171171
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 in `self.hparams`. Consider removing `init=False` and just"
176-
" re-initialize the attributes in the `__post_init__` method of the dataclass."
177-
)
178172
else:
179173
init_args = {}
180174

tests/tests_pytorch/models/test_hparams.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -895,8 +895,7 @@ def __post_init__(self):
895895
super().__init__()
896896
self.save_hyperparameters()
897897

898-
with pytest.warns(UserWarning, match="Detected a dataclass with fields with `init=False`"):
899-
model = DataClassWithInitFalseFieldsModel(33, optional="cocofruit")
898+
model = DataClassWithInitFalseFieldsModel(33, optional="cocofruit")
900899

901900
expected_hparams = {"mandatory": 33, "optional": "cocofruit"}
902901
assert model.hparams == expected_hparams

0 commit comments

Comments
 (0)