We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
num_training_batches rounds down, causing 0 batches count
## 🐛 Bug

self.num_training_batches is defined using int [here](https://github.com/williamFalcon/pytorch-lightning/blob/ca73b70d15bc8db3f57c1fd2d3bf152e6e1d7c4e/pytorch_lightning/trainer/data_loading.py#L52), which rounds it down to 0 when a small training_percent_check or overfit_pct is used, even though at least 1 batch is still processed. 

This does not cause any errors in "vanilla" lightning, but crashes any user code that uses the number of batches in a division (for example to get an average of some quantity over batches).

### To Reproduce

Steps to reproduce the behavior:

Set the training percentage to a small enough percentage that the number of examples is smaller than the batch size for a given dataset.

This would require a very simple fix, either to use `math.ceil()` or `max(1, self.num_training_batches)`, depending of how the quantity is expected to behave in the rest of the code.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pytorch_lightning/trainer/data_loading.py`
Content:
```
1 import warnings
2 from abc import ABC
3 
4 import torch.distributed as dist
5 try:
6     # loading for pyTorch 1.3
7     from torch.utils.data import IterableDataset
8 except ImportError:
9     # loading for pyTorch 1.1
10     import torch
11     warnings.warn('Your version of pyTorch %s does not support `IterableDataset`,'
12                   ' please upgrade to 1.2+' % torch.__version__, ImportWarning)
13     EXIST_ITER_DATASET = False
14 else:
15     EXIST_ITER_DATASET = True
16 from torch.utils.data.distributed import DistributedSampler
17 
18 from pytorch_lightning.utilities.debugging import MisconfigurationException
19 
20 try:
21     from apex import amp
22 
23     APEX_AVAILABLE = True
24 except ImportError:
25     APEX_AVAILABLE = False
26 
27 
28 class TrainerDataLoadingMixin(ABC):
29 
30     def __init__(self):
31         # this is just a summary on variables used in this abstract class,
32         #  the proper values/initialisation should be done in child class
33         self.proc_rank = None
34         self.use_ddp = None
35         self.use_ddp2 = None
36         self.shown_warnings = None
37         self.val_check_interval = None
38 
39     def init_train_dataloader(self, model):
40         """
41         Dataloaders are provided by the model
42         :param model:
43         :return:
44         """
45         self.get_train_dataloader = model.train_dataloader
46 
47         # determine number of training batches
48         if EXIST_ITER_DATASET and isinstance(self.get_train_dataloader().dataset, IterableDataset):
49             self.num_training_batches = float('inf')
50         else:
51             self.num_training_batches = len(self.get_train_dataloader())
52             self.num_training_batches = int(self.num_training_batches * self.train_percent_check)
53 
54         # determine when to check validation
55         # if int passed in, val checks that often
56         # otherwise, it checks in [0, 1.0] % range of a training epoch
57         if isinstance(self.val_check_interval, int):
58             self.val_check_batch = self.val_check_interval
59         else:
60             self.val_check_batch = int(self.num_training_batches * self.val_check_interval)
61             self.val_check_batch = max(1, self.val_check_batch)
62 
63         on_ddp = self.use_ddp or self.use_ddp2
64         if on_ddp and not isinstance(self.get_train_dataloader().sampler, DistributedSampler):
65             msg = """
66             You're using multiple gpus and multiple nodes without using a DistributedSampler
67             to assign a subset of your data to each process. To silence this warning, pass a
68             DistributedSampler to your DataLoader.
69 
70             ie: this:
71             dataset = myDataset()
72             dataloader = Dataloader(dataset)
73 
74             becomes:
75             dataset = myDataset()
76             dist_sampler = torch.utils.data.distributed.DistributedSampler(dataset)
77             dataloader = Dataloader(dataset, sampler=dist_sampler)
78 
79             If you want each process to load the full dataset, ignore this warning.
80             """
81             if msg not in self.shown_warnings and self.proc_rank == 0:
82                 self.shown_warnings.add(msg)
83                 warnings.warn(msg)
84 
85     def init_val_dataloader(self, model):
86         """
87         Dataloaders are provided by the model
88         :param model:
89         :return:
90         """
91         self.get_val_dataloaders = model.val_dataloader
92 
93         # determine number of validation batches
94         # val datasets could be none, 1 or 2+
95         if self.get_val_dataloaders() is not None:
96             self.num_val_batches = sum(len(dataloader) for dataloader in self.get_val_dataloaders())
97             self.num_val_batches = int(self.num_val_batches * self.val_percent_check)
98             self.num_val_batches = max(1, self.num_val_batches)
99 
100         on_ddp = self.use_ddp or self.use_ddp2
101         if on_ddp and self.get_val_dataloaders() is not None:
102             for dataloader in self.get_val_dataloaders():
103                 if not isinstance(dataloader.sampler, DistributedSampler):
104                     msg = """
105                     Your val_dataloader(s) don't use DistributedSampler.
106 
107                     You're using multiple gpus and multiple nodes without using a
108                     DistributedSampler to assign a subset of your data to each process.
109                     To silence this warning, pass a DistributedSampler to your DataLoader.
110 
111                     ie: this:
112                     dataset = myDataset()
113                     dataloader = Dataloader(dataset)
114 
115                     becomes:
116                     dataset = myDataset()
117                     dist_sampler = torch.utils.data.distributed.DistributedSampler(dataset)
118                     dataloader = Dataloader(dataset, sampler=dist_sampler)
119 
120                     If you want each process to load the full dataset, ignore this warning.
121                     """
122                     if msg not in self.shown_warnings and self.proc_rank == 0:
123                         self.shown_warnings.add(msg)
124                         warnings.warn(msg)
125                     break
126 
127     def init_test_dataloader(self, model):
128         """Dataloaders are provided by the model.
129 
130         :param model:
131         """
132 
133         self.get_test_dataloaders = model.test_dataloader
134 
135         # determine number of test batches
136         if self.get_test_dataloaders() is not None:
137             len_sum = sum(len(dataloader) for dataloader in self.get_test_dataloaders())
138             self.num_test_batches = len_sum
139             self.num_test_batches = int(self.num_test_batches * self.test_percent_check)
140             self.num_test_batches = max(1, self.num_test_batches)
141 
142         on_ddp = self.use_ddp or self.use_ddp2
143         if on_ddp and self.get_test_dataloaders() is not None:
144             for dataloader in self.get_test_dataloaders():
145                 if not isinstance(dataloader.sampler, DistributedSampler):
146                     msg = """
147                     Your `test_dataloader(s)` don't use DistributedSampler.
148 
149                     You're using multiple gpus and multiple nodes without using a
150                     DistributedSampler to assign a subset of your data to each process.
151                     To silence this warning, pass a DistributedSampler to your DataLoader.
152 
153                     ie: this::
154 
155                         dataset = myDataset()
156                         dataloader = Dataloader(dataset)
157 
158                     becomes::
159 
160                         dataset = myDataset()
161                         dist_sampler = torch.utils.data.distributed.DistributedSampler(dataset)
162                         dataloader = Dataloader(dataset, sampler=dist_sampler)
163 
164                     If you want each process to load the full dataset, ignore this warning.
165                     """
166                     if msg not in self.shown_warnings and self.proc_rank == 0:
167                         self.shown_warnings.add(msg)
168                         warnings.warn(msg)
169                     break
170 
171     def get_dataloaders(self, model):
172         """
173         Dataloaders are provided by the model
174         :param model:
175         :return:
176         """
177 
178         self.init_train_dataloader(model)
179         self.init_test_dataloader(model)
180         self.init_val_dataloader(model)
181 
182         if self.use_ddp or self.use_ddp2:
183             # wait for all processes to catch up
184             dist.barrier()
185 
186             # load each dataloader
187             self.get_train_dataloader()
188             self.get_test_dataloaders()
189             self.get_val_dataloaders()
190 
191         # support IterableDataset for train data
192         self.is_iterable_train_dataloader = (
193             EXIST_ITER_DATASET and isinstance(self.get_train_dataloader().dataset, IterableDataset))
194         if self.is_iterable_train_dataloader and not isinstance(self.val_check_interval, int):
195             m = '''
196             When using an iterableDataset for `train_dataloader`,
197             `Trainer(val_check_interval)` must be an int.
198             An int k specifies checking validation every k training batches
199             '''
200             raise MisconfigurationException(m)
201 
202     def determine_data_use_amount(self, train_percent_check, val_percent_check,
203                                   test_percent_check, overfit_pct):
204         """
205         Use less data for debugging purposes
206         """
207         self.train_percent_check = train_percent_check
208         self.val_percent_check = val_percent_check
209         self.test_percent_check = test_percent_check
210         if overfit_pct > 0:
211             self.train_percent_check = overfit_pct
212             self.val_percent_check = overfit_pct
213             self.test_percent_check = overfit_pct
214
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pytorch_lightning/trainer/data_loading.py b/pytorch_lightning/trainer/data_loading.py
--- a/pytorch_lightning/trainer/data_loading.py
+++ b/pytorch_lightning/trainer/data_loading.py
@@ -36,6 +36,15 @@
         self.shown_warnings = None
         self.val_check_interval = None
 
+    def _percent_range_check(self, name):
+        value = getattr(self, name)
+        msg = f"`{name}` must lie in the range [0.0, 1.0], but got {value:.3f}."
+        if name == "val_check_interval":
+            msg += " If you want to disable validation set `val_percent_check` to 0.0 instead."
+
+        if not 0. <= value <= 1.:
+            raise ValueError(msg)
+
     def init_train_dataloader(self, model):
         """
         Dataloaders are provided by the model
@@ -48,6 +57,8 @@
         if EXIST_ITER_DATASET and isinstance(self.get_train_dataloader().dataset, IterableDataset):
             self.num_training_batches = float('inf')
         else:
+            self._percent_range_check('train_percent_check')
+
             self.num_training_batches = len(self.get_train_dataloader())
             self.num_training_batches = int(self.num_training_batches * self.train_percent_check)
 
@@ -56,7 +67,14 @@
         # otherwise, it checks in [0, 1.0] % range of a training epoch
         if isinstance(self.val_check_interval, int):
             self.val_check_batch = self.val_check_interval
+            if self.val_check_batch > self.num_training_batches:
+                raise ValueError(
+                    f"`val_check_interval` ({self.val_check_interval}) must be less than or equal "
+                    f"to the number of the training batches ({self.num_training_batches}). "
+                    f"If you want to disable validation set `val_percent_check` to 0.0 instead.")
         else:
+            self._percent_range_check('val_check_interval')
+
             self.val_check_batch = int(self.num_training_batches * self.val_check_interval)
             self.val_check_batch = max(1, self.val_check_batch)
 
@@ -89,13 +107,15 @@
         :return:
         """
         self.get_val_dataloaders = model.val_dataloader
+        self.num_val_batches = 0
 
         # determine number of validation batches
         # val datasets could be none, 1 or 2+
         if self.get_val_dataloaders() is not None:
+            self._percent_range_check('val_percent_check')
+
             self.num_val_batches = sum(len(dataloader) for dataloader in self.get_val_dataloaders())
             self.num_val_batches = int(self.num_val_batches * self.val_percent_check)
-            self.num_val_batches = max(1, self.num_val_batches)
 
         on_ddp = self.use_ddp or self.use_ddp2
         if on_ddp and self.get_val_dataloaders() is not None:
@@ -134,10 +154,11 @@
 
         # determine number of test batches
         if self.get_test_dataloaders() is not None:
+            self._percent_range_check('test_percent_check')
+
             len_sum = sum(len(dataloader) for dataloader in self.get_test_dataloaders())
             self.num_test_batches = len_sum
             self.num_test_batches = int(self.num_test_batches * self.test_percent_check)
-            self.num_test_batches = max(1, self.num_test_batches)
 
         on_ddp = self.use_ddp or self.use_ddp2
         if on_ddp and self.get_test_dataloaders() is not None:
@@ -208,6 +229,10 @@
         self.val_percent_check = val_percent_check
         self.test_percent_check = test_percent_check
         if overfit_pct > 0:
+            if overfit_pct > 1:
+                raise ValueError(f"`overfit_pct` must be not greater than 1.0, but got "
+                                 f"{overfit_pct:.3f}.")
+
             self.train_percent_check = overfit_pct
             self.val_percent_check = overfit_pct
             self.test_percent_check = overfit_pct

{"golden_diff": "diff --git a/pytorch_lightning/trainer/data_loading.py b/pytorch_lightning/trainer/data_loading.py\n--- a/pytorch_lightning/trainer/data_loading.py\n+++ b/pytorch_lightning/trainer/data_loading.py\n@@ -36,6 +36,15 @@\n         self.shown_warnings = None\n         self.val_check_interval = None\n \n+    def _percent_range_check(self, name):\n+        value = getattr(self, name)\n+        msg = f\"`{name}` must lie in the range [0.0, 1.0], but got {value:.3f}.\"\n+        if name == \"val_check_interval\":\n+            msg += \" If you want to disable validation set `val_percent_check` to 0.0 instead.\"\n+\n+        if not 0. <= value <= 1.:\n+            raise ValueError(msg)\n+\n     def init_train_dataloader(self, model):\n         \"\"\"\n         Dataloaders are provided by the model\n@@ -48,6 +57,8 @@\n         if EXIST_ITER_DATASET and isinstance(self.get_train_dataloader().dataset, IterableDataset):\n             self.num_training_batches = float('inf')\n         else:\n+            self._percent_range_check('train_percent_check')\n+\n             self.num_training_batches = len(self.get_train_dataloader())\n             self.num_training_batches = int(self.num_training_batches * self.train_percent_check)\n \n@@ -56,7 +67,14 @@\n         # otherwise, it checks in [0, 1.0] % range of a training epoch\n         if isinstance(self.val_check_interval, int):\n             self.val_check_batch = self.val_check_interval\n+            if self.val_check_batch > self.num_training_batches:\n+                raise ValueError(\n+                    f\"`val_check_interval` ({self.val_check_interval}) must be less than or equal \"\n+                    f\"to the number of the training batches ({self.num_training_batches}). \"\n+                    f\"If you want to disable validation set `val_percent_check` to 0.0 instead.\")\n         else:\n+            self._percent_range_check('val_check_interval')\n+\n             self.val_check_batch = int(self.num_training_batches * self.val_check_interval)\n             self.val_check_batch = max(1, self.val_check_batch)\n \n@@ -89,13 +107,15 @@\n         :return:\n         \"\"\"\n         self.get_val_dataloaders = model.val_dataloader\n+        self.num_val_batches = 0\n \n         # determine number of validation batches\n         # val datasets could be none, 1 or 2+\n         if self.get_val_dataloaders() is not None:\n+            self._percent_range_check('val_percent_check')\n+\n             self.num_val_batches = sum(len(dataloader) for dataloader in self.get_val_dataloaders())\n             self.num_val_batches = int(self.num_val_batches * self.val_percent_check)\n-            self.num_val_batches = max(1, self.num_val_batches)\n \n         on_ddp = self.use_ddp or self.use_ddp2\n         if on_ddp and self.get_val_dataloaders() is not None:\n@@ -134,10 +154,11 @@\n \n         # determine number of test batches\n         if self.get_test_dataloaders() is not None:\n+            self._percent_range_check('test_percent_check')\n+\n             len_sum = sum(len(dataloader) for dataloader in self.get_test_dataloaders())\n             self.num_test_batches = len_sum\n             self.num_test_batches = int(self.num_test_batches * self.test_percent_check)\n-            self.num_test_batches = max(1, self.num_test_batches)\n \n         on_ddp = self.use_ddp or self.use_ddp2\n         if on_ddp and self.get_test_dataloaders() is not None:\n@@ -208,6 +229,10 @@\n         self.val_percent_check = val_percent_check\n         self.test_percent_check = test_percent_check\n         if overfit_pct > 0:\n+            if overfit_pct > 1:\n+                raise ValueError(f\"`overfit_pct` must be not greater than 1.0, but got \"\n+                                 f\"{overfit_pct:.3f}.\")\n+\n             self.train_percent_check = overfit_pct\n             self.val_percent_check = overfit_pct\n             self.test_percent_check = overfit_pct\n", "issue": "num_training_batches rounds down, causing 0 batches count\n## \ud83d\udc1b Bug\r\n\r\nself.num_training_batches is defined using int [here](https://github.com/williamFalcon/pytorch-lightning/blob/ca73b70d15bc8db3f57c1fd2d3bf152e6e1d7c4e/pytorch_lightning/trainer/data_loading.py#L52), which rounds it down to 0 when a small training_percent_check or overfit_pct is used, even though at least 1 batch is still processed. \r\n\r\nThis does not cause any errors in \"vanilla\" lightning, but crashes any user code that uses the number of batches in a division (for example to get an average of some quantity over batches).\r\n\r\n### To Reproduce\r\n\r\nSteps to reproduce the behavior:\r\n\r\nSet the training percentage to a small enough percentage that the number of examples is smaller than the batch size for a given dataset.\r\n\r\nThis would require a very simple fix, either to use `math.ceil()` or `max(1, self.num_training_batches)`, depending of how the quantity is expected to behave in the rest of the code.\r\n\n", "before_files": [{"content": "import warnings\nfrom abc import ABC\n\nimport torch.distributed as dist\ntry:\n    # loading for pyTorch 1.3\n    from torch.utils.data import IterableDataset\nexcept ImportError:\n    # loading for pyTorch 1.1\n    import torch\n    warnings.warn('Your version of pyTorch %s does not support `IterableDataset`,'\n                  ' please upgrade to 1.2+' % torch.__version__, ImportWarning)\n    EXIST_ITER_DATASET = False\nelse:\n    EXIST_ITER_DATASET = True\nfrom torch.utils.data.distributed import DistributedSampler\n\nfrom pytorch_lightning.utilities.debugging import MisconfigurationException\n\ntry:\n    from apex import amp\n\n    APEX_AVAILABLE = True\nexcept ImportError:\n    APEX_AVAILABLE = False\n\n\nclass TrainerDataLoadingMixin(ABC):\n\n    def __init__(self):\n        # this is just a summary on variables used in this abstract class,\n        #  the proper values/initialisation should be done in child class\n        self.proc_rank = None\n        self.use_ddp = None\n        self.use_ddp2 = None\n        self.shown_warnings = None\n        self.val_check_interval = None\n\n    def init_train_dataloader(self, model):\n        \"\"\"\n        Dataloaders are provided by the model\n        :param model:\n        :return:\n        \"\"\"\n        self.get_train_dataloader = model.train_dataloader\n\n        # determine number of training batches\n        if EXIST_ITER_DATASET and isinstance(self.get_train_dataloader().dataset, IterableDataset):\n            self.num_training_batches = float('inf')\n        else:\n            self.num_training_batches = len(self.get_train_dataloader())\n            self.num_training_batches = int(self.num_training_batches * self.train_percent_check)\n\n        # determine when to check validation\n        # if int passed in, val checks that often\n        # otherwise, it checks in [0, 1.0] % range of a training epoch\n        if isinstance(self.val_check_interval, int):\n            self.val_check_batch = self.val_check_interval\n        else:\n            self.val_check_batch = int(self.num_training_batches * self.val_check_interval)\n            self.val_check_batch = max(1, self.val_check_batch)\n\n        on_ddp = self.use_ddp or self.use_ddp2\n        if on_ddp and not isinstance(self.get_train_dataloader().sampler, DistributedSampler):\n            msg = \"\"\"\n            You're using multiple gpus and multiple nodes without using a DistributedSampler\n            to assign a subset of your data to each process. To silence this warning, pass a\n            DistributedSampler to your DataLoader.\n\n            ie: this:\n            dataset = myDataset()\n            dataloader = Dataloader(dataset)\n\n            becomes:\n            dataset = myDataset()\n            dist_sampler = torch.utils.data.distributed.DistributedSampler(dataset)\n            dataloader = Dataloader(dataset, sampler=dist_sampler)\n\n            If you want each process to load the full dataset, ignore this warning.\n            \"\"\"\n            if msg not in self.shown_warnings and self.proc_rank == 0:\n                self.shown_warnings.add(msg)\n                warnings.warn(msg)\n\n    def init_val_dataloader(self, model):\n        \"\"\"\n        Dataloaders are provided by the model\n        :param model:\n        :return:\n        \"\"\"\n        self.get_val_dataloaders = model.val_dataloader\n\n        # determine number of validation batches\n        # val datasets could be none, 1 or 2+\n        if self.get_val_dataloaders() is not None:\n            self.num_val_batches = sum(len(dataloader) for dataloader in self.get_val_dataloaders())\n            self.num_val_batches = int(self.num_val_batches * self.val_percent_check)\n            self.num_val_batches = max(1, self.num_val_batches)\n\n        on_ddp = self.use_ddp or self.use_ddp2\n        if on_ddp and self.get_val_dataloaders() is not None:\n            for dataloader in self.get_val_dataloaders():\n                if not isinstance(dataloader.sampler, DistributedSampler):\n                    msg = \"\"\"\n                    Your val_dataloader(s) don't use DistributedSampler.\n\n                    You're using multiple gpus and multiple nodes without using a\n                    DistributedSampler to assign a subset of your data to each process.\n                    To silence this warning, pass a DistributedSampler to your DataLoader.\n\n                    ie: this:\n                    dataset = myDataset()\n                    dataloader = Dataloader(dataset)\n\n                    becomes:\n                    dataset = myDataset()\n                    dist_sampler = torch.utils.data.distributed.DistributedSampler(dataset)\n                    dataloader = Dataloader(dataset, sampler=dist_sampler)\n\n                    If you want each process to load the full dataset, ignore this warning.\n                    \"\"\"\n                    if msg not in self.shown_warnings and self.proc_rank == 0:\n                        self.shown_warnings.add(msg)\n                        warnings.warn(msg)\n                    break\n\n    def init_test_dataloader(self, model):\n        \"\"\"Dataloaders are provided by the model.\n\n        :param model:\n        \"\"\"\n\n        self.get_test_dataloaders = model.test_dataloader\n\n        # determine number of test batches\n        if self.get_test_dataloaders() is not None:\n            len_sum = sum(len(dataloader) for dataloader in self.get_test_dataloaders())\n            self.num_test_batches = len_sum\n            self.num_test_batches = int(self.num_test_batches * self.test_percent_check)\n            self.num_test_batches = max(1, self.num_test_batches)\n\n        on_ddp = self.use_ddp or self.use_ddp2\n        if on_ddp and self.get_test_dataloaders() is not None:\n            for dataloader in self.get_test_dataloaders():\n                if not isinstance(dataloader.sampler, DistributedSampler):\n                    msg = \"\"\"\n                    Your `test_dataloader(s)` don't use DistributedSampler.\n\n                    You're using multiple gpus and multiple nodes without using a\n                    DistributedSampler to assign a subset of your data to each process.\n                    To silence this warning, pass a DistributedSampler to your DataLoader.\n\n                    ie: this::\n\n                        dataset = myDataset()\n                        dataloader = Dataloader(dataset)\n\n                    becomes::\n\n                        dataset = myDataset()\n                        dist_sampler = torch.utils.data.distributed.DistributedSampler(dataset)\n                        dataloader = Dataloader(dataset, sampler=dist_sampler)\n\n                    If you want each process to load the full dataset, ignore this warning.\n                    \"\"\"\n                    if msg not in self.shown_warnings and self.proc_rank == 0:\n                        self.shown_warnings.add(msg)\n                        warnings.warn(msg)\n                    break\n\n    def get_dataloaders(self, model):\n        \"\"\"\n        Dataloaders are provided by the model\n        :param model:\n        :return:\n        \"\"\"\n\n        self.init_train_dataloader(model)\n        self.init_test_dataloader(model)\n        self.init_val_dataloader(model)\n\n        if self.use_ddp or self.use_ddp2:\n            # wait for all processes to catch up\n            dist.barrier()\n\n            # load each dataloader\n            self.get_train_dataloader()\n            self.get_test_dataloaders()\n            self.get_val_dataloaders()\n\n        # support IterableDataset for train data\n        self.is_iterable_train_dataloader = (\n            EXIST_ITER_DATASET and isinstance(self.get_train_dataloader().dataset, IterableDataset))\n        if self.is_iterable_train_dataloader and not isinstance(self.val_check_interval, int):\n            m = '''\n            When using an iterableDataset for `train_dataloader`,\n            `Trainer(val_check_interval)` must be an int.\n            An int k specifies checking validation every k training batches\n            '''\n            raise MisconfigurationException(m)\n\n    def determine_data_use_amount(self, train_percent_check, val_percent_check,\n                                  test_percent_check, overfit_pct):\n        \"\"\"\n        Use less data for debugging purposes\n        \"\"\"\n        self.train_percent_check = train_percent_check\n        self.val_percent_check = val_percent_check\n        self.test_percent_check = test_percent_check\n        if overfit_pct > 0:\n            self.train_percent_check = overfit_pct\n            self.val_percent_check = overfit_pct\n            self.test_percent_check = overfit_pct\n", "path": "pytorch_lightning/trainer/data_loading.py"}], "after_files": [{"content": "import warnings\nfrom abc import ABC\n\nimport torch.distributed as dist\ntry:\n    # loading for pyTorch 1.3\n    from torch.utils.data import IterableDataset\nexcept ImportError:\n    # loading for pyTorch 1.1\n    import torch\n    warnings.warn('Your version of pyTorch %s does not support `IterableDataset`,'\n                  ' please upgrade to 1.2+' % torch.__version__, ImportWarning)\n    EXIST_ITER_DATASET = False\nelse:\n    EXIST_ITER_DATASET = True\nfrom torch.utils.data.distributed import DistributedSampler\n\nfrom pytorch_lightning.utilities.debugging import MisconfigurationException\n\ntry:\n    from apex import amp\n\n    APEX_AVAILABLE = True\nexcept ImportError:\n    APEX_AVAILABLE = False\n\n\nclass TrainerDataLoadingMixin(ABC):\n\n    def __init__(self):\n        # this is just a summary on variables used in this abstract class,\n        #  the proper values/initialisation should be done in child class\n        self.proc_rank = None\n        self.use_ddp = None\n        self.use_ddp2 = None\n        self.shown_warnings = None\n        self.val_check_interval = None\n\n    def _percent_range_check(self, name):\n        value = getattr(self, name)\n        msg = f\"`{name}` must lie in the range [0.0, 1.0], but got {value:.3f}.\"\n        if name == \"val_check_interval\":\n            msg += \" If you want to disable validation set `val_percent_check` to 0.0 instead.\"\n\n        if not 0. <= value <= 1.:\n            raise ValueError(msg)\n\n    def init_train_dataloader(self, model):\n        \"\"\"\n        Dataloaders are provided by the model\n        :param model:\n        :return:\n        \"\"\"\n        self.get_train_dataloader = model.train_dataloader\n\n        # determine number of training batches\n        if EXIST_ITER_DATASET and isinstance(self.get_train_dataloader().dataset, IterableDataset):\n            self.num_training_batches = float('inf')\n        else:\n            self._percent_range_check('train_percent_check')\n\n            self.num_training_batches = len(self.get_train_dataloader())\n            self.num_training_batches = int(self.num_training_batches * self.train_percent_check)\n\n        # determine when to check validation\n        # if int passed in, val checks that often\n        # otherwise, it checks in [0, 1.0] % range of a training epoch\n        if isinstance(self.val_check_interval, int):\n            self.val_check_batch = self.val_check_interval\n            if self.val_check_batch > self.num_training_batches:\n                raise ValueError(\n                    f\"`val_check_interval` ({self.val_check_interval}) must be less than or equal \"\n                    f\"to the number of the training batches ({self.num_training_batches}). \"\n                    f\"If you want to disable validation set `val_percent_check` to 0.0 instead.\")\n        else:\n            self._percent_range_check('val_check_interval')\n\n            self.val_check_batch = int(self.num_training_batches * self.val_check_interval)\n            self.val_check_batch = max(1, self.val_check_batch)\n\n        on_ddp = self.use_ddp or self.use_ddp2\n        if on_ddp and not isinstance(self.get_train_dataloader().sampler, DistributedSampler):\n            msg = \"\"\"\n            You're using multiple gpus and multiple nodes without using a DistributedSampler\n            to assign a subset of your data to each process. To silence this warning, pass a\n            DistributedSampler to your DataLoader.\n\n            ie: this:\n            dataset = myDataset()\n            dataloader = Dataloader(dataset)\n\n            becomes:\n            dataset = myDataset()\n            dist_sampler = torch.utils.data.distributed.DistributedSampler(dataset)\n            dataloader = Dataloader(dataset, sampler=dist_sampler)\n\n            If you want each process to load the full dataset, ignore this warning.\n            \"\"\"\n            if msg not in self.shown_warnings and self.proc_rank == 0:\n                self.shown_warnings.add(msg)\n                warnings.warn(msg)\n\n    def init_val_dataloader(self, model):\n        \"\"\"\n        Dataloaders are provided by the model\n        :param model:\n        :return:\n        \"\"\"\n        self.get_val_dataloaders = model.val_dataloader\n        self.num_val_batches = 0\n\n        # determine number of validation batches\n        # val datasets could be none, 1 or 2+\n        if self.get_val_dataloaders() is not None:\n            self._percent_range_check('val_percent_check')\n\n            self.num_val_batches = sum(len(dataloader) for dataloader in self.get_val_dataloaders())\n            self.num_val_batches = int(self.num_val_batches * self.val_percent_check)\n\n        on_ddp = self.use_ddp or self.use_ddp2\n        if on_ddp and self.get_val_dataloaders() is not None:\n            for dataloader in self.get_val_dataloaders():\n                if not isinstance(dataloader.sampler, DistributedSampler):\n                    msg = \"\"\"\n                    Your val_dataloader(s) don't use DistributedSampler.\n\n                    You're using multiple gpus and multiple nodes without using a\n                    DistributedSampler to assign a subset of your data to each process.\n                    To silence this warning, pass a DistributedSampler to your DataLoader.\n\n                    ie: this:\n                    dataset = myDataset()\n                    dataloader = Dataloader(dataset)\n\n                    becomes:\n                    dataset = myDataset()\n                    dist_sampler = torch.utils.data.distributed.DistributedSampler(dataset)\n                    dataloader = Dataloader(dataset, sampler=dist_sampler)\n\n                    If you want each process to load the full dataset, ignore this warning.\n                    \"\"\"\n                    if msg not in self.shown_warnings and self.proc_rank == 0:\n                        self.shown_warnings.add(msg)\n                        warnings.warn(msg)\n                    break\n\n    def init_test_dataloader(self, model):\n        \"\"\"Dataloaders are provided by the model.\n\n        :param model:\n        \"\"\"\n\n        self.get_test_dataloaders = model.test_dataloader\n\n        # determine number of test batches\n        if self.get_test_dataloaders() is not None:\n            self._percent_range_check('test_percent_check')\n\n            len_sum = sum(len(dataloader) for dataloader in self.get_test_dataloaders())\n            self.num_test_batches = len_sum\n            self.num_test_batches = int(self.num_test_batches * self.test_percent_check)\n\n        on_ddp = self.use_ddp or self.use_ddp2\n        if on_ddp and self.get_test_dataloaders() is not None:\n            for dataloader in self.get_test_dataloaders():\n                if not isinstance(dataloader.sampler, DistributedSampler):\n                    msg = \"\"\"\n                    Your `test_dataloader(s)` don't use DistributedSampler.\n\n                    You're using multiple gpus and multiple nodes without using a\n                    DistributedSampler to assign a subset of your data to each process.\n                    To silence this warning, pass a DistributedSampler to your DataLoader.\n\n                    ie: this::\n\n                        dataset = myDataset()\n                        dataloader = Dataloader(dataset)\n\n                    becomes::\n\n                        dataset = myDataset()\n                        dist_sampler = torch.utils.data.distributed.DistributedSampler(dataset)\n                        dataloader = Dataloader(dataset, sampler=dist_sampler)\n\n                    If you want each process to load the full dataset, ignore this warning.\n                    \"\"\"\n                    if msg not in self.shown_warnings and self.proc_rank == 0:\n                        self.shown_warnings.add(msg)\n                        warnings.warn(msg)\n                    break\n\n    def get_dataloaders(self, model):\n        \"\"\"\n        Dataloaders are provided by the model\n        :param model:\n        :return:\n        \"\"\"\n\n        self.init_train_dataloader(model)\n        self.init_test_dataloader(model)\n        self.init_val_dataloader(model)\n\n        if self.use_ddp or self.use_ddp2:\n            # wait for all processes to catch up\n            dist.barrier()\n\n            # load each dataloader\n            self.get_train_dataloader()\n            self.get_test_dataloaders()\n            self.get_val_dataloaders()\n\n        # support IterableDataset for train data\n        self.is_iterable_train_dataloader = (\n            EXIST_ITER_DATASET and isinstance(self.get_train_dataloader().dataset, IterableDataset))\n        if self.is_iterable_train_dataloader and not isinstance(self.val_check_interval, int):\n            m = '''\n            When using an iterableDataset for `train_dataloader`,\n            `Trainer(val_check_interval)` must be an int.\n            An int k specifies checking validation every k training batches\n            '''\n            raise MisconfigurationException(m)\n\n    def determine_data_use_amount(self, train_percent_check, val_percent_check,\n                                  test_percent_check, overfit_pct):\n        \"\"\"\n        Use less data for debugging purposes\n        \"\"\"\n        self.train_percent_check = train_percent_check\n        self.val_percent_check = val_percent_check\n        self.test_percent_check = test_percent_check\n        if overfit_pct > 0:\n            if overfit_pct > 1:\n                raise ValueError(f\"`overfit_pct` must be not greater than 1.0, but got \"\n                                 f\"{overfit_pct:.3f}.\")\n\n            self.train_percent_check = overfit_pct\n            self.val_percent_check = overfit_pct\n            self.test_percent_check = overfit_pct\n", "path": "pytorch_lightning/trainer/data_loading.py"}]}