Skip to content

Commit c43b23b

Browse files
authored
Rename LightningLite (6/n) (#15982)
1 parent deac2b5 commit c43b23b

File tree

11 files changed

+67
-67
lines changed

11 files changed

+67
-67
lines changed

.azure/gpu-tests-fabric.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ pr:
2323
include:
2424
- ".actions/**"
2525
- ".azure/gpu-tests-fabric.yml"
26-
- "examples/lite/**"
27-
- "examples/run_lite_examples.sh"
26+
- "examples/fabric/**"
27+
- "examples/run_fabric_examples.sh"
2828
- "tests/tests_lite/run_standalone_*.sh"
2929
- "tests/tests_pytorch/run_standalone_tests.sh" # used by Lite through a symlink
3030
- "requirements/fabric/**"
@@ -126,9 +126,9 @@ jobs:
126126

127127
- script: |
128128
# In order to run the examples, we need to substitute the meta package imports with the standalone package
129-
python ../.actions/assistant.py copy_replace_imports --source_dir="./lite" --source_import="lightning.fabric" --target_import="lightning_fabric.fabric"
129+
python ../.actions/assistant.py copy_replace_imports --source_dir="./fabric" --source_import="lightning.fabric" --target_import="lightning_fabric.fabric"
130130
set -e
131-
bash run_lite_examples.sh --accelerator=cuda --devices=1
132-
bash run_lite_examples.sh --accelerator=cuda --devices=2 --strategy ddp
131+
bash run_fabric_examples.sh --accelerator=cuda --devices=1
132+
bash run_fabric_examples.sh --accelerator=cuda --devices=2 --strategy ddp
133133
workingDirectory: examples
134134
displayName: 'Testing: Lite examples'

.github/checkgroup.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,8 @@ subprojects:
204204
paths:
205205
- ".actions/**"
206206
- ".azure/gpu-tests-fabric.yml"
207-
- "examples/lite/**"
208-
- "examples/run_lite_examples.sh"
207+
- "examples/fabric/**"
208+
- "examples/run_fabric_examples.sh"
209209
- "tests/tests_lite/run_standalone_*.sh"
210210
- "tests/tests_pytorch/run_standalone_tests.sh" # used by Lite through a symlink
211211
- "requirements/fabric/**"

examples/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ ______________________________________________________________________
1111

1212
______________________________________________________________________
1313

14-
## Lightning Lite Examples
14+
## Lightning Fabric Examples
1515

16-
We show how to accelerate your PyTorch code with [Lightning Lite](https://pytorch-lightning.readthedocs.io/en/latest/starter/lightning_lite.html) with minimal code changes.
16+
We show how to accelerate your PyTorch code with [Lightning Fabric](https://pytorch-lightning.readthedocs.io/en/latest/starter/lightning_fabric.html) with minimal code changes.
1717
You stay in full control of the training loop.
1818

19-
- [MNIST with vanilla PyTorch](lite/image_classifier_1_pytorch.py)
20-
- [MNIST with Lightning Lite](lite/image_classifier_2_lite.py)
19+
- [MNIST with vanilla PyTorch](fabric/image_classifier_1_pytorch.py)
20+
- [MNIST with Lightning Fabric](fabric/image_classifier_2_fabric.py)
2121

2222
______________________________________________________________________
2323

examples/app_multi_node/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ or you can use the built-in component for it.
1818
lightning run app train_pytorch_spawn.py
1919
```
2020

21-
## Multi Node with raw PyTorch + Lite
21+
## Multi Node with raw PyTorch + Fabric
2222

23-
You can run the multi-node raw PyTorch and Lite by running the following commands.
23+
You can run the multi-node raw PyTorch and Fabric by running the following commands.
2424

2525
```bash
26-
lightning run app train_lite.py
26+
lightning run app train_fabric.py
2727
```
2828

29-
Using Lite, you retain control over your loops while accessing in a minimal way all Lightning distributed strategies.
29+
Using Fabric, you retain control over your loops while accessing in a minimal way all Lightning distributed strategies.
3030

3131
## Multi Node with Lightning Trainer
3232

examples/app_multi_node/train_lite.py renamed to examples/app_multi_node/train_fabric.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ def run(self):
1515
)
1616

1717
# 2. Create Fabric.
18-
lite = Fabric(strategy="ddp", precision=16)
19-
model, optimizer = lite.setup(model, torch.optim.SGD(model.parameters(), lr=0.01))
18+
fabric = Fabric(strategy="ddp", precision=16)
19+
model, optimizer = fabric.setup(model, torch.optim.SGD(model.parameters(), lr=0.01))
2020
criterion = torch.nn.MSELoss()
2121

2222
# 3. Train the model for 1000 steps.
2323
for step in range(1000):
2424
model.zero_grad()
25-
x = torch.tensor([0.8]).to(lite.device)
26-
target = torch.tensor([1.0]).to(lite.device)
25+
x = torch.tensor([0.8]).to(fabric.device)
26+
target = torch.tensor([1.0]).to(fabric.device)
2727
output = model(x)
2828
loss = criterion(output, target)
29-
print(f"global_rank: {lite.global_rank} step: {step} loss: {loss}")
30-
lite.backward(loss)
29+
print(f"global_rank: {fabric.global_rank} step: {step} loss: {loss}")
30+
fabric.backward(loss)
3131
optimizer.step()
3232

3333

examples/fabric/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## MNIST Examples
2+
3+
Here are two MNIST classifiers implemented in PyTorch.
4+
The first one is implemented in pure PyTorch, but isn't easy to scale.
5+
The second one is using [Lightning Fabric](https://pytorch-lightning.readthedocs.io/en/stable/starter/lightning_fabric.html) to accelerate and scale the model.
6+
7+
#### 1. Image Classifier with Vanilla PyTorch
8+
9+
Trains a simple CNN over MNIST using vanilla PyTorch. It only supports singe GPU training.
10+
11+
```bash
12+
# CPU
13+
python image_classifier_1_pytorch.py
14+
```
15+
16+
______________________________________________________________________
17+
18+
#### 2. Image Classifier with Lightning Fabric
19+
20+
This script shows you how to scale the pure PyTorch code to enable GPU and multi-GPU training using [Lightning Fabric](https://pytorch-lightning.readthedocs.io/en/stable/starter/lightning_fabric.html).
21+
22+
```bash
23+
# CPU
24+
lightning run model image_classifier_2_fabric.py
25+
26+
# GPU (CUDA or M1 Mac)
27+
lightning run model image_classifier_2_fabric.py --accelerator=gpu
28+
29+
# Multiple GPUs
30+
lightning run model image_classifier_2_fabric.py --accelerator=gpu --devices=4
31+
```
File renamed without changes.

examples/lite/image_classifier_2_lite.py renamed to examples/fabric/image_classifier_2_fabric.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
"""Here are 4 easy steps to use Fabric in your PyTorch code.
1616
17-
1. Create the Lightning Lite object at the beginning of your script.
17+
1. Create the Lightning Fabric object at the beginning of your script.
1818
1919
2. Remove all ``.to`` and ``.cuda`` calls since Fabric will take care of it.
2020
@@ -25,7 +25,7 @@
2525
2626
Accelerate your training loop by setting the ``--accelerator``, ``--strategy``, ``--devices`` options directly from
2727
the command line. See ``lightning run model --help`` or learn more from the documentation:
28-
https://pytorch-lightning.readthedocs.io/en/latest/starter/lightning_lite.lite.html.
28+
https://pytorch-lightning.readthedocs.io/en/latest/starter/lightning_fabric.html.
2929
"""
3030

3131
import argparse
@@ -47,18 +47,18 @@
4747

4848

4949
def run(hparams):
50-
# Create the Lightning Lite object. The parameters like accelerator, strategy, devices etc. will be proided
50+
# Create the Lightning Fabric object. The parameters like accelerator, strategy, devices etc. will be proided
5151
# by the command line. See all options: `lightning run model --help`
52-
lite = Fabric()
52+
fabric = Fabric()
5353

54-
lite.hparams = hparams
54+
fabric.hparams = hparams
5555
seed_everything(hparams.seed) # instead of torch.manual_seed(...)
5656

5757
transform = T.Compose([T.ToTensor(), T.Normalize((0.1307,), (0.3081,))])
5858
# This is meant to ensure the data are download only by 1 process.
59-
if lite.is_global_zero:
59+
if fabric.is_global_zero:
6060
MNIST(DATASETS_PATH, download=True)
61-
lite.barrier()
61+
fabric.barrier()
6262
train_dataset = MNIST(DATASETS_PATH, train=True, transform=transform)
6363
test_dataset = MNIST(DATASETS_PATH, train=False, transform=transform)
6464
train_loader = torch.utils.data.DataLoader(
@@ -68,19 +68,19 @@ def run(hparams):
6868
test_loader = torch.utils.data.DataLoader(test_dataset, batch_size=hparams.batch_size)
6969

7070
# don't forget to call `setup_dataloaders` to prepare for dataloaders for distributed training.
71-
train_loader, test_loader = lite.setup_dataloaders(train_loader, test_loader)
71+
train_loader, test_loader = fabric.setup_dataloaders(train_loader, test_loader)
7272

7373
model = Net() # remove call to .to(device)
7474
optimizer = optim.Adadelta(model.parameters(), lr=hparams.lr)
7575

7676
# don't forget to call `setup` to prepare for model / optimizer for distributed training.
7777
# the model is moved automatically to the right device.
78-
model, optimizer = lite.setup(model, optimizer)
78+
model, optimizer = fabric.setup(model, optimizer)
7979

8080
scheduler = StepLR(optimizer, step_size=1, gamma=hparams.gamma)
8181

8282
# use torchmetrics instead of manually computing the accuracy
83-
test_acc = Accuracy().to(lite.device)
83+
test_acc = Accuracy().to(fabric.device)
8484

8585
# EPOCH LOOP
8686
for epoch in range(1, hparams.epochs + 1):
@@ -92,7 +92,7 @@ def run(hparams):
9292
optimizer.zero_grad()
9393
output = model(data)
9494
loss = F.nll_loss(output, target)
95-
lite.backward(loss) # instead of loss.backward()
95+
fabric.backward(loss) # instead of loss.backward()
9696

9797
optimizer.step()
9898
if (batch_idx == 0) or ((batch_idx + 1) % hparams.log_interval == 0):
@@ -130,18 +130,18 @@ def run(hparams):
130130
break
131131

132132
# all_gather is used to aggregated the value across processes
133-
test_loss = lite.all_gather(test_loss).sum() / len(test_loader.dataset)
133+
test_loss = fabric.all_gather(test_loss).sum() / len(test_loader.dataset)
134134

135135
print(f"\nTest set: Average loss: {test_loss:.4f}, Accuracy: ({100 * test_acc.compute():.0f}%)\n")
136136
test_acc.reset()
137137

138138
if hparams.dry_run:
139139
break
140140

141-
# When using distributed training, use `lite.save`
141+
# When using distributed training, use `fabric.save`
142142
# to ensure the current process is allowed to save a checkpoint
143143
if hparams.save_model:
144-
lite.save(model.state_dict(), "mnist_cnn.pt")
144+
fabric.save(model.state_dict(), "mnist_cnn.pt")
145145

146146

147147
if __name__ == "__main__":
File renamed without changes.

examples/lite/README.md

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)