• Docs >
  • Evolve a model into an ML system

Evolve a model into an ML system

Required background: Basic Python familiarity and complete the Build and Train a Model guide.

Goal: We’ll walk you through the two key steps to build your first Lightning App from your existing PyTorch Lightning scripts.

Training and beyond

With PyTorch Lightning, we abstracted distributed training and hardware, by organizing PyTorch code. With Lightning Apps, we unified the local and cloud experience while abstracting infrastructure.

By using PyTorch Lightning and Lightning Apps together, a completely new world of possibilities emerges.

From PyTorch Lightning to Lightning App

1. Write an App to run the train.py script

This article continues where the Build and Train a Model guide finished.

Create an additional file app.py in the pl_project folder as follows:


Inside the app.py file, add the following code.

from lightning.app import LightningFlow, LightningApp, CloudCompute
from lightning.app.components import TracerPythonScript

class RootFlow(LightningFlow):
    def __init__(self):
        self.runner = TracerPythonScript(

    def run(self):

app = LightningApp(RootFlow())

This App runs the PyTorch Lightning script contained in the train.py file using the powerful TracerPythonScript component. This is really worth checking out!

2. Run the train.py file locally or in the cloud

First, go to the pl_folder folder from the local terminal and install the requirements.

cd pl_folder
pip install -r requirements.txt

To run your app, copy the following command to your local terminal:

lightning_app run app app.py

Simply add --cloud to run this application in the cloud with a GPU machine 🤯

lightning_app run app app.py --cloud

Congratulations! Now, you know how to run a PyTorch Lightning script with Lightning Apps.

Lightning Apps can make your ML system way more powerful, keep reading to learn how.

Next Steps