Skip to content

Commit

Permalink
Forward fix / Update dill_available API for torchdata (#1222)
Browse files Browse the repository at this point in the history
Summary:

Changes from the PyTorch repo (D53082622) broke torchdata. I updated the dill_available API for torchdata to keep everything in sync.

Differential Revision: D53086369
  • Loading branch information
DanilBaibak authored and facebook-github-bot committed Jan 25, 2024
1 parent d727f63 commit c2fdc2d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
8 changes: 4 additions & 4 deletions test/test_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
import torchdata.datapipes.iter as iterdp
import torchdata.datapipes.map as mapdp
from _utils._common_utils_for_test import create_temp_dir, create_temp_files
from torch.utils.data.datapipes.utils.common import DILL_AVAILABLE
from torch.utils._import_utils import dill_available
from torchdata.datapipes.iter import IterableWrapper
from torchdata.datapipes.map import SequenceWrapper

if DILL_AVAILABLE:
if dill_available():
import dill

dill.extend(use_dill=False)
Expand Down Expand Up @@ -87,7 +87,7 @@ def _filter_by_module_availability(datapipes):
filter_set.update([iterdp.IoPathFileLister, iterdp.IoPathFileOpener, iterdp.IoPathSaver])
if rarfile is None:
filter_set.update([iterdp.RarArchiveLoader])
if torcharrow is None or not DILL_AVAILABLE:
if torcharrow is None or not dill_available():
filter_set.update([iterdp.DataFrameMaker, iterdp.ParquetDataFrameLoader])
return [dp for dp in datapipes if dp[0] not in filter_set]

Expand Down Expand Up @@ -374,7 +374,7 @@ def test_serializable_with_dill(self) -> None:
# Skipping value comparison for these DataPipes
dp_skip_comparison = {iterdp.OnDiskCacheHolder, iterdp.ParagraphAggregator}
for dpipe, dp_args, dp_kwargs in unpicklable_datapipes:
if DILL_AVAILABLE:
if dill_available():
try:
if dpipe in dp_skip_comparison: # Make sure they are picklable/loadable (no value comparison)
datapipe = dpipe(input_dp, *dp_args, **dp_kwargs) # type: ignore[call-arg]
Expand Down
5 changes: 3 additions & 2 deletions torchdata/datapipes/iter/util/cacheholder.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
except ImportError:
portalocker = None

from torch.utils.data.datapipes.utils.common import _check_unpickable_fn, DILL_AVAILABLE
from torch.utils._import_utils import dill_available
from torch.utils.data.datapipes.utils.common import _check_unpickable_fn

from torch.utils.data.graph import traverse_dps
from torchdata.datapipes import functional_datapipe
from torchdata.datapipes.iter import IterableWrapper, IterDataPipe

if DILL_AVAILABLE:
if dill_available():
import dill

dill.extend(use_dill=False)
Expand Down
10 changes: 6 additions & 4 deletions torchdata/datapipes/iter/util/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@

from typing import Callable, Dict, Optional

from torch.utils._import_utils import dill_available

from torch.utils.data import IterDataPipe, MapDataPipe
from torch.utils.data.datapipes.utils.common import _check_unpickable_fn, DILL_AVAILABLE
from torch.utils.data.datapipes.utils.common import _check_unpickable_fn

if DILL_AVAILABLE:
if dill_available():
import dill

dill.extend(use_dill=False)
Expand Down Expand Up @@ -108,7 +110,7 @@ def __len__(self):
return len(self._map) # type: ignore[arg-type]

def __getstate__(self):
if DILL_AVAILABLE:
if dill_available():
dill_key_value_fn = dill.dumps(self.key_value_fn)
else:
dill_key_value_fn = self.key_value_fn
Expand All @@ -120,7 +122,7 @@ def __getstate__(self):

def __setstate__(self, state):
(self.datapipe, dill_key_value_fn, self._map) = state
if DILL_AVAILABLE:
if dill_available():
self.key_value_fn = dill.loads(dill_key_value_fn) # type: ignore[assignment]
else:
self.key_value_fn = dill_key_value_fn # type: ignore[assignment]
Expand Down
8 changes: 4 additions & 4 deletions torchdata/datapipes/iter/util/dataframemaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from functools import partial
from typing import List, Optional, TypeVar

from torch.utils.data.datapipes.utils.common import DILL_AVAILABLE
from torch.utils._import_utils import dill_available

from torchdata.datapipes import functional_datapipe
from torchdata.datapipes.iter import IterDataPipe
Expand All @@ -19,7 +19,7 @@
torcharrow = None
parquet = None

if DILL_AVAILABLE:
if dill_available():
import dill

dill.extend(use_dill=False)
Expand Down Expand Up @@ -150,7 +150,7 @@ def __iter__(self):
yield torcharrow.from_arrow(row_group, dtype=self.dtype)

def __getstate__(self):
if DILL_AVAILABLE:
if dill_available():
dill_dtype = dill.dumps(self.dtype)
else:
dill_dtype = self.dtype
Expand All @@ -161,7 +161,7 @@ def __getstate__(self):

def __setstate__(self, state):
(self.source_dp, dill_dtype, self.columns, self.device, self.use_threads) = state
if DILL_AVAILABLE:
if dill_available():
self.dtype = dill.loads(dill_dtype) # type: ignore[assignment]
else:
self.dtype = dill_dtype # type: ignore[assignment]

0 comments on commit c2fdc2d

Please sign in to comment.