Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[App] Improve LightningTrainerScript start-up time #15751

Merged
merged 4 commits into from Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/app_multi_node/train_pytorch.py
Expand Up @@ -23,7 +23,7 @@ def distributed_train(local_rank: int, main_address: str, main_port: int, num_no
# 2. PREPARE DISTRIBUTED MODEL
model = torch.nn.Linear(32, 2)
device = torch.device(f"cuda:{local_rank}") if torch.cuda.is_available() else torch.device("cpu")
model = DistributedDataParallel(model, device_ids=[local_rank]).to(device)
model = DistributedDataParallel(model, device_ids=[local_rank] if torch.cuda.is_available() else None).to(device)

# 3. SETUP LOSS AND OPTIMIZER
criterion = torch.nn.MSELoss()
Expand Down Expand Up @@ -55,7 +55,7 @@ def run(self, main_address: str, main_port: int, num_nodes: int, node_rank: int)
)


# 32 GPUs: (8 nodes x 4 v 100)
# 32 GPUs: (2 nodes x 4 v 100)
compute = L.CloudCompute("gpu-fast-multi") # 4xV100
component = MultiNode(PyTorchDistributed, num_nodes=2, cloud_compute=compute)
app = L.LightningApp(component)
31 changes: 13 additions & 18 deletions src/lightning_app/components/training.py
Expand Up @@ -147,33 +147,28 @@ def __init__(
the ServableModule API
"""
super().__init__()
self.ws = structures.List()
self.has_initialized = False
self.script_path = script_path
self.script_args = script_args
self.num_nodes = num_nodes
self._cloud_compute = cloud_compute # TODO: Add support for cloudCompute
self.sanity_serving = sanity_serving
self._script_runner = script_runner
self._script_runner_kwargs = script_runner_kwargs

def run(self, **run_kwargs):
if not self.has_initialized:
for node_rank in range(self.num_nodes):
self.ws.append(
self._script_runner(
script_path=self.script_path,
script_args=self.script_args,
cloud_compute=self._cloud_compute,
node_rank=node_rank,
sanity_serving=self.sanity_serving,
num_nodes=self.num_nodes,
**self._script_runner_kwargs,
)
self.ws = structures.List()
for node_rank in range(self.num_nodes):
self.ws.append(
self._script_runner(
script_path=self.script_path,
script_args=self.script_args,
cloud_compute=cloud_compute,
node_rank=node_rank,
sanity_serving=self.sanity_serving,
num_nodes=self.num_nodes,
**self._script_runner_kwargs,
)
)

self.has_initialized = True

def run(self, **run_kwargs):
for work in self.ws:
if all(w.internal_ip for w in self.ws):
internal_urls = [(w.internal_ip, w.port) for w in self.ws]
Expand Down