Skip to content

Commit 6c9be15

Browse files
Update README.md
1 parent 5661988 commit 6c9be15

File tree

1 file changed

+33
-27
lines changed

1 file changed

+33
-27
lines changed

README.md

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -39,35 +39,35 @@ ______________________________________________________________________
3939
-->
4040

4141
</div>
42+
43+
## Install Lightning
44+
45+
```bash
46+
pip install lightning
47+
```
4248
______________________________________________________________________
4349

44-
## Train and deploy with PyTorch Lightning
50+
## Train and deploy PyTorch with Lightning
51+
52+
PyTorch Lightning is just organized PyTorch - Lightning disentangles PyTorch code to decouple the science from the engineering.
4553

46-
PyTorch Lightning is just organized PyTorch- Lightning disentangles PyTorch code to decouple the science from the engineering.
4754
![PT to PL](docs/source-pytorch/_static/images/general/pl_quick_start_full_compressed.gif)
4855

49-
<details>
50-
<summary>How to use PyTorch Lightning</summary>
56+
----
5157

52-
### Step 1: Add these imports
58+
### Hello simple model
5359

5460
```python
61+
# main.py
62+
# ! pip install torchvision
63+
import os, torch, torch.nn as nn, torch.utils.data as data, torchvision as tv, torch.nn.functional as F
5564
import lightning as L
5665

57-
import os
58-
import torch
59-
from torch import nn
60-
import torch.nn.functional as F
61-
from torchvision.datasets import MNIST
62-
from torch.utils.data import DataLoader, random_split
63-
from torchvision import transforms
64-
```
65-
66-
### Step 2: Define a LightningModule (nn.Module subclass)
66+
# --------------------------------
67+
# Step 1: Define a LightningModule
68+
# --------------------------------
69+
# A LightningModule (nn.Module subclass) defines a full *system* (ie: an LLM, difussion model, autoencoder, or simple image classifier).
6770

68-
A LightningModule defines a full *system* (ie: a GAN, autoencoder, BERT or a simple Image Classifier).
69-
70-
```python
7171
class LitAutoEncoder(L.LightningModule):
7272
def __init__(self):
7373
super().__init__()
@@ -92,19 +92,25 @@ class LitAutoEncoder(L.LightningModule):
9292
def configure_optimizers(self):
9393
optimizer = torch.optim.Adam(self.parameters(), lr=1e-3)
9494
return optimizer
95-
```
96-
97-
**Note: Training_step defines the training loop. Forward defines how the LightningModule behaves during inference/prediction.**
9895

99-
### Step 3: Train!
100-
101-
```python
102-
dataset = MNIST(os.getcwd(), download=True, transform=transforms.ToTensor())
103-
train, val = random_split(dataset, [55000, 5000])
96+
# -------------------
97+
# Step 2: Define data
98+
# -------------------
99+
dataset = tv.datasets.MNIST(os.getcwd(), download=True, transform=tv.transforms.ToTensor())
100+
train, val = data.random_split(dataset, [55000, 5000])
104101

102+
# -------------------
103+
# Step 3: Train
104+
# -------------------
105105
autoencoder = LitAutoEncoder()
106106
trainer = L.Trainer()
107-
trainer.fit(autoencoder, DataLoader(train), DataLoader(val))
107+
trainer.fit(autoencoder, data.DataLoader(train), data.DataLoader(val))
108+
```
109+
110+
Run the model on your terminal
111+
``` bash
112+
pip install torchvision
113+
python main.py
108114
```
109115

110116
## Advanced features

0 commit comments

Comments
 (0)