Skip to content

Commit c389461

Browse files
authored
chore: pinpoint the platform needed (Linux) for ddp examples (#283)
1 parent 58e57c2 commit c389461

5 files changed

Lines changed: 48 additions & 7 deletions

File tree

neps_examples/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@
2323
"pytorch_native_ddp",
2424
"pytorch_lightning_ddp",
2525
],
26+
"async_evaluation": [
27+
"submit",
28+
],
29+
"experimental": [
30+
"ask_and_tell_example",
31+
"freeze_thaw",
32+
],
2633
}
2734

2835
core_examples = [ # Run locally and on github actions

neps_examples/efficiency/pytorch_lightning_ddp.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import platform
23

34
import lightning as L
45
import torch
@@ -7,7 +8,7 @@
78
from torch.utils.data import DataLoader, random_split
89
import neps
910

10-
NUM_GPU = 8 # Number of GPUs to use for DDP
11+
NUM_GPU = 4 # Number of GPUs to use for DDP
1112

1213

1314
class ToyModel(nn.Module):
@@ -55,6 +56,14 @@ def configure_optimizers(self):
5556

5657

5758
def evaluate_pipeline(lr=0.1, epoch=20):
59+
if platform.system() != "Linux":
60+
raise RuntimeError(
61+
"This example uses torch.distributed via Lightning's DDP "
62+
f"strategy, which is only supported on Linux here. Detected "
63+
f"platform: {platform.system()}. Run it on a Linux machine with "
64+
"GPUs (e.g. a Linux GPU cluster)."
65+
)
66+
5867
L.seed_everything(42)
5968
# Model
6069
model = LightningModel(lr=lr)
@@ -86,7 +95,7 @@ def evaluate_pipeline(lr=0.1, epoch=20):
8695

8796

8897
class HPOSpace(neps.PipelineSpace):
89-
lr = neps.Float(lower=0.001, upper=0.1, log=True, prior=0.01)
98+
lr = neps.Float(lower=0.001, upper=0.1, log=True, prior=0.01, prior_confidence="high")
9099
epoch = neps.IntegerFidelity(lower=1, upper=3)
91100

92101

neps_examples/efficiency/pytorch_lightning_fsdp.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
33
Mind that this example does not run on Windows at the moment."""
44

5+
import platform
6+
57
import torch
68
import torch.nn.functional as F
79
from torch.utils.data import DataLoader
@@ -35,6 +37,13 @@ def configure_optimizers(self):
3537

3638

3739
def evaluate_pipeline(lr=0.1, epoch=20):
40+
if platform.system() != "Linux":
41+
raise RuntimeError(
42+
"This example uses FSDP with the NCCL backend, which only runs on "
43+
f"Linux. Detected platform: {platform.system()}. Run it on a Linux "
44+
"machine with GPUs (e.g. a Linux GPU cluster)."
45+
)
46+
3847
L.seed_everything(42)
3948

4049
# Data
@@ -45,8 +54,8 @@ def evaluate_pipeline(lr=0.1, epoch=20):
4554
model = LanguageModel(vocab_size=dataset.vocab_size, lr=lr)
4655

4756
# Trainer
48-
trainer = L.Trainer(accelerator="cuda", strategy=FSDPStrategy())
49-
trainer.fit(model, train_dataloader, max_epochs=epoch)
57+
trainer = L.Trainer(accelerator="cuda", strategy=FSDPStrategy(), max_epochs=epoch)
58+
trainer.fit(model, train_dataloader)
5059
return trainer.logged_metrics["train_loss"].detach().item()
5160

5261

@@ -57,7 +66,7 @@ def evaluate_pipeline(lr=0.1, epoch=20):
5766
logging.basicConfig(level=logging.INFO)
5867

5968
class HPOSpace(neps.PipelineSpace):
60-
lr = neps.Float(lower=0.001, upper=0.1, log=True, prior=0.01)
69+
lr = neps.Float(lower=0.001, upper=0.1, log=True, prior=0.01, prior_confidence="high")
6170
epoch = neps.IntegerFidelity(lower=1, upper=3)
6271

6372
neps.run(

neps_examples/efficiency/pytorch_native_ddp.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Mind that this example does not run on Windows at the moment."""
44

55
import os
6+
import platform
67
import sys
78
import tempfile
89
import torch
@@ -16,7 +17,7 @@
1617
import neps
1718
import logging
1819

19-
NUM_GPU = 8 # Number of GPUs to use for DDP
20+
NUM_GPU = 4 # Number of GPUs to use for DDP
2021

2122
# On Windows platform, the torch.distributed package only
2223
# supports Gloo backend, FileStore and TcpStore.
@@ -88,6 +89,13 @@ def demo_basic(rank, world_size, loss_dict, learning_rate, epochs):
8889

8990

9091
def evaluate_pipeline(learning_rate, epochs):
92+
if platform.system() != "Linux":
93+
raise RuntimeError(
94+
"This example uses torch.distributed DDP, which is only supported "
95+
f"on Linux here. Detected platform: {platform.system()}. Run it on "
96+
"a Linux machine with GPUs (e.g. a Linux GPU cluster)."
97+
)
98+
9199
from torch.multiprocessing import Manager
92100

93101
world_size = NUM_GPU # Number of GPUs

neps_examples/efficiency/pytorch_native_fsdp.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import math
66
import os
77
import functools
8+
import platform
89
import torch
910
import torch.nn as nn
1011
import torch.nn.functional as F
@@ -189,6 +190,13 @@ def fsdp_main(rank, world_size, test_loss_tensor, lr, epochs, save_model=False):
189190

190191

191192
def evaluate_pipeline(lr=0.1, epoch=20):
193+
if platform.system() != "Linux":
194+
raise RuntimeError(
195+
"This example uses FSDP with the NCCL backend, which only runs on "
196+
f"Linux. Detected platform: {platform.system()}. Run it on a Linux "
197+
"machine with GPUs (e.g. a Linux GPU cluster)."
198+
)
199+
192200
torch.manual_seed(42)
193201

194202
test_loss_tensor = torch.zeros(1)
@@ -209,7 +217,7 @@ def evaluate_pipeline(lr=0.1, epoch=20):
209217
logging.basicConfig(level=logging.INFO)
210218

211219
class HPOSpace(neps.PipelineSpace):
212-
lr = neps.Float(lower=0.0001, upper=0.1, log=True, prior=0.01)
220+
lr = neps.Float(lower=0.0001, upper=0.1, log=True, prior=0.01, prior_confidence="high")
213221
epoch = neps.IntegerFidelity(lower=1, upper=3)
214222

215223
neps.run(

0 commit comments

Comments
 (0)