|
2 | 2 |
|
3 | 3 | Use these examples to test how Lightning works. |
4 | 4 |
|
5 | | -#### MNIST |
| 5 | +## MNIST Examples |
6 | 6 |
|
7 | | -Trains MNIST where the model is defined inside the `LightningModule`. |
| 7 | +Here are 5 MNIST examples showing you how to gradually convert from pure PyTorch to PyTorch Lightning. |
8 | 8 |
|
9 | | -```bash |
10 | | -# cpu |
11 | | -python simple_image_classifier.py |
| 9 | +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. |
| 10 | + |
| 11 | +#### 1. Image Classifier with Vanilla PyTorch |
12 | 12 |
|
13 | | -# gpus (any number) |
14 | | -python simple_image_classifier.py --trainer.gpus 2 |
| 13 | +Trains a simple CNN over MNIST using vanilla PyTorch. |
15 | 14 |
|
16 | | -# Distributed Data Parallel |
17 | | -python simple_image_classifier.py --trainer.gpus 2 --trainer.accelerator ddp |
| 15 | +```bash |
| 16 | +# CPU |
| 17 | +python image_classifier_1_pytorch.py |
18 | 18 | ``` |
19 | 19 |
|
20 | 20 | ______________________________________________________________________ |
21 | 21 |
|
22 | | -#### MNIST with DALI |
| 22 | +#### 2. Image Classifier with LightningLite |
23 | 23 |
|
24 | | -The MNIST example above using [NVIDIA DALI](https://developer.nvidia.com/DALI). |
25 | | -Requires NVIDIA DALI to be installed based on your CUDA version, see [here](https://docs.nvidia.com/deeplearning/dali/user-guide/docs/installation.html). |
| 24 | +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). |
26 | 25 |
|
27 | 26 | ```bash |
28 | | -python dali_image_classifier.py |
| 27 | +# CPU / multiple GPUs if available |
| 28 | +python image_classifier_2_lite.py |
29 | 29 | ``` |
30 | 30 |
|
31 | 31 | ______________________________________________________________________ |
32 | 32 |
|
33 | | -#### Image classifier |
| 33 | +#### 3. Image Classifier - Conversion from Lite to Lightning |
34 | 34 |
|
35 | | -Generic image classifier with an arbitrary backbone (ie: a simple system) |
| 35 | +This script shows you how to prepare your conversion from [LightningLite](https://pytorch-lightning.readthedocs.io/en/stable/starter/lightning_lite.html) to `LightningModule`. |
36 | 36 |
|
37 | 37 | ```bash |
38 | | -# cpu |
39 | | -python backbone_image_classifier.py |
| 38 | +# CPU / multiple GPUs if available |
| 39 | +python image_classifier_3_lite_to_lightning_module.py |
| 40 | +``` |
40 | 41 |
|
41 | | -# gpus (any number) |
42 | | -python backbone_image_classifier.py --trainer.gpus 2 |
| 42 | +______________________________________________________________________ |
| 43 | + |
| 44 | +#### 4. Image Classifier with LightningModule |
| 45 | + |
| 46 | +This script shows you the result of the conversion to the `LightningModule` and finally all the benefits you get from the Lightning ecosystem. |
| 47 | + |
| 48 | +```bash |
| 49 | +# CPU |
| 50 | +python image_classifier_4_lightning_module.py |
43 | 51 |
|
44 | | -# Distributed Data Parallel |
45 | | -python backbone_image_classifier.py --trainer.gpus 2 --trainer.accelerator ddp |
| 52 | +# GPUs (any number) |
| 53 | +python image_classifier_4_lightning_module.py --trainer.gpus 2 |
46 | 54 | ``` |
47 | 55 |
|
48 | 56 | ______________________________________________________________________ |
49 | 57 |
|
50 | | -#### Autoencoder |
| 58 | +#### 5. Image Classifier with LightningModule and LightningDataModule |
51 | 59 |
|
52 | | -Showing the power of a system... arbitrarily complex training loops |
| 60 | +This script shows you how to extract the data related components into a `LightningDataModule`. |
53 | 61 |
|
54 | 62 | ```bash |
55 | | -# cpu |
56 | | -python autoencoder.py |
| 63 | +# CPU |
| 64 | +python image_classifier_5_lightning_datamodule.py |
57 | 65 |
|
58 | | -# gpus (any number) |
59 | | -python autoencoder.py --trainer.gpus 2 |
| 66 | +# GPUs (any number) |
| 67 | +python image_classifier_5_lightning_datamodule.py --trainer.gpus 2 |
60 | 68 |
|
61 | | -# Distributed Data Parallel |
62 | | -python autoencoder.py --trainer.gpus 2 --trainer.accelerator ddp |
| 69 | +# Distributed Data Parallel (DDP) |
| 70 | +python image_classifier_5_lightning_datamodule.py --trainer.gpus 2 --trainer.strategy 'ddp' |
63 | 71 | ``` |
0 commit comments