Level 3: Save money on cloud costs¶
Audience: Users who want to use the AWS cloud efficiently.
Prereqs: You must have finished level 1.
Save money with these optimizations¶
A Lightning component gives you fine-grain control over the cloud lifecycle of that component.
Here are a few features that will enable you save a lot on your cloud costs:
15+ accelerators
Auto-stop idle machines
Auto-timeout submitted work
Use spot machines (~70% discount)
Work with massive datasets
Mount cloud storage
Use a custom container
# app.py
from lightning.app import LightningWork, LightningApp, CloudCompute
class YourComponent(LightningWork):
def run(self):
print('RUN ANY PYTHON CODE HERE')
# custom accelerators
compute = CloudCompute('gpu')
component = YourComponent(cloud_compute=compute)
app = LightningApp(component)
# OTHER ACCELERATORS:
# compute = CloudCompute('default') # 1 CPU
# compute = CloudCompute('cpu-medium') # 8 CPUs
# compute = CloudCompute('gpu') # 1 T4 GPU
# compute = CloudCompute('gpu-fast-multi') # 4 V100 GPU
# compute = CloudCompute('p4d.24xlarge') # AWS instance name (8 A100 GPU)
# compute = ...
# app.py
from lightning.app import LightningWork, LightningApp, CloudCompute
class YourComponent(LightningWork):
def run(self):
print('RUN ANY PYTHON CODE HERE')
# stop the machine when idle for 10 seconds
compute = CloudCompute('gpu', idle_timeout=10)
component = YourComponent(cloud_compute=compute)
app = LightningApp(component)
# app.py
from lightning.app import LightningWork, LightningApp, CloudCompute
class YourComponent(LightningWork):
def run(self):
print('RUN ANY PYTHON CODE HERE')
# if the machine hasn't started after 60 seconds, cancel the work
compute = CloudCompute('gpu', wait_timeout=60)
component = YourComponent(cloud_compute=compute)
app = LightningApp(component)
# app.py
from lightning.app import LightningWork, LightningApp, CloudCompute
class YourComponent(LightningWork):
def run(self):
print('RUN ANY PYTHON CODE HERE')
# spot machines can be turned off without notice, use for non-critical, resumable work
# request a spot machine, after 60 seconds of waiting switch to full-price
compute = CloudCompute('gpu', wait_timeout=60, spot=True)
component = YourComponent(cloud_compute=compute)
app = LightningApp(component)
# app.py
from lightning.app import LightningWork, LightningApp, CloudCompute
class YourComponent(LightningWork):
def run(self):
print('RUN ANY PYTHON CODE HERE')
# use 100 GB of space on that machine (max size: 64 TB)
compute = CloudCompute('gpu', disk_size=100)
component = YourComponent(cloud_compute=compute)
app = LightningApp(component)
from lightning.app import LightningWork, LightningApp, CloudCompute
import os
class YourComponent(LightningWork):
def run(self):
os.listdir('/foo')
# mount the files on the s3 bucket under this path
mount = Mount(source="s3://lightning-example-public/", mount_path="/foo")
compute = CloudCompute(mounts=mount)
component = YourComponent(cloud_compute=compute)
app = LightningApp(component)
# app.py
from lightning.app import LightningWork, LightningApp
class YourComponent(LightningWork):
def run(self):
print('RUN ANY PYTHON CODE HERE')
# custom image (from any provider)
config= BuildConfig(image="gcr.io/google-samples/hello-app:1.0")
component = YourComponent(cloud_build_config=config)
app = LightningApp(component)
Next: Coordinate 2+ components¶
Now that you know how to organize arbitrary code inside a Lightning component, learn to coordinate 2 or more components into workflows which we call Lightning apps.