• Docs >
  • Run in the Lightning Cloud
Shortcuts

Run in the Lightning Cloud

Audience: Users who don’t want to waste time on cluster configuration and maintenance.

The Lightning AI cloud is a platform where you can build, train, finetune and deploy models without worrying about infrastructure, cost management, scaling, and other technical headaches. In this guide, and within just 10 minutes, you will learn how to run a Fabric training script across multiple nodes in the cloud.


Initial Setup

First, create a free Lightning AI account. Then, log in from the CLI:

lightning login

A page opens in your browser where you can follow the instructions to complete the setup.


Launch multi-node training in the cloud

Step 1: Put your code inside a LightningWork:

app.py
import lightning as L
from lightning.app.components import FabricMultiNode


# 1. Put your code inside a LightningWork
class MyTrainingComponent(L.LightningWork):
    def run(self):
        # Set up Fabric
        # The `devices` and `num_nodes` gets set by Lightning automatically
        fabric = L.Fabric(strategy="ddp", precision="16-mixed")

        # Your training code
        model = ...
        optimizer = ...
        model, optimizer = fabric.setup(model, optimizer)
        ...

Step 2: Init a LightningApp with the FabricMultiNode component. Configure the number of nodes, the number of GPUs per node, and the type of GPU:

app.py
# 2. Create the app with the FabricMultiNode component inside
app = L.LightningApp(
    FabricMultiNode(
        MyTrainingComponent,
        # Run with 2 nodes
        num_nodes=2,
        # Each with 4 x V100 GPUs, total 8 GPUs
        cloud_compute=L.CloudCompute("gpu-fast-multi"),
    )
)

Step 3: Run your code from the CLI:

lightning run app app.py --cloud

This command will upload your Python file and then opens the app admin view, where you can see the logs of what’s happening.

The Lightning AI admin page of an app running a multi-node fabric training script

Next steps


© Copyright Copyright (c) 2018-2023, Lightning AI et al...

Built with Sphinx using a theme provided by Read the Docs.