2022-11-03 14:55:30 +00:00
####################################################
2022-11-06 10:55:57 +00:00
Level 4: Connect components into a full stack AI app
2022-11-03 14:55:30 +00:00
####################################################
**Audience:** Users who want to build apps with multiple components.
2023-08-17 15:48:45 +00:00
**Prereqs:** You know how to :doc: `build a component <../basic/build_a_lightning_component>` .
2022-11-03 14:55:30 +00:00
----
***** ***** ***** ***** ***** ***
What is a full stack AI app?
***** ***** ***** ***** ***** ***
2022-11-04 12:31:27 +00:00
In the ML world, workflows coordinate multiple pieces of code working together. In Lightning,
2023-08-17 15:48:45 +00:00
when we coordinate 2 or more :doc: `Lightning components <../basic/build_a_lightning_component>` working together,
2022-11-04 12:31:27 +00:00
we instead call it a Lightning App. The difference will become more obvious when we introduce reactive
workflows in the advanced section.
2022-11-03 14:55:30 +00:00
2022-11-04 12:31:27 +00:00
For the time being, we'll go over how to coordinate 2 components together in a traditional workflow setting
and explain how it works.
2022-11-03 14:55:30 +00:00
.. note :: If you've used workflow tools for Python, this page describes conventional DAGs.
2023-08-17 15:48:45 +00:00
In :doc: `level 6 <run_lightning_work_in_parallel>` , we introduce reactive workflows that generalize beyond DAGs
2022-11-03 14:55:30 +00:00
so you can build complex systems without much effort.
----
***** ***** *
The toy app
***** ***** *
In this app, we define two components that run across 2 separate machines. One to train a model on a GPU machine and one to analyze the model
on a separate CPU machine. We save money by stopping the GPU machine when the work is done.
.. lit_tabs ::
:titles: Import Lightning; Define Component 1; Define Component 2; Orchestrator; Connect component 1; Connect component 2; Implement run; Train; Analyze; Define app placeholder
:descriptions: First, import Lightning; This component trains a model on a GPU machine; This component analyzes a model on a CPU machine; Define the LightningFlow that orchestrates components; Component 1 will run on a CPU machine; Component 2 will run on an accelerated GPU machine; Describe the workflow in the run method; Training runs first and completes; Analyze runs after training completes; This allows the app to be runnable
:code_files: ./level_2_scripts/hello_app.py; ./level_2_scripts/hello_app.py; ./level_2_scripts/hello_app.py; ./level_2_scripts/hello_app.py; ./level_2_scripts/hello_app.py; ./level_2_scripts/hello_app.py; ./level_2_scripts/hello_app.py; ./level_2_scripts/hello_app.py; ./level_2_scripts/hello_app.py; ./level_2_scripts/hello_app.py
2022-11-04 12:31:27 +00:00
:highlights: 2; 5-7; 9-11; 13; 16; 17; 19; 20; 21; 23
2022-11-17 09:13:09 +00:00
:enable_run: true
2022-11-03 14:55:30 +00:00
:tab_rows: 4
2022-11-04 12:31:27 +00:00
:height: 460px
2022-11-03 14:55:30 +00:00
|
Now run the app:
.. lit_tabs ::
:titles: Run on Lightning cloud; Your own hardware
:descriptions: Run to see these 2 components execute on separate machines 🤯; Run it locally without code changes 🤯🤯;
2022-11-06 10:55:57 +00:00
:code_files: ./level_2_scripts/code_run_cloud.bash; ./level_2_scripts/code_run_local.bash
2022-11-03 14:55:30 +00:00
:tab_rows: 7
:height: 195px
|
Now you can develop distributed cloud apps on your laptop 🤯🤯🤯🤯!
----
2022-11-06 10:55:57 +00:00
***** ***** ***
Now you know:
***** ***** ***
2022-11-03 14:55:30 +00:00
Without going out of your way, you're now doing the following: (Hint: Click **visualize** to see an animation describing the code).
.. lit_tabs ::
:titles: Orchestration; Distributed cloud computing; Multi-machine communication; Multi-machine communication; Multi-cloud;
2022-11-04 12:31:27 +00:00
:descriptions: Define orchestration in Python with full control-flow; The two pieces of independent Python code ran on separate machines 🤯🤯; The text "CPU machine 1" was sent from the flow machine to the machine running the TrainComponent; The text "GPU machine 2" was sent from the flow machine to the machine running the AnalyzeComponent; The full Lightning app can move across clusters and clouds
2023-07-27 22:16:21 +00:00
:code_files: ./level_2_scripts/hello_app.py; ./level_2_scripts/hello_app.py; ./level_2_scripts/hello_app.py; ./level_2_scripts/hello_app.py;
2022-11-03 14:55:30 +00:00
:tab_rows: 4
2023-07-27 22:16:21 +00:00
:highlights: 19-21; 16-17; 20; 21
2022-11-03 14:55:30 +00:00
:images: <img src="https://pl-bolts-doc-images.s3.us-east-2.amazonaws.com/orchestration.gif" style="max-height: 430px; width: auto"></img> | <img src="https://pl-bolts-doc-images.s3.us-east-2.amazonaws.com/distributed_computing.gif" style="max-height: 430px; width: auto"></img> | <img src="https://pl-bolts-doc-images.s3.us-east-2.amazonaws.com/multi_machine_comms.gif" style="max-height: 430px; width: auto"></img> | <img src="https://pl-bolts-doc-images.s3.us-east-2.amazonaws.com/multi_machine_comms.gif" style="max-height: 430px; width: auto"></img> | <img src="https://pl-bolts-doc-images.s3.us-east-2.amazonaws.com/multi_cloud.gif" style="max-height: 430px; width: auto"></img>
2022-11-06 10:55:57 +00:00
:height: 470px
2022-11-03 14:55:30 +00:00
----
***** ***** ***** ***** *
Maintain full control
***** ***** ***** ***** *
Although we've abstracted the infrastructure, you still have full control when you need it:
.. lit_tabs ::
:titles: Scheduler; Crontab syntax; Auto-scaling; Organized Python; Full terraform control;
:descriptions: Although you can use Python timers, we have a scheduler short-hand; You can also use full cron syntax; Code your own auto-scaling syntax (Lightning plays well with Kubernetes); *Remember* components organize ANY Python code which can even call external non-python scripts such as optimized C++ model servers ;Experts have the option to use terraform to configure Lightning clusters
2023-07-27 22:16:21 +00:00
:code_files: ./level_2_scripts/hello_app_scheduler.py; ./level_2_scripts/hello_app_cron.py; ./level_2_scripts/hello_app_auto_scale.py; ./level_2_scripts/organized_app_python.py;
2022-11-03 14:55:30 +00:00
:tab_rows: 4
2023-07-27 22:16:21 +00:00
:highlights: 24; 24; 21, 24, 27, 28; 9, 16, 17
2022-11-06 10:55:57 +00:00
:height: 700px
2022-11-03 14:55:30 +00:00
----
2022-11-06 10:55:57 +00:00
***** ***** ***** ***** *****
Next: Review how to debug
***** ***** ***** ***** *****
The next levels does a 2 minute review to make sure you know how to debug a Lightning app.
2022-11-04 12:31:27 +00:00
2022-11-06 10:55:57 +00:00
.. raw :: html
2022-11-04 12:31:27 +00:00
2022-11-06 10:55:57 +00:00
<div class="display-card-container">
<div class="row">
2022-11-04 12:31:27 +00:00
2022-11-06 10:55:57 +00:00
.. Add callout items below this line
2022-11-04 12:31:27 +00:00
2022-11-06 10:55:57 +00:00
.. displayitem ::
:header: Level 5: Debug a Lightning App
:description: Learn to debug a lightning app.
:button_link: debug_a_lightning_app.html
:col_css: col-md-12
:height: 170
:tag: 10 minutes
2022-11-03 14:55:30 +00:00
2022-11-06 10:55:57 +00:00
.. raw :: html
2022-11-03 14:55:30 +00:00
2022-11-06 10:55:57 +00:00
</div>
</div>