Loader docs (#1416)
* added multiple loader docs * added multiple loader docs * added multiple loader docs * added multiple loader docs * added multiple loader docs * Apply suggestions from code review * added multiple loader docs * added build docs script * typo * added build docs script * added build docs script * added build docs script Co-authored-by: Jirka Borovec <Borda@users.noreply.github.com> Co-authored-by: J. Borovec <jirka.borovec@seznam.cz>
This commit is contained in:
parent
d8cbf8d60c
commit
7d0c2c7db8
|
@ -0,0 +1 @@
|
|||
make clean ; make html --debug --jobs 2 SPHINXOPTS="-W"
|
|
@ -67,6 +67,7 @@ PyTorch Lightning Documentation
|
|||
hooks
|
||||
hyperparameters
|
||||
multi_gpu
|
||||
multiple_loaders
|
||||
weights_loading
|
||||
optimizers
|
||||
profiler
|
||||
|
|
|
@ -28,6 +28,23 @@ to use inheritance to very quickly create an AutoEncoder.
|
|||
|
||||
---------
|
||||
|
||||
Installing Lightning
|
||||
--------------------
|
||||
Lightning is trivial to install.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
conda activate my_env
|
||||
pip install pytorch-lightning
|
||||
|
||||
Or without conda environments, anywhere you can use pip.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
pip install pytorch-lightning
|
||||
|
||||
---------
|
||||
|
||||
Lightning Philosophy
|
||||
--------------------
|
||||
Lightning factors DL/ML code into three types:
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
Multiple Datasets
|
||||
=================
|
||||
Lightning supports multiple dataloaders in a few ways.
|
||||
|
||||
1. Create a dataloader that iterates both datasets under the hood.
|
||||
2. In the validation and test loop you also have the option to return multiple dataloaders
|
||||
which lightning will call sequentially.
|
||||
|
||||
Multiple training dataloaders
|
||||
-----------------------------
|
||||
For training, the best way to use multiple-dataloaders is to create a Dataloader class
|
||||
which wraps both your dataloaders. (This of course also works for testing and validation
|
||||
dataloaders).
|
||||
|
||||
(`reference <https://discuss.pytorch.org/t/train-simultaneously-on-two-datasets/649/2>`_)
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
class ConcatDataset(torch.utils.data.Dataset):
|
||||
def __init__(self, *datasets):
|
||||
self.datasets = datasets
|
||||
|
||||
def __getitem__(self, i):
|
||||
return tuple(d[i] for d in self.datasets)
|
||||
|
||||
def __len__(self):
|
||||
return min(len(d) for d in self.datasets)
|
||||
|
||||
class LitModel(LightningModule):
|
||||
def train_dataloader(self):
|
||||
concat_dataset = ConcatDataset(
|
||||
datasets.ImageFolder(traindir_A),
|
||||
datasets.ImageFolder(traindir_B)
|
||||
)
|
||||
|
||||
loader = torch.utils.data.DataLoader(
|
||||
concat_dataset,
|
||||
batch_size=args.batch_size,
|
||||
shuffle=True,
|
||||
num_workers=args.workers,
|
||||
pin_memory=True
|
||||
)
|
||||
return loader
|
||||
|
||||
def val_dataloader(self):
|
||||
# SAME
|
||||
|
||||
def test_dataloader(self):
|
||||
# SAME
|
||||
|
||||
Test/Val dataloaders
|
||||
--------------------
|
||||
For validation, test dataloaders lightning also gives you the additional
|
||||
option of passing in multiple dataloaders back from each call.
|
||||
|
||||
See the following for more details:
|
||||
|
||||
- :meth:`~pytorch_lightning.core.LightningModule.val_dataloader`
|
||||
- :meth:`~pytorch_lightning.core.LightningModule.test_dataloader`
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
def val_dataloader(self):
|
||||
loader_1 = Dataloader()
|
||||
loader_2 = Dataloader()
|
||||
return [loader_1, loader_2]
|
|
@ -58,7 +58,7 @@ So you can run it like so:distributed_backend
|
|||
|
||||
.. code-block:: bash
|
||||
|
||||
$ python main.py --gpus 2
|
||||
python main.py --gpus 2
|
||||
|
||||
|
||||
.. note::
|
||||
|
@ -550,7 +550,7 @@ submit this script using the xla_dist script.
|
|||
|
||||
Example::
|
||||
|
||||
$ python -m torch_xla.distributed.xla_dist
|
||||
python -m torch_xla.distributed.xla_dist
|
||||
--tpu=$TPU_POD_NAME
|
||||
--conda-env=torch-xla-nightly
|
||||
--env=XLA_USE_BF16=1
|
||||
|
|
Loading…
Reference in New Issue