@@ -39,35 +39,35 @@ ______________________________________________________________________
39
39
-->
40
40
41
41
</div >
42
+
43
+ ## Install Lightning
44
+
45
+ ``` bash
46
+ pip install lightning
47
+ ```
42
48
______________________________________________________________________
43
49
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.
45
53
46
- PyTorch Lightning is just organized PyTorch- Lightning disentangles PyTorch code to decouple the science from the engineering.
47
54
![ PT to PL] ( docs/source-pytorch/_static/images/general/pl_quick_start_full_compressed.gif )
48
55
49
- <details >
50
- <summary >How to use PyTorch Lightning</summary >
56
+ ----
51
57
52
- ### Step 1: Add these imports
58
+ ### Hello simple model
53
59
54
60
``` 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
55
64
import lightning as L
56
65
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).
67
70
68
- A LightningModule defines a full * system* (ie: a GAN, autoencoder, BERT or a simple Image Classifier).
69
-
70
- ``` python
71
71
class LitAutoEncoder (L .LightningModule ):
72
72
def __init__ (self ):
73
73
super ().__init__ ()
@@ -92,19 +92,25 @@ class LitAutoEncoder(L.LightningModule):
92
92
def configure_optimizers (self ):
93
93
optimizer = torch.optim.Adam(self .parameters(), lr = 1e-3 )
94
94
return optimizer
95
- ```
96
-
97
- ** Note: Training_step defines the training loop. Forward defines how the LightningModule behaves during inference/prediction.**
98
95
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 ])
104
101
102
+ # -------------------
103
+ # Step 3: Train
104
+ # -------------------
105
105
autoencoder = LitAutoEncoder()
106
106
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
108
114
```
109
115
110
116
## Advanced features
0 commit comments