Repository: Lightning-AI/pytorch-lightning

Issue:
IterableDataset breaks 1.1 compatibility
A recently introduced feature unfortunately breaks compability with Pytorch 1.1.0. 

**Describe the bug**
IterableDataset support, introduced in [issue 323](https://github.com/williamFalcon/pytorch-lightning/issues/323), requires Pytorch 1.2.0+.    

**To Reproduce**
In a python environment with Pytorch 1.1.0 do:
import pytorch_lightning

**Expected behavior**
Compatibility with Pytorch 1.1.0. I'm filing it as a bug report rather than a docs fix since the dependency on 1.2.0+ introduced by [issue 323](https://github.com/williamFalcon/pytorch-lightning/issues/323) doesn't seem to be intentional.





Discussion:
good catch. mind submitting a PR? was not the intention of that fix :)

We want to support 1.1
I have played with versions and it seems to me that it does not run even with 1.2.0; see #462
weird. let’s patch it and make a nee release? in the meantime, put a note on the readme to use 0.5.2.1 if you need pt 1.1 or 1.2 support?
you may rather change requirements.txt and after fix put it back...
I see that >=1.2.0 is there already for some time... 8-)
Is this already fixed? I see that torch 1.2.0 is already in requirements.txt ?
I think not yet...8-)
Do you suggest torch 1.3.0 ? 
we need to support 1.2.0 :)
@Borda did we get this fixed? is PT 1.2 supported now? If not, what do we need to do?
I have not worked on it yet (bit busy with docs), hopefully this week... 

Resolving patch:
diff --git a/pytorch_lightning/trainer/data_loading_mixin.py b/pytorch_lightning/trainer/data_loading_mixin.py
--- a/pytorch_lightning/trainer/data_loading_mixin.py
+++ b/pytorch_lightning/trainer/data_loading_mixin.py
@@ -1,7 +1,17 @@
 import warnings
 
 import torch.distributed as dist
-from torch.utils.data import IterableDataset
+try:
+    # loading for pyTorch 1.3
+    from torch.utils.data import IterableDataset
+except ImportError:
+    # loading for pyTorch 1.1
+    import torch
+    warnings.warn('Your version of pyTorch %s does not support `IterableDataset`,'
+                  ' please upgrade to 1.2+' % torch.__version__, ImportWarning)
+    EXIST_ITER_DATASET = False
+else:
+    EXIST_ITER_DATASET = True
 from torch.utils.data.distributed import DistributedSampler
 
 from pytorch_lightning.utilities.debugging import MisconfigurationException
@@ -24,7 +34,7 @@ def init_train_dataloader(self, model):
         self.get_train_dataloader = model.train_dataloader
 
         # determine number of training batches
-        if isinstance(self.get_train_dataloader().dataset, IterableDataset):
+        if EXIST_ITER_DATASET and isinstance(self.get_train_dataloader().dataset, IterableDataset):
             self.nb_training_batches = float('inf')
         else:
             self.nb_training_batches = len(self.get_train_dataloader())
@@ -167,7 +177,8 @@ def get_dataloaders(self, model):
             self.get_val_dataloaders()
 
         # support IterableDataset for train data
-        self.is_iterable_train_dataloader = isinstance(self.get_train_dataloader().dataset, IterableDataset)
+        self.is_iterable_train_dataloader = (
+            EXIST_ITER_DATASET and isinstance(self.get_train_dataloader().dataset, IterableDataset))
         if self.is_iterable_train_dataloader and not isinstance(self.val_check_interval, int):
             m = '''
             When using an iterableDataset for train_dataloader,


Test patch: