Skip to content

Commit f473428

Browse files
committed
Replace __reduce__ with __getstate__
1 parent 9c3103a commit f473428

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

pytorch_lightning/core/datamodule.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -326,11 +326,8 @@ def test_dataloader():
326326
datamodule.test_dataloader = test_dataloader
327327
return datamodule
328328

329-
def __new__(cls, *args: Any, **kwargs: Any) -> 'LightningDataModule':
329+
def __new__(cls, *_: Any, **__: Any) -> 'LightningDataModule':
330330
obj = super().__new__(cls)
331-
# save `args` and `kwargs` for `__reduce__`
332-
obj.__args = args
333-
obj.__kwargs = kwargs
334331
# track `DataHooks` calls and run `prepare_data` only on rank zero
335332
obj.prepare_data = cls._track_data_hook_calls(obj, rank_zero_only(obj.prepare_data))
336333
obj.setup = cls._track_data_hook_calls(obj, obj.setup)
@@ -381,6 +378,9 @@ def wrapped_fn(*args: str, **kwargs: Optional[str]) -> Any:
381378

382379
return wrapped_fn
383380

384-
def __reduce__(self) -> Tuple[type, tuple, dict]:
381+
def __getstate__(self) -> dict:
385382
# avoids _pickle.PicklingError: Can't pickle <...>: it's not the same object as <...>
386-
return self.__class__, self.__args, self.__kwargs
383+
d = self.__dict__.copy()
384+
for fn in ("prepare_data", "setup", "teardown"):
385+
del d[fn]
386+
return d

0 commit comments

Comments
 (0)