lightning/pl_examples/basic_examples/README.md

72 lines
2.2 KiB
Markdown
Raw Normal View History

## Basic Examples
Use these examples to test how Lightning works.
2019-10-05 18:13:55 +00:00
## MNIST Examples
Here are 5 MNIST examples showing you how to gradually convert from pure PyTorch to PyTorch Lightning.
The transition through [LightningLite](https://pytorch-lightning.readthedocs.io/en/stable/starter/lightning_lite.rst) from pure PyTorch is optional but it might be helpful to learn about it.
#### 1. Image Classifier with Vanilla PyTorch
2019-10-05 18:13:55 +00:00
Trains a simple CNN over MNIST using vanilla PyTorch.
2019-10-05 18:13:55 +00:00
```bash
# CPU
python image_classifier_1_pytorch.py
```
2019-10-05 18:13:55 +00:00
______________________________________________________________________
#### 2. Image Classifier with LightningLite
This script shows you how to scale the previous script to enable GPU and multi-GPU training using [LightningLite](https://pytorch-lightning.readthedocs.io/en/stable/starter/lightning_lite.html).
```bash
# CPU / multiple GPUs if available
python image_classifier_2_lite.py
```
______________________________________________________________________
#### 3. Image Classifier - Conversion from Lite to Lightning
This script shows you how to prepare your conversion from [LightningLite](https://pytorch-lightning.readthedocs.io/en/stable/starter/lightning_lite.html) to `LightningModule`.
2019-10-05 18:13:55 +00:00
```bash
# CPU / multiple GPUs if available
python image_classifier_3_lite_to_lightning_module.py
```
2019-10-05 18:13:55 +00:00
______________________________________________________________________
#### 4. Image Classifier with LightningModule
This script shows you the result of the conversion to the `LightningModule` and finally all the benefits you get from the Lightning ecosystem.
```bash
# CPU
python image_classifier_4_lightning_module.py
2019-10-05 18:13:55 +00:00
# GPUs (any number)
python image_classifier_4_lightning_module.py --trainer.gpus 2
2019-10-05 18:13:55 +00:00
```
______________________________________________________________________
#### 5. Image Classifier with LightningModule and LightningDataModule
This script shows you how to extract the data related components into a `LightningDataModule`.
2019-10-05 18:13:55 +00:00
```bash
# CPU
python image_classifier_5_lightning_datamodule.py
# GPUs (any number)
python image_classifier_5_lightning_datamodule.py --trainer.gpus 2
# Distributed Data Parallel (DDP)
python image_classifier_5_lightning_datamodule.py --trainer.gpus 2 --trainer.strategy 'ddp'
```