lightning/pl_examples/basic_examples
Rohit Gupta 581bf7f2f2
Deprecate `on_epoch_start/on_epoch_end` hook (#11578)
2022-02-07 14:15:27 +00:00
..
mnist_examples Fix KFold example (#11230) 2022-01-03 09:54:44 +00:00
README.md Lite Docs and Example Improvements (#10303) 2021-11-02 16:13:01 +01:00
__init__.py changes examples to pl_examples for name connflict 2019-10-19 00:41:17 +02:00
autoencoder.py Deprecate `on_epoch_start/on_epoch_end` hook (#11578) 2022-02-07 14:15:27 +00:00
backbone_image_classifier.py remove dataloader patching on the LightningModule (#9764) 2021-10-20 15:23:20 +02:00
mnist_datamodule.py MANIFEST.in and setup.py clean-up (#7614) 2021-11-19 15:38:42 +01:00
profiler_example.py [bugfix] Resolve example after LightningCLI update (#9520) 2021-09-15 12:31:41 +05:30

README.md

Basic Examples

Use these examples to test how Lightning works.

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 mnist_examples/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 mnist_examples/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 mnist_examples/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 the Lightning ecosystem.

# CPU
python mnist_examples/image_classifier_4_lightning_module.py

# GPUs (any number)
python mnist_examples/image_classifier_4_lightning_module.py --trainer.gpus 2

5. Image Classifier with LightningModule and LightningDataModule

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

# CPU
python mnist_examples/image_classifier_5_lightning_datamodule.py

# GPUs (any number)
python mnist_examples/image_classifier_5_lightning_datamodule.py --trainer.gpus 2

# Distributed Data Parallel (DDP)
python mnist_examples/image_classifier_5_lightning_datamodule.py --trainer.gpus 2 --trainer.strategy 'ddp'

AutoEncoder

This script shows you how to implement a CNN auto-encoder.

# CPU
python autoencoder.py

# GPUs (any number)
python autoencoder.py --trainer.gpus 2

# Distributed Data Parallel (DDP)
python autoencoder.py --trainer.gpus 2 --trainer.strategy 'ddp'

Backbone Image Classifier

This script shows you how to implement a LightningModule as a system. A system describes a LightningModule which takes a single torch.nn.Module which makes exporting to producion simpler.

# CPU
python backbone_image_classifier.py

# GPUs (any number)
python backbone_image_classifier.py --trainer.gpus 2

# Distributed Data Parallel (DDP)
python backbone_image_classifier.py --trainer.gpus 2 --trainer.strategy 'ddp'

PyTorch Profiler

This script shows you how to activate the PyTorch Profiler with Lightning.

python profiler_example.py