Rename IterableAsDataPipe to IterableWrapper (#63981)
authorErjia Guan <erjia@fb.com>
Thu, 26 Aug 2021 17:21:48 +0000 (10:21 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Thu, 26 Aug 2021 17:23:25 +0000 (10:23 -0700)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/63981

Rename `IterableAsDataPipe` to `IterableWrapper` based on our naming convention `Op-er`

Test Plan: Imported from OSS

Reviewed By: VitalyFedyunin

Differential Revision: D30554197

Pulled By: ejguan

fbshipit-source-id: c2eacb20df5645d83ca165d6a1591f7e4791990f

test/test_dataloader.py
torch/utils/data/dataloader_experimental.py
torch/utils/data/datapipes/iter/__init__.py
torch/utils/data/datapipes/iter/utils.py

index 01136b9e4bb07c5c0b83d5b00a1baa600e95751a..65554632fd30fbd945d27add54ca73dbc7061ac1 100644 (file)
@@ -26,7 +26,7 @@ from torch.utils.data import (
 )
 from torch.utils.data._utils import MP_STATUS_CHECK_INTERVAL
 from torch.utils.data.dataset import random_split
-from torch.utils.data.datapipes.iter import IterableAsDataPipe
+from torch.utils.data.datapipes.iter import IterableWrapper
 from torch._utils import ExceptionWrapper
 from torch.testing._internal.common_utils import (TestCase, run_tests, TEST_NUMPY, IS_WINDOWS,
                                                   IS_IN_CI, NO_MULTIPROCESSING_SPAWN, skipIfRocm, slowTest,
@@ -1963,7 +1963,7 @@ except RuntimeError as e:
 class TestDataLoader2(TestCase):
     @skipIfNoDill
     def test_basics(self):
-        dp = IterableAsDataPipe(list(range(10)))
+        dp = IterableWrapper(list(range(10)))
         dl = DataLoader(dp, batch_size=3, collate_fn=lambda x: x, num_workers=2)
         dl2 = DataLoader2(dp, batch_size=3, collate_fn=lambda x: x, num_workers=2)
         self.assertEquals(list(dl), list(dl2))
index 85028afd22124c847272a895b083e1da8f295ed4..ea085298bf00ff34d200aa341f4c2eb30f71d211 100644 (file)
@@ -3,7 +3,7 @@ import functools
 
 import torch.utils.data.backward_compatibility
 from torch.utils.data import DataLoader, IterDataPipe
-from torch.utils.data.datapipes.iter import IterableAsDataPipe
+from torch.utils.data.datapipes.iter import IterableWrapper
 
 class DataLoader2:
     def __new__(cls,
@@ -69,7 +69,7 @@ class DataLoader2:
             else:
                 if collate_fn is None:
                     collate_fn = torch.utils.data._utils.collate.default_collate
-                datapipe = IterableAsDataPipe(data_loader).batch(
+                datapipe = IterableWrapper(data_loader).batch(
                     batch_size, drop_last=drop_last).map(collate_fn)
                 return datapipe
 
index 5af2ab661da40f84bc18dbf8706279301ea92494..f302fd3a2b7ea3dbf0f492a27917897089b207ee 100644 (file)
@@ -43,7 +43,7 @@ from torch.utils.data.datapipes.iter.ziparchivereader import (
     ZipArchiveReaderIterDataPipe as ZipArchiveReader,
 )
 from torch.utils.data.datapipes.iter.utils import (
-    IterableAsDataPipeIterDataPipe as IterableAsDataPipe,
+    IterableWrapperIterDataPipe as IterableWrapper,
 )
 
 __all__ = ['Batcher',
@@ -55,7 +55,7 @@ __all__ = ['Batcher',
            'FileLoader',
            'Filter',
            'HttpReader',
-           'IterableAsDataPipe',
+           'IterableWrapper',
            'LineReader',
            'Mapper',
            'RoutedDecoder',
index ea241d9f2716ca6c773af74dfd7c261c35ccda74..ee04abc455fba06566d1aa193c019114b92ca766 100644 (file)
@@ -1,10 +1,13 @@
 from torch.utils.data import IterDataPipe
 
 
-class IterableAsDataPipeIterDataPipe(IterDataPipe):
+class IterableWrapperIterDataPipe(IterDataPipe):
     def __init__(self, iterable):
         self.iterable = iterable
 
     def __iter__(self):
         for data in self.iterable:
             yield data
+
+    def __len__(self):
+        return len(self.iterable)