lightning/examples/fabric/image_classifier
Jirka Borovec fe535970a9
lint: switch `pyupgrade` with Ruff's `UP` rule (#19638)
* ruff
* configure
* update

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-03-15 20:48:17 +01:00
..
README.md Rename `fabric run model` to `fabric run` (#19527) 2024-02-27 11:36:46 -05:00
train_fabric.py lint: switch `pyupgrade` with Ruff's `UP` rule (#19638) 2024-03-15 20:48:17 +01:00
train_torch.py lint: switch `pyupgrade` with Ruff's `UP` rule (#19638) 2024-03-15 20:48:17 +01:00

README.md

MNIST Examples

Here are two MNIST classifiers implemented in PyTorch. The first one is implemented in pure PyTorch, but isn't easy to scale. The second one is using Lightning Fabric to accelerate and scale the model.

Tip: You can easily inspect the difference between the two files with:

sdiff train_torch.py train_fabric.py

1. Image Classifier with Vanilla PyTorch

Trains a simple CNN over MNIST using vanilla PyTorch. It only supports single GPU training.

# CPU
python train_torch.py

2. Image Classifier with Lightning Fabric

This script shows you how to scale the pure PyTorch code to enable GPU and multi-GPU training using Lightning Fabric.

# CPU
fabric run train_fabric.py

# GPU (CUDA or M1 Mac)
fabric run train_fabric.py --accelerator=gpu

# Multiple GPUs
fabric run train_fabric.py --accelerator=gpu --devices=4