lightning/examples/convert_from_pt_to_pl
Jirka Borovec 9cc714cdd1
Future 2/n: stand-alone examples (#13294)
* move: pl_examples >> src/

* convert pl_examples package to plain examples

* update CI for examples

* ci

* missing

* install
2022-06-15 08:53:51 -04:00
..
README.md Future 2/n: stand-alone examples (#13294) 2022-06-15 08:53:51 -04:00
image_classifier_1_pytorch.py Future 2/n: stand-alone examples (#13294) 2022-06-15 08:53:51 -04:00
image_classifier_2_lite.py Future 2/n: stand-alone examples (#13294) 2022-06-15 08:53:51 -04:00
image_classifier_3_lite_to_lightning_module.py Future 2/n: stand-alone examples (#13294) 2022-06-15 08:53:51 -04:00
image_classifier_4_lightning_module.py Future 2/n: stand-alone examples (#13294) 2022-06-15 08:53:51 -04:00
image_classifier_5_lightning_datamodule.py Future 2/n: stand-alone examples (#13294) 2022-06-15 08:53:51 -04:00

README.md

MNIST Examples

Here are 5 MNIST examples showing you how to gradually convert from pure PyTorch to PyTorch Lightning.

The transition through LightningLite from pure PyTorch is optional but it might be helpful to learn about it.

1. Image Classifier with Vanilla PyTorch

Trains a simple CNN over MNIST using vanilla PyTorch.

# CPU
python image_classifier_1_pytorch.py

2. Image Classifier with LightningLite

This script shows you how to scale the previous script to enable GPU and multi-GPU training using LightningLite.

# 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 to LightningModule.

# CPU / multiple GPUs if available
python image_classifier_3_lite_to_lightning_module.py

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 Lightning.

# CPU
python image_classifier_4_lightning_module.py

# GPUs (any number)
python image_classifier_4_lightning_module.py --trainer.accelerator 'gpu' --trainer.devices 2

5. Image Classifier with LightningModule and LightningDataModule

This script shows you how to extract the data related components into a LightningDataModule.

# CPU
python image_classifier_5_lightning_datamodule.py

# GPUs (any number)
python image_classifier_5_lightning_datamodule.py --trainer.accelerator 'gpu' --trainer.devices 2

# Distributed Data parallel
python image_classifier_5_lightning_datamodule.py --trainer.accelerator 'gpu' --trainer.devices 2 --trainer.strategy 'ddp'