Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions neps_examples/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
"pytorch_native_ddp",
"pytorch_lightning_ddp",
],
"async_evaluation": [
"submit",
],
"experimental": [
"ask_and_tell_example",
"freeze_thaw",
],
}

core_examples = [ # Run locally and on github actions
Expand Down
13 changes: 11 additions & 2 deletions neps_examples/efficiency/pytorch_lightning_ddp.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import platform

import lightning as L
import torch
Expand All @@ -7,7 +8,7 @@
from torch.utils.data import DataLoader, random_split
import neps

NUM_GPU = 8 # Number of GPUs to use for DDP
NUM_GPU = 4 # Number of GPUs to use for DDP


class ToyModel(nn.Module):
Expand Down Expand Up @@ -55,6 +56,14 @@ def configure_optimizers(self):


def evaluate_pipeline(lr=0.1, epoch=20):
if platform.system() != "Linux":
raise RuntimeError(
"This example uses torch.distributed via Lightning's DDP "
f"strategy, which is only supported on Linux here. Detected "
f"platform: {platform.system()}. Run it on a Linux machine with "
"GPUs (e.g. a Linux GPU cluster)."
)

L.seed_everything(42)
# Model
model = LightningModel(lr=lr)
Expand Down Expand Up @@ -86,7 +95,7 @@ def evaluate_pipeline(lr=0.1, epoch=20):


class HPOSpace(neps.PipelineSpace):
lr = neps.Float(lower=0.001, upper=0.1, log=True, prior=0.01)
lr = neps.Float(lower=0.001, upper=0.1, log=True, prior=0.01, prior_confidence="high")
epoch = neps.IntegerFidelity(lower=1, upper=3)


Expand Down
15 changes: 12 additions & 3 deletions neps_examples/efficiency/pytorch_lightning_fsdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

Mind that this example does not run on Windows at the moment."""

import platform

import torch
import torch.nn.functional as F
from torch.utils.data import DataLoader
Expand Down Expand Up @@ -35,6 +37,13 @@ def configure_optimizers(self):


def evaluate_pipeline(lr=0.1, epoch=20):
if platform.system() != "Linux":
raise RuntimeError(
"This example uses FSDP with the NCCL backend, which only runs on "
f"Linux. Detected platform: {platform.system()}. Run it on a Linux "
"machine with GPUs (e.g. a Linux GPU cluster)."
)

L.seed_everything(42)

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

# Trainer
trainer = L.Trainer(accelerator="cuda", strategy=FSDPStrategy())
trainer.fit(model, train_dataloader, max_epochs=epoch)
trainer = L.Trainer(accelerator="cuda", strategy=FSDPStrategy(), max_epochs=epoch)
trainer.fit(model, train_dataloader)
return trainer.logged_metrics["train_loss"].detach().item()


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

class HPOSpace(neps.PipelineSpace):
lr = neps.Float(lower=0.001, upper=0.1, log=True, prior=0.01)
lr = neps.Float(lower=0.001, upper=0.1, log=True, prior=0.01, prior_confidence="high")
epoch = neps.IntegerFidelity(lower=1, upper=3)

neps.run(
Expand Down
10 changes: 9 additions & 1 deletion neps_examples/efficiency/pytorch_native_ddp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Mind that this example does not run on Windows at the moment."""

import os
import platform
import sys
import tempfile
import torch
Expand All @@ -16,7 +17,7 @@
import neps
import logging

NUM_GPU = 8 # Number of GPUs to use for DDP
NUM_GPU = 4 # Number of GPUs to use for DDP

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


def evaluate_pipeline(learning_rate, epochs):
if platform.system() != "Linux":
raise RuntimeError(
"This example uses torch.distributed DDP, which is only supported "
f"on Linux here. Detected platform: {platform.system()}. Run it on "
"a Linux machine with GPUs (e.g. a Linux GPU cluster)."
)

from torch.multiprocessing import Manager

world_size = NUM_GPU # Number of GPUs
Expand Down
10 changes: 9 additions & 1 deletion neps_examples/efficiency/pytorch_native_fsdp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import math
import os
import functools
import platform
import torch
import torch.nn as nn
import torch.nn.functional as F
Expand Down Expand Up @@ -189,6 +190,13 @@ def fsdp_main(rank, world_size, test_loss_tensor, lr, epochs, save_model=False):


def evaluate_pipeline(lr=0.1, epoch=20):
if platform.system() != "Linux":
raise RuntimeError(
"This example uses FSDP with the NCCL backend, which only runs on "
f"Linux. Detected platform: {platform.system()}. Run it on a Linux "
"machine with GPUs (e.g. a Linux GPU cluster)."
)

torch.manual_seed(42)

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

class HPOSpace(neps.PipelineSpace):
lr = neps.Float(lower=0.0001, upper=0.1, log=True, prior=0.01)
lr = neps.Float(lower=0.0001, upper=0.1, log=True, prior=0.01, prior_confidence="high")
epoch = neps.IntegerFidelity(lower=1, upper=3)

neps.run(
Expand Down
Loading