2023-01-04 15:57:18 +00:00
## MNIST Examples
Here are two MNIST classifiers implemented in PyTorch.
The first one is implemented in pure PyTorch, but isn't easy to scale.
2023-03-15 19:19:41 +00:00
The second one is using [Lightning Fabric ](https://lightning.ai/docs/fabric ) to accelerate and scale the model.
2023-01-04 15:57:18 +00:00
2023-01-05 14:07:43 +00:00
Tip: You can easily inspect the difference between the two files with:
```bash
2023-01-12 14:31:34 +00:00
sdiff train_torch.py train_fabric.py
2023-01-05 14:07:43 +00:00
```
2023-01-04 15:57:18 +00:00
#### 1. Image Classifier with Vanilla PyTorch
2023-09-26 15:54:44 +00:00
Trains a simple CNN over MNIST using vanilla PyTorch. It only supports single GPU training.
2023-01-04 15:57:18 +00:00
```bash
# CPU
2023-01-05 14:07:43 +00:00
python train_torch.py
2023-01-04 15:57:18 +00:00
```
______________________________________________________________________
#### 2. Image Classifier with Lightning Fabric
2023-03-15 19:19:41 +00:00
This script shows you how to scale the pure PyTorch code to enable GPU and multi-GPU training using [Lightning Fabric ](https://lightning.ai/docs/fabric ).
2023-01-04 15:57:18 +00:00
```bash
# CPU
2024-02-27 16:36:46 +00:00
fabric run train_fabric.py
2023-01-04 15:57:18 +00:00
# GPU (CUDA or M1 Mac)
2024-02-27 16:36:46 +00:00
fabric run train_fabric.py --accelerator=gpu
2023-01-04 15:57:18 +00:00
# Multiple GPUs
2024-02-27 16:36:46 +00:00
fabric run train_fabric.py --accelerator=gpu --devices=4
2023-01-04 15:57:18 +00:00
```