Skip to content

Commit 2c47738

Browse files
williamFalconBordapre-commit-ci[bot]rlizzo
authored andcommitted
Docs 4/n (#15628)
* remove source-lit * docs * docs * docs * docs * ic * deploy * deploy * deploy * deploy * deploy * deploy * Apply suggestions from code review * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * make build run Co-authored-by: Jirka Borovec <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Rick Izzo <[email protected]> (cherry picked from commit d5c0eff)
1 parent eb87018 commit 2c47738

25 files changed

+224
-128
lines changed

docs/source-app/api_reference/components.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ ___________________
2020

2121
~python.popen.PopenPythonScript
2222
~python.tracer.TracerPythonScript
23-
~training.LightningTrainingComponent
23+
~training.LightningTrainerScript
2424
~serve.gradio.ServeGradio
2525
~serve.serve.ModelInferenceAPI

docs/source-app/api_references.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ ___________________
3434

3535
~python.popen.PopenPythonScript
3636
~python.tracer.TracerPythonScript
37-
~training.LightningTrainingComponent
37+
~training.LightningTrainerScript
3838
~serve.gradio.ServeGradio
3939
~serve.serve.ModelInferenceAPI
4040

docs/source-app/index.rst

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#######################
77
Welcome to ⚡ Lightning
88
#######################
9-
Build models and full stack AI apps ⚡ *Lightning fast*.
9+
Build models, ML components and full stack AI apps ⚡ *Lightning fast*.
1010

1111
.. join_slack::
1212
:align: left
@@ -22,23 +22,22 @@ Build models and full stack AI apps ⚡ *Lightning fast*.
2222

2323
.. app_card::
2424
:title: Develop and Train
25-
:description: Train an LLM (64 GPUs)
25+
:description: Train a model (32 GPUs)
2626
:width: 280
2727
:image: https://lightning-ai-docs.s3.amazonaws.com/develop_n_train_v1.jpg
28-
:preview: https://lightning.ai
29-
:deploy: https://lightning.ai
30-
:target: https://apple.com
31-
:tags: Model
28+
:target: levels/basic/real_lightning_component_implementations.html#ex-pytorch-lightning-trainer
29+
:preview: levels/basic/real_lightning_component_implementations.html#ex-pytorch-lightning-trainer
30+
:tags: Training
3231

3332
.. app_card::
3433
:title: Serve and deploy
35-
:description: Production-ready stable diffusion server (<2s latency)
34+
:description: Production diffusion server (<2s latency)
3635
:width: 280
3736
:app_id: HvUwbEG90E
3837
:image: https://lightning-ai-docs.s3.amazonaws.com/serve_n_deploy_v1.jpg
3938
:deploy: https://lightning.ai
4039
:target: https://01gbx4m78rbkpczdf5cpz2hpbh.litng-ai-03.litng.ai/root.api_component/
41-
:tags: App
40+
:tags: Serving
4241

4342
.. app_card::
4443
:title: Scale and build a product
@@ -47,7 +46,7 @@ Build models and full stack AI apps ⚡ *Lightning fast*.
4746
:app_id: HvUwbEG90E
4847
:image: https://lightning-ai-docs.s3.amazonaws.com/scale_n_build_v1.jpg
4948
:target: https://lightning.ai/muse
50-
:tags: App
49+
:tags: AI App
5150

5251
.. raw:: html
5352

@@ -56,13 +55,14 @@ Build models and full stack AI apps ⚡ *Lightning fast*.
5655

5756
----
5857

59-
****************************************
60-
Build self-contained, modular components
61-
****************************************
62-
Lightning is a hyper-minimalistic framework designed to maximize expressivity that
63-
enables you to build modular, self-contained components and plug them into your existing workflows.
64-
A Lightning component organizes arbitrary code so it can run on the cloud. A component can train a model, deploy, or even host a web UI.
65-
The component manages its own infrastructure, cloud costs, networking and more, so you can focus on application logic and not engineering.
58+
********************************
59+
Build self-contained, components
60+
********************************
61+
Use Lightning, the hyper-minimalistic framework, to build machine learning components that can plug into existing ML workflows.
62+
A Lightning component organizes arbitrary code to run on the cloud, manage its own infrastructure, cloud costs, networking, and more.
63+
Focus on component logic and not engineering.
64+
65+
Use components on their own, or compose them into full-stack AI apps with our next-generation Lightning orchestrator.
6666

6767
.. raw:: html
6868

@@ -78,6 +78,10 @@ The component manages its own infrastructure, cloud costs, networking and more,
7878

7979
.. include:: ./levels/basic/hero_components.rst
8080

81+
|
82+
83+
Components run the same on the cloud and locally on your choice of hardware.
84+
8185
.. lit_tabs::
8286
:code_files: landing_app_run.bash
8387
:highlights: 5

docs/source-app/landing_app_run.bash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# install lightning
22
pip install lightning
33

4-
# run the app
5-
lightning run app app.py --cloud
4+
# run the app on the --cloud (--setup installs deps automatically)
5+
lightning run app app.py --setup --cloud

docs/source-app/levels/basic/build_a_lightning_component.rst

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@ Level 1: Package code in a lightning component
1414
*********************************
1515
Why you need Lightning components
1616
*********************************
17-
A Lightning component organizes a piece of code into a self-contained, modular component that
18-
can be integrated into your existing workflows or assembled to form a Lightning app.
19-
A Lightning component manages its own infrastructure, auto-scaling, cost management, and more, so you
20-
can focus on the program logic and not the cloud engineering.
17+
A Lightning component is a self-contained, modular machine-learning component
18+
that you can plug into your existing ML workflows. A Lightning component organizes arbitrary code so it can run on the cloud, manages
19+
its own infrastructure, cloud costs, networking and more. Connect components using your current workflow management tools or
20+
our `next-generation reactive orchestrator <../intermediate/index.html>`_.
2121

22-
Components run on the cloud or your laptop without code changes 🤯🤯. Connect components using your current workflow management tools or use
23-
Lightning apps to build powerful sequential AND reactive workflows.
22+
Components run on the cloud or your laptop without code changes 🤯🤯.
2423

2524
.. raw:: html
2625

@@ -109,7 +108,7 @@ First, install Lightning.
109108
**************************
110109
Build your first component
111110
**************************
112-
A Lightning component organizes Python code into a self-contained module so it can run on the cloud.
111+
A Lightning component organizes arbitrary code so it can run on the cloud, manages its own infrastructure, cloud costs, networking and more
113112

114113
**Run one of these components!**
115114

@@ -119,12 +118,7 @@ A Lightning component organizes Python code into a self-contained module so it c
119118
120119
Components run the same on the cloud and locally on your choice of hardware.
121120

122-
.. lit_tabs::
123-
:titles: Lightning Cloud (fully-managed); Your AWS account; Your own hardware
124-
:code_files: ./hello_components/code_run_cloud.bash; ./hello_components/code_run_cloud_yours.bash; ./hello_components/code_run_local.bash
125-
:tab_rows: 4
126-
:highlights: ; 5; 0
127-
:height: 195px
121+
.. include:: /levels/basic/hero_run_setup.rst
128122

129123
----
130124

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lightning run app app.py --setup --cloud
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# first create a cluster (creation could take ~30 minutes)
2+
lightning create cluster pikachu --provider aws --role-arn arn:aws:iam::1234567890:role/lai-byoc
3+
4+
# run on that cluster
5+
lightning run app app.py --setup --cloud pikachu
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
lightning run app app.py --setup
Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,31 @@
1-
# A hello world component
2-
# app.py
1+
# !pip install torchvision
32
import lightning as L
3+
from lightning.app.components.serve import PythonServer, Image, Number
4+
import base64, io, torchvision, torch
5+
from PIL import Image as PILImage
46

57

6-
class YourComponent(L.LightningWork):
7-
def run(self):
8-
print('RUN ANY PYTHON CODE HERE')
8+
class PyTorchServer(PythonServer):
9+
def setup(self):
10+
self._model = torchvision.models.resnet18(pretrained=True)
11+
self._device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
12+
self._model.to(self._device)
913

14+
def predict(self, request):
15+
image = base64.b64decode(request.image.encode("utf-8"))
16+
image = PILImage.open(io.BytesIO(image))
17+
transforms = torchvision.transforms.Compose([
18+
torchvision.transforms.Resize(224),
19+
torchvision.transforms.ToTensor(),
20+
torchvision.transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
21+
])
22+
image = transforms(image)
23+
image = image.to(self._device)
24+
prediction = self._model(image.unsqueeze(0))
25+
return {"prediction": prediction.argmax().item()}
1026

1127

12-
# run on a cloud machine
13-
compute = L.CloudCompute("cpu")
14-
worker = YourComponent(cloud_compute=compute)
15-
app = L.LightningApp(worker)
28+
component = PyTorchServer(
29+
input_type=Image, output_type=Number, cloud_compute=L.CloudCompute('gpu')
30+
)
31+
app = L.LightningApp(component)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# app.py
2+
import lightning as L
3+
from lightning.app.components import PyTorchLightningMultiNode
4+
from lightning.pytorch.demos.boring_classes import BoringModel
5+
6+
7+
class LightningTrainerDistributed(L.LightningWork):
8+
@staticmethod
9+
def run():
10+
model = BoringModel()
11+
trainer = L.Trainer(max_epochs=10, strategy="ddp")
12+
trainer.fit(model)
13+
14+
# 8 GPU: (2 nodes of 4 x v100)
15+
component = PyTorchLightningMultiNode(
16+
LightningTrainerDistributed,
17+
num_nodes=2,
18+
cloud_compute=L.CloudCompute("gpu-fast-multi"), # 4 x v100
19+
)
20+
app = L.LightningApp(component)

0 commit comments

Comments
 (0)