forked from Lightning-AI/pytorch-lightning
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
IK
committed
Apr 1, 2020
1 parent
7de51f7
commit 7eac3d8
Showing
11 changed files
with
279 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# An unique identifier for the head node and workers of this cluster. | ||
cluster_name: local | ||
|
||
## NOTE: Typically for local clusters, min_workers == initial_workers == max_workers. | ||
|
||
# The minimum number of workers nodes to launch in addition to the head | ||
# node. This number should be >= 0. | ||
# Typically, min_workers == initial_workers == max_workers. | ||
min_workers: 0 | ||
# The initial number of worker nodes to launch in addition to the head node. | ||
# Typically, min_workers == initial_workers == max_workers. | ||
initial_workers: 0 | ||
|
||
# The maximum number of workers nodes to launch in addition to the head node. | ||
# This takes precedence over min_workers. | ||
# Typically, min_workers == initial_workers == max_workers. | ||
max_workers: 0 | ||
|
||
# Autoscaling parameters. | ||
# Ignore this if min_workers == initial_workers == max_workers. | ||
autoscaling_mode: default | ||
target_utilization_fraction: 0.8 | ||
idle_timeout_minutes: 5 | ||
|
||
# This executes all commands on all nodes in the docker container, | ||
# and opens all the necessary ports to support the Ray cluster. | ||
# Empty string means disabled. Assumes Docker is installed. | ||
docker: | ||
image: "" # e.g., tensorflow/tensorflow:1.5.0-py3 | ||
container_name: "" # e.g. ray_docker | ||
# If true, pulls latest version of image. Otherwise, `docker run` will only pull the image | ||
# if no cached version is present. | ||
pull_before_run: True | ||
run_options: [] # Extra options to pass into "docker run" | ||
|
||
# Local specific configuration. | ||
provider: | ||
type: local | ||
head_ip: 127.0.0.1 | ||
worker_ips: [] | ||
|
||
# How Ray will authenticate with newly launched nodes. | ||
auth: | ||
ssh_user: nada | ||
ssh_private_key: ~/.ssh/id_rsa | ||
|
||
# Leave this empty. | ||
head_node: {} | ||
|
||
# Leave this empty. | ||
worker_nodes: {} | ||
|
||
# Files or directories to copy to the head and worker nodes. The format is a | ||
# dictionary from REMOTE_PATH: LOCAL_PATH, e.g. | ||
file_mounts: { | ||
# "/path1/on/remote/machine": "/path1/on/local/machine", | ||
# "/path2/on/remote/machine": "/path2/on/local/machine", | ||
} | ||
|
||
# List of commands that will be run before `setup_commands`. If docker is | ||
# enabled, these commands will run outside the container and before docker | ||
# is setup. | ||
initialization_commands: [] | ||
|
||
# List of shell commands to run to set up each nodes. | ||
setup_commands: | ||
- pip install -U ray | ||
|
||
# Custom commands that will be run on the head node after common setup. | ||
head_setup_commands: [] | ||
|
||
# Custom commands that will be run on worker nodes after common setup. | ||
worker_setup_commands: [] | ||
|
||
# Command to start ray on the head node. You don't need to change this. | ||
head_start_ray_commands: | ||
- ray stop | ||
- ulimit -c unlimited && ray start --head --redis-port=6379 --autoscaling-config=~/ray_bootstrap_config.yaml | ||
|
||
# Command to start ray on worker nodes. You don't need to change this. | ||
worker_start_ray_commands: | ||
- ray stop | ||
- ray start --address=$RAY_HEAD_IP:6379 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import ray | ||
from torch.utils.data import TensorDataset, DataLoader | ||
|
||
from pytorch_lightning import LightningModule | ||
import torch.nn.functional as F | ||
|
||
import torch as pt | ||
class Foo(LightningModule): | ||
def __init__(self,batch_size=5): | ||
super().__init__() | ||
self.batch_size=10 | ||
self.linear=pt.nn.Linear(3,10) | ||
self.linear2=pt.nn.Linear(10,3) | ||
self.loss=pt.nn.CrossEntropyLoss() | ||
def prepare_data(self) -> None: | ||
self.ts=TensorDataset(pt.randn(100,3),pt.randint(3,[100])) | ||
self.vs = TensorDataset(pt.randn(100, 3), pt.randint(3,[100])) | ||
self.tts = TensorDataset(pt.randn(100, 3), pt.randint(3,[100])) | ||
def train_dataloader(self) -> DataLoader: | ||
return DataLoader(self.ts,batch_size=self.batch_size,shuffle=True) | ||
def configure_optimizers(self): | ||
return pt.optim.Adam(self.parameters()) | ||
def forward(self, x): | ||
x=self.linear(x) | ||
x=F.relu(x) | ||
x=self.linear2(x) | ||
return x | ||
def training_step(self, batch,batch_idx): | ||
x,y=batch | ||
yhat=self.forward(x) | ||
print(yhat.shape) | ||
loss=self.loss(yhat,y) | ||
ret={"loss":loss} | ||
print(ret) | ||
return ret | ||
from pytorch_lightning.utilities.ray import RayTrainer,RayRemoteTrainer | ||
|
||
@ray.remote(num_gpus=None) | ||
class RayRemote(RayRemoteTrainer): | ||
pass | ||
|
||
trainer=RayTrainer(RayRemote,num_nodes=1,distributed_backend="ddp",_ray_random_seed=5,gpus=None) | ||
trainer.make_model(lambda: Foo()) | ||
sd=trainer.fit() | ||
print(sd) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.