.. displayitem::
- :header: Build a component
+ :header: Build a Lightning component
:description: Learn the basics of building a Lightning component
:col_css: col-md-4
:button_link: basic.html
@@ -36,8 +36,8 @@ Basics
:tag: basic
.. displayitem::
- :header: Explore community components
- :description: Discover community-built components
+ :header: Explore community Lightning components
+ :description: Discover community-built Lightning components
:col_css: col-md-4
:button_link: https://lightning.ai/components
:height: 150
@@ -84,7 +84,7 @@ Intermediate
:tag: intermediate
.. displayitem::
- :header: Publish a component
+ :header: Publish a Lightning component
:description: Learn the basics of publishing a Lightning component.
:col_css: col-md-4
:button_link: publish_a_component.html
diff --git a/docs/source-app/workflows/build_lightning_component/intermediate.rst b/docs/source-app/workflows/build_lightning_component/intermediate.rst
index a1956b260d..070d3aa0ca 100644
--- a/docs/source-app/workflows/build_lightning_component/intermediate.rst
+++ b/docs/source-app/workflows/build_lightning_component/intermediate.rst
@@ -29,11 +29,11 @@ To *connect* this user interface to the component, define the configure_layout m
.. code:: python
:emphasize-lines: 5, 6
- import lightning_app as la
+ import lightning as L
from lightning_app.frontend.web import StaticWebFrontend
- class LitHTMLComponent(lapp.LightningFlow):
+ class LitHTMLComponent(L.LightningFlow):
def configure_layout(self):
return StaticWebFrontend(serve_dir="path/to/folder/with/index.html/inside")
@@ -43,15 +43,15 @@ Finally, route the component's UI through the root component's **configure_layou
:emphasize-lines: 14
# app.py
- import lightning_app as la
+ import lightning as L
- class LitHTMLComponent(lapp.LightningFlow):
+ class LitHTMLComponent(L.LightningFlow):
def configure_layout(self):
- return lapp.frontend.web.StaticWebFrontend(serve_dir="path/to/folder/with/index.html/inside")
+ return L.frontend.web.StaticWebFrontend(serve_dir="path/to/folder/with/index.html/inside")
- class LitApp(lapp.LightningFlow):
+ class LitApp(L.LightningFlow):
def __init__(self):
super().__init__()
self.lit_html_component = LitHTMLComponent()
@@ -61,7 +61,7 @@ Finally, route the component's UI through the root component's **configure_layou
return tab1
- app = lapp.LightningApp(LitApp())
+ app = L.LightningApp(LitApp())
Run your app and you'll see the UI on the Lightning App view:
diff --git a/docs/source-app/workflows/build_lightning_component/publish_a_component.rst b/docs/source-app/workflows/build_lightning_component/publish_a_component.rst
index f4ed73b2bd..8364afd3d5 100644
--- a/docs/source-app/workflows/build_lightning_component/publish_a_component.rst
+++ b/docs/source-app/workflows/build_lightning_component/publish_a_component.rst
@@ -13,7 +13,7 @@ the default template.
Generate your component template with this command:
-.. code:: bash
+.. code:: python
lightning init component your-component-name
@@ -36,20 +36,18 @@ Now import your component and use it in an app:
# app.py
from your_component import TemplateComponent
- import lightning_app as la
+ import lightning as L
-
- class LitApp(lapp.LightningFlow):
+ class LitApp(L.LightningFlow):
def __init__(self) -> None:
super().__init__()
self.your_component = TemplateComponent()
def run(self):
- print("this is a simple Lightning app to verify your component is working as expected")
+ print('this is a simple Lightning app to verify your component is working as expected')
self.your_component.run()
-
- app = lapp.LightningApp(LitApp())
+ app = L.LightningApp(LitApp())
and run the app:
diff --git a/docs/source-app/workflows/debug_locally.rst b/docs/source-app/workflows/debug_locally.rst
index 77ea163b44..cd5a5a80fd 100644
--- a/docs/source-app/workflows/debug_locally.rst
+++ b/docs/source-app/workflows/debug_locally.rst
@@ -1,3 +1,5 @@
+:orphan:
+
#####################################
Debug a Distributed Cloud App Locally
#####################################
diff --git a/docs/source-app/workflows/enable_fault_tolerance.rst b/docs/source-app/workflows/enable_fault_tolerance.rst
index c7af476d34..b1630d4d39 100644
--- a/docs/source-app/workflows/enable_fault_tolerance.rst
+++ b/docs/source-app/workflows/enable_fault_tolerance.rst
@@ -1,3 +1,5 @@
+:orphan:
+
######################
Enable Fault Tolerance
######################
diff --git a/docs/source-app/workflows/extend_app.rst b/docs/source-app/workflows/extend_app.rst
index d0ac9feab3..2e17af481b 100644
--- a/docs/source-app/workflows/extend_app.rst
+++ b/docs/source-app/workflows/extend_app.rst
@@ -1,7 +1,7 @@
######################
Extend an Existing App
######################
-You can extend a Lightning app by using community components or building your own.
+You can extend a Lightning App by using community components or building your own.
----
@@ -13,8 +13,8 @@ You can extend a Lightning app by using community components or building your ow
.. Add callout items below this line
.. displayitem::
- :header: Add more components
- :description: Extend an app by adding a prebuilt component.
+ :header: Add more Components
+ :description: Extend an App by adding a prebuilt component.
:col_css: col-md-4
:button_link: add_components/index.html
:height: 150
@@ -22,23 +22,23 @@ You can extend a Lightning app by using community components or building your ow
.. displayitem::
:header: Add a web user interface (UI)
- :description: Extend an app by adding a web user interface (UI)
+ :description: Extend an App by adding a web user interface (UI)
:col_css: col-md-4
:button_link: add_web_ui/index.html
:height: 150
:tag: basic
.. displayitem::
- :header: Add a url link
- :description: Extend an app by adding a web url link
+ :header: Add a URL link
+ :description: Extend an App by adding a web URL link
:col_css: col-md-4
:button_link: add_web_link.html
:height: 150
:tag: basic
.. displayitem::
- :header: Build a component
- :description: Extend an app by building a component
+ :header: Build a Component
+ :description: Extend an App by building a Component
:col_css: col-md-4
:button_link: build_lightning_component/index.html
:height: 150
@@ -46,7 +46,7 @@ You can extend a Lightning app by using community components or building your ow
.. displayitem::
:header: Add a server
- :description: Extend an app by adding a server to a component.
+ :description: Extend an App by adding a server to a Component.
:col_css: col-md-4
:button_link: add_server/index.html
:height: 150
diff --git a/docs/source-app/workflows/index.rst b/docs/source-app/workflows/index.rst
new file mode 100644
index 0000000000..7f0642f661
--- /dev/null
+++ b/docs/source-app/workflows/index.rst
@@ -0,0 +1,114 @@
+:orphan:
+
+################
+Common Workflows
+################
+
+.. raw:: html
+
+
+
+
+.. displayitem::
+ :header: Add a web user interface
+ :description: Learn how to add React, StreamLit, Dash to your App.
+ :col_css: col-md-4
+ :button_link: add_web_ui/index.html
+ :height: 180
+
+.. displayitem::
+ :header: Add a web link
+ :description: Learn how to embed external websites
+ :col_css: col-md-4
+ :button_link: add_web_link.html
+ :height: 180
+
+.. displayitem::
+ :header: Arrange App tabs
+ :description: Learn how to organize your UI
+ :col_css: col-md-4
+ :button_link: arrange_tabs/index.html
+ :height: 180
+
+.. displayitem::
+ :header: Build a Lightning App
+ :description: Simple App to get started
+ :col_css: col-md-4
+ :button_link: build_lightning_app/index.html
+ :height: 180
+
+.. displayitem::
+ :header: Build a Lightning Component
+ :description: Understand how to separated the glue from the actual work
+ :col_css: col-md-4
+ :button_link: build_lightning_component/index.html
+ :height: 180
+
+.. displayitem::
+ :header: Cache Work run calls
+ :description: Understand how to trigger a work run method
+ :col_css: col-md-4
+ :button_link: run_work_once.html
+ :height: 180
+
+.. displayitem::
+ :header: Customize your cloud compute
+ :description: Select machines to run on
+ :col_css: col-md-4
+ :button_link: ../core_api/lightning_work/compute.html
+ :height: 180
+
+.. displayitem::
+ :header: Extend an existing App
+ :description: Learn where to go next with an App
+ :col_css: col-md-4
+ :button_link: extend_app.html
+ :height: 180
+
+.. displayitem::
+ :header: Publish a Lightning Component
+ :description: Share your components with others
+ :col_css: col-md-4
+ :button_link: build_lightning_component/publish_a_component.html
+ :height: 180
+
+.. displayitem::
+ :header: Run a server within a Lightning App
+ :description: Lightning Work can be infinite jobs
+ :col_css: col-md-4
+ :button_link: add_server/index.html
+ :height: 180
+
+.. displayitem::
+ :header: Run an App on the cloud
+ :description: Learn how to get things done in the cloud with ease
+ :col_css: col-md-4
+ :button_link: run_app_on_cloud/index.html
+ :height: 180
+
+.. displayitem::
+ :header: Run Works in parallel
+ :description: Learn how to make your Work non blocking
+ :col_css: col-md-4
+ :button_link: run_work_in_parallel.html
+ :height: 180
+
+.. displayitem::
+ :header: Share an App
+ :description: Learn how to share your work with others
+ :col_css: col-md-4
+ :button_link: share_app.html
+ :height: 180
+
+.. displayitem::
+ :header: Share files between components
+ :description: Learn how Lightning Storage emulates a single filesystem in a distributed setting
+ :col_css: col-md-4
+ :button_link: share_files_between_components.html
+ :height: 180
+
+
+.. raw:: html
+
+
+
diff --git a/docs/source-app/workflows/run_app_on_cloud/cloud_files.rst b/docs/source-app/workflows/run_app_on_cloud/cloud_files.rst
new file mode 100644
index 0000000000..3130cd0f33
--- /dev/null
+++ b/docs/source-app/workflows/run_app_on_cloud/cloud_files.rst
@@ -0,0 +1,58 @@
+.. _ignore:
+
+##################################
+Configure Your Lightning Cloud App
+##################################
+
+**Audience:** Users who want to control Lightning App files on the cloud.
+
+----
+
+**************************************
+Ignore file uploads to Lightning cloud
+**************************************
+Running Lightning Apps on the cloud will upload the source code of your app to the cloud. You can use ``.lightningignore`` file(s) to ignore files or directories while uploading. The `.lightningignore` file follows the same format as a `.gitignore`
+file.
+
+For example, the source code directory below with the ``.lightningignore`` file will ignore the file named
+``model.pt`` and directory named ``data_dir``.
+
+.. code:: bash
+
+ .
+ ├── README.md
+ ├── app.py
+ ├── data_dir
+ │ ├── image1.png
+ │ ├── image2.png
+ │ └── ...
+ ├── .lightningignore
+ ├── requirements.txt
+ └── model.pt
+
+
+.. code:: bash
+
+ ~/project/home ❯ cat .lightningignore
+ model.pt
+ data_dir
+
+A sample ``.lightningignore`` file can be found `here
`_.
+
+
+----
+
+*******************
+Structure app files
+*******************
+
+We recommend your app contain the following files:
+
+.. code:: bash
+
+ .
+ ├── .lightning (auto-generated- conatins Lightning configuration)
+ ├── .lightningignore (contains files not to upload to the cloud)
+ ├── app.py
+ ├── README.md (optional- a markdown description of your app)
+ └── requirements.txt (optional- conatins all your app dependencies)
diff --git a/docs/source-app/workflows/run_app_on_cloud/index.rst b/docs/source-app/workflows/run_app_on_cloud/index.rst
new file mode 100644
index 0000000000..55bc3b6807
--- /dev/null
+++ b/docs/source-app/workflows/run_app_on_cloud/index.rst
@@ -0,0 +1,5 @@
+#####################
+Run apps on the cloud
+#####################
+
+.. include:: index_content.rst
diff --git a/docs/source-app/workflows/run_app_on_cloud/index_content.rst b/docs/source-app/workflows/run_app_on_cloud/index_content.rst
new file mode 100644
index 0000000000..b0f67570d7
--- /dev/null
+++ b/docs/source-app/workflows/run_app_on_cloud/index_content.rst
@@ -0,0 +1,115 @@
+.. _run_app_in_cloud:
+
+.. toctree::
+ :maxdepth: 1
+ :hidden:
+
+ cloud_files
+ lightning_cloud
+ on_prem
+ on_your_own_machine
+
+**Audience:** Users who want to share or scale Lightning Apps.
+
+----
+
+*****************************
+Run on Lightning Public Cloud
+*****************************
+
+You can run Lightning Apps for free on the Public Lightning cloud with a single flag!
+
+.. raw:: html
+
+
+
+
+.. Add callout items below this line
+
+.. displayitem::
+ :header: Run on Lightning Cloud
+ :description: Learn how to run on the Lightning public cloud
+ :col_css: col-md-4
+ :button_link: lightning_cloud.html
+ :height: 150
+ :tag: basic
+
+.. displayitem::
+ :header: Choose Hardware
+ :description: Configure you app cloud resources
+ :col_css: col-md-4
+ :button_link: ../../core_api/lightning_work/compute.html
+ :height: 150
+ :tag: Basic
+
+.. displayitem::
+ :header: Set Environment Variables
+ :description: Manage your environment variables in the cloud
+ :col_css: col-md-4
+ :button_link: ../../glossary/environment_variables.html
+ :height: 150
+ :tag: Basic
+
+.. displayitem::
+ :header: Configure Your Lightning Cloud App
+ :description: Customize your cloud apps files
+ :col_css: col-md-4
+ :button_link: cloud_files.html
+ :height: 150
+ :tag: Intermediate
+
+.. displayitem::
+ :header: Manage App Dependancies
+ :description: Configure your python requirements or use a custom docker image
+ :col_css: col-md-4
+ :button_link: ../../glossary/build_config/build_config.html
+ :height: 150
+ :tag: Intermediate
+
+.. displayitem::
+ :header: Share Files Between Works
+ :description: Learn more about data transfering
+ :col_css: col-md-4
+ :button_link: ../../glossary/storage/storage.html
+ :height: 150
+ :tag: Intermediate
+
+.. raw:: html
+
+
+
+
+----
+
+************
+Other Clouds
+************
+
+.. raw:: html
+
+
+
+
+.. Add callout items below this line
+
+.. displayitem::
+ :header: Run On Your Own Machine
+ :description: Run Lightning Apps on any machine
+ :col_css: col-md-4
+ :button_link: on_your_own_machine.html
+ :height: 150
+ :tag: basic
+
+.. displayitem::
+ :header: Run On Your Private Cloud
+ :description: Run Lightning Apps on your own cloud
+ :col_css: col-md-4
+ :button_link: on_prem.html
+ :height: 150
+ :tag: basic
+
+
+.. raw:: html
+
+
+
diff --git a/docs/source-app/workflows/run_app_on_cloud/lightning_cloud.rst b/docs/source-app/workflows/run_app_on_cloud/lightning_cloud.rst
new file mode 100644
index 0000000000..aaa9d7bb08
--- /dev/null
+++ b/docs/source-app/workflows/run_app_on_cloud/lightning_cloud.rst
@@ -0,0 +1,67 @@
+#######################
+Run an App on the Cloud
+#######################
+
+**Audience:** Users who want to share their apps or run on specialized hardware (like GPUs).
+
+----
+
+*********************************
+Run on the public Lightning cloud
+*********************************
+To run any app on the public lightning cloud use the ``--cloud`` argument:
+
+.. code:: bash
+
+ lightning run app app.py --cloud
+
+
+.. note::
+ By default, running your apps on the public Lightning cloud is free of charge using default CPUs, and any app uploaded to the Lightning cloud will be shared with the community (source code and app view will be public). If you would like to make your apps private please `contact us `_.
+
+If your app contains ``LightningWork`` components that require more compute resources, such as larger CPUs or **GPUs**, you'll need to add credits to your Lightning AI account.
+
+
+----
+
+**************************
+Add dependencies to my app
+**************************
+
+
+Add all dependencies required to run your app to a `requirements.txt` file in your app's directory. Read :ref:`build_config` for more details.
+
+
+
+----
+
+
+********
+Name app
+********
+
+Simply use the ``--name`` flag when running your app, for example:
+
+.. code:: bash
+
+ lightning run app app.py --cloud --name my-awesome-app
+
+Alternatively, you can change the name of the app in the ``.lightning`` file:
+
+.. code:: bash
+
+ ~/project/home ❯ cat .lightning
+ name: my-awesome-app
+
+The ``.lightning`` file is a general configuration file.
+To learn more about optional configuration file parameters, see :class:`~lightning.utilities.packaging.app_config.AppConfig`.
+
+------
+
+********************
+Choose Cloud Compute
+********************
+
+You can configure the hardware your app is running on by setting a :class:`~lightning.utilities.packaging.cloud_compute.CloudCompute` object onto the ``cloud_compute`` property of your work's.
+
+Learn more with the :ref:`cloud_compute` guide
diff --git a/docs/source-app/workflows/run_app_on_cloud/on_prem.rst b/docs/source-app/workflows/run_app_on_cloud/on_prem.rst
new file mode 100644
index 0000000000..be0a954f29
--- /dev/null
+++ b/docs/source-app/workflows/run_app_on_cloud/on_prem.rst
@@ -0,0 +1,6 @@
+###########################
+Run an App on Private Cloud
+###########################
+
+
+To run Lightning apps on a private or on-prem cluster, `contact us `_.
diff --git a/docs/source-app/workflows/run_app_on_cloud/on_your_own_machine.rst b/docs/source-app/workflows/run_app_on_cloud/on_your_own_machine.rst
new file mode 100644
index 0000000000..795205f552
--- /dev/null
+++ b/docs/source-app/workflows/run_app_on_cloud/on_your_own_machine.rst
@@ -0,0 +1,23 @@
+#######################
+Run on your own machine
+#######################
+
+**Audience:** Users who want to run Lightning App on a remote machine.
+
+----
+
+***********
+Run via ssh
+***********
+To run a Lightning App on any machine, simply ssh to the machine and run the app directly
+
+.. code:: bash
+
+ # log into your cloud machine
+ ssh your_name@your_cloud_machine
+
+ # get your code on the machine and install deps
+ ...
+
+ # start the app
+ lightning run app app.py
diff --git a/docs/source-app/workflows/run_components_on_different_hardware.rst b/docs/source-app/workflows/run_components_on_different_hardware.rst
index ef3aac100d..9685c3461e 100644
--- a/docs/source-app/workflows/run_components_on_different_hardware.rst
+++ b/docs/source-app/workflows/run_components_on_different_hardware.rst
@@ -1,3 +1,5 @@
+:orphan:
+
####################################
Run components on different hardware
####################################
diff --git a/docs/source-app/workflows/run_work_in_parallel.rst b/docs/source-app/workflows/run_work_in_parallel.rst
index 542b36b3b3..58089b6ed7 100644
--- a/docs/source-app/workflows/run_work_in_parallel.rst
+++ b/docs/source-app/workflows/run_work_in_parallel.rst
@@ -1,56 +1,11 @@
-####################
-Run work in parallel
-####################
+##############################
+Run LightningWorks in parallel
+##############################
-When there is a long-running workload such as a model training, or a deployment server, it may be desirable to run that work in parallel
-while the rest of the app continues to execute.
+**Audience:** Users who want to run multiple LightningWorks at once.
+
+**Prereqs:** Level 8+
----
-****************************
-Why do I need parallel work?
-****************************
-The default behavior of the ``LightningWork`` is to wait for the ``run`` method to complete:
-
-.. code:: python
-
- import lightning_app as la
-
-
- class Root(lapp.LightningFlow):
- def __init__(self):
- self.work_component_a = lapp.demo.InfinteWorkComponent()
-
- def run(self):
- self.work_component_a.run()
- print("this will never print")
-
-Since this Work component we created loops forever, the print statement will never execute. In practice
-``LightningWork`` workloads are finite and don't run forever.
-
-When a ``LightningWork`` performs a heavy operation (longer than 1 second), or requires its own hardware,
-work that is *not* done in parallel will slow down your app.
-
-----
-
-********************
-Enable parallel work
-********************
-To run work in parallel while the rest of the app executes without delays, enable ``parallel=True``:
-
-.. code:: python
- :emphasize-lines: 5
-
- import lightning_app as la
-
-
- class Root(lapp.LightningFlow):
- def __init__(self):
- self.work_component_a = lapp.demo.InfinteWorkComponent(parallel=True)
-
- def run(self):
- self.work_component_a.run()
- print("repeats while the infinite work runs ONCE (and forever) in parallel")
-
-Any work that will take more than **1 second** should be run in parallel
-unless the rest of your app depends on the output of this work (for example, downloading a dataset).
+.. include:: run_work_in_parallel_content.rst
diff --git a/docs/source-app/workflows/run_work_in_parallel_content.rst b/docs/source-app/workflows/run_work_in_parallel_content.rst
new file mode 100644
index 0000000000..ecb87c5cea
--- /dev/null
+++ b/docs/source-app/workflows/run_work_in_parallel_content.rst
@@ -0,0 +1,53 @@
+
+
+****************************************************
+What running LightningWorks in parallel does for you
+****************************************************
+
+When there is a long-running workload such as a model training, or a deployment server, you might want to run that LightningWork in parallel
+while the rest of the Lightning App continues to execute.
+
+The default behavior of the ``LightningWork`` is to wait for the ``run`` method to complete:
+
+.. code:: python
+
+ import lightning as L
+
+
+ class Root(L.LightningFlow):
+ def __init__(self):
+ self.work_component_a = L.demo.InfinteWorkComponent()
+
+ def run(self):
+ self.work_component_a.run()
+ print("this will never print")
+
+Since this LightningWork component we created loops forever, the print statement will never execute. In practice
+``LightningWork`` workloads are finite and don't run forever.
+
+When a ``LightningWork`` performs a heavy operation (longer than 1 second), or requires its own hardware,
+LightningWork that is *not* done in parallel will slow down your app.
+
+----
+
+******************************
+Enable parallel LightningWorks
+******************************
+To run LightningWorks in parallel, while the rest of the app executes without delays, enable ``parallel=True``:
+
+.. code:: python
+ :emphasize-lines: 5
+
+ import lightning as L
+
+
+ class Root(L.LightningFlow):
+ def __init__(self):
+ self.work_component_a = L.demo.InfinteWorkComponent(parallel=True)
+
+ def run(self):
+ self.work_component_a.run()
+ print("repeats while the infinite work runs ONCE (and forever) in parallel")
+
+Any LightningWorks that will take more than **1 second** should be run in parallel
+unless the rest of your Lightning App depends on the output of this work (for example, downloading a dataset).
diff --git a/docs/source-app/workflows/run_work_once.rst b/docs/source-app/workflows/run_work_once.rst
index b98df496bc..240cde3d08 100644
--- a/docs/source-app/workflows/run_work_once.rst
+++ b/docs/source-app/workflows/run_work_once.rst
@@ -1,126 +1,13 @@
-.. _cache_calls:
-
-#################
-Caching Work Runs
-#################
+##########################
+Cache LightningWork Runs
+##########################
**Audience:** Users who want to know how ``LightningWork`` works.
-**Level:** Basic
+**Level:** Advanced
-**Prerequisite**: Read the :ref:`event_loop` guide.
+**Prereqs**: Level 16+ and read the `Event Loop guide <../glossary/event_loop.html>`_.
----
-**********************************************************
-What does it mean to cache the calls of Work's run method?
-**********************************************************
-
-By default, the run method in a LightningWork "remembers" (caches) the input arguments it is getting called with and does not execute again if called with the same arguments again.
-In other words, the run method only executes when the input arguments have never been seen before.
-
-This behavior can be toggled on or off:
-
-.. code-block:: python
-
- # Run only when the input arguments change (default)
- work = MyWork(cache_calls=True)
-
- # Run everytime regardless of whether input arguments change or not
- work = MyWork(cache_calls=False)
-
-
-To better understand this, imagine you want every day to sequentially download and process some data and then train a model on those data.
-As explained in the pre-requisite, the Lightning App runs within an infinite while loop, so the pseudo-code of your application might looks like this:
-
-.. code-block:: python
-
- from datetime import datetime
-
- # Lightning code
- while True: # This is the Lightning Event Loop
-
- # Your code
- today = datetime.now().strftime("%D") # '05/25/22'
- data_processor.run(today)
- train_model.run(data_processor.data)
-
-In this scenario, you want your components to run ``once`` a day, no more! But your code is running within an infinite loop, how can this even work?
-This is where the work's internal caching mechanism comes in. By default, Lightning caches a hash of the input provided to its run method and won't re-execute the method if the same input is provided again.
-In the example above, the **data_processor** component run method receives the string **"05/25/22"**. It runs one time and any further execution during the day is skipped until tomorrow is reached and the work run method receives **06/25/22**. This logic applies everyday.
-This caching mechanism is inspired from how `React.js Components and Props `_ renders website. Only changes to the inputs re-trigger execution.
-
-*******************************
-How can I verify this behavior?
-*******************************
-
-Here's an example of this behavior with LightningWork:
-
-.. literalinclude:: ../code_samples/basics/0.py
- :language: python
- :emphasize-lines: 10, 19
-
-And you should see the following by running the code above:
-
-.. code-block:: console
-
- $ python example.py
- INFO: Your app has started. View it in your browser: http://127.0.0.1:7501/view
- # After you have clicked `run` on the UI.
- I received the following props: args: () kwargs: {'value': 1}
- I received the following props: args: () kwargs: {'value': 10}
-
-As you can see, the intermediate run didn't execute, as we would expected when ``cache_calls=True``.
-
-************************************************
-What are the implications of turnin caching off?
-************************************************
-
-By setting ``cache_calls=False``, Lightning won't cache the return value and re-execute the run method on every call.
-
-.. literalinclude:: ../code_samples/basics/1.py
- :diff: ../code_samples/basics/0.py
-
-.. code-block:: console
-
- $ python example.py
- INFO: Your app has started. View it in your browser: http://127.0.0.1:7501/view
- # After you have clicked `run` on the UI.
- I received the following props: args: () kwargs: {'value': 1}
- I received the following props: args: () kwargs: {'value': 1}
- I received the following props: args: () kwargs: {'value': 1}
- I received the following props: args: () kwargs: {'value': 1}
- I received the following props: args: () kwargs: {'value': 1}
- I received the following props: args: () kwargs: {'value': 10}
-
-
-Be aware than when setting both ``cache_calls=False`` and ``parallel=False`` to a work, the code after the ``self.work.run()`` is unreachable
-as the work continuously execute in a blocking way.
-
-.. code-block:: python
-
- from lightning_app import LightningApp, LightningFlow, LightningWork
-
-
- class Flow(LightningFlow):
- def __init__(self):
- super().__init__()
-
- self.work = Work(cache_calls=False, parallel=False)
-
- def run(self):
- print("HERE BEFORE")
- self.work.run()
- print("HERE AFTER")
-
-
- app = LightningApp(Flow())
-
-.. code-block:: console
-
- $ lightning run app app.py
- INFO: Your app has started. View it in your browser: http://127.0.0.1:7501/view
- print("HERE BEFORE")
- print("HERE BEFORE")
- print("HERE BEFORE")
- ...
+.. include:: run_work_once_content.rst
diff --git a/docs/source-app/workflows/run_work_once_content.rst b/docs/source-app/workflows/run_work_once_content.rst
new file mode 100644
index 0000000000..dbef378135
--- /dev/null
+++ b/docs/source-app/workflows/run_work_once_content.rst
@@ -0,0 +1,151 @@
+
+********************************************************
+What caching the calls of Work's run method does for you
+********************************************************
+
+By default, the run method in a LightningWork (Work) "remembers" (caches) the input arguments it is getting called with and does not execute again if called with the same arguments again.
+In other words, the run method only executes when the input arguments have never been seen before.
+
+You can turn caching on or off:
+
+.. code-block:: python
+
+ # Run only when the input arguments change (default)
+ work = MyWork(cache_calls=True)
+
+ # Run everytime regardless of whether input arguments change or not
+ work = MyWork(cache_calls=False)
+
+To better understand this, imagine that every day you want to sequentially download and process some data and then train a model on that data.
+As explained in the `Event Loop guide <../glossary/event_loop.html>`_, the Lightning App runs within an infinite while loop, so the pseudo-code of your application might looks like this:
+
+.. code-block:: python
+
+ from datetime import datetime
+
+ # Lightning code
+ while True: # This is the Lightning Event Loop
+
+ # Your code
+ today = datetime.now().strftime("%D") # '05/25/22'
+ data_processor.run(today)
+ train_model.run(data_processor.data)
+
+In this scenario, you want your components to run ``once`` a day, and no more than that! But your code is running within an infinite loop, how can this even work?
+This is where the Work's internal caching mechanism comes in. By default, Lightning caches a hash of the input provided to its run method and won't re-execute the method if the same input is provided again.
+In the example above, the **data_processor** component run method receives the string **"05/25/22"**. It runs one time and any further execution during the day is skipped until tomorrow is reached and the work run method receives **06/25/22**. This logic applies everyday.
+This caching mechanism is inspired from how `React.js Components and Props `_ renders websites. Only changes to the inputs re-trigger execution.
+
+***************
+Caching Example
+***************
+
+Here's an example of this behavior with LightningWork:
+
+.. code:: python
+ :emphasize-lines: 11, 17
+
+ import lightning as L
+
+
+ class ExampleWork(L.LightningWork):
+ def run(self, *args, **kwargs):
+ print(f"I received the following props: args: {args} kwargs: {kwargs}")
+
+
+ work = ExampleWork()
+ work.run(value=1)
+
+ # Providing the same value. This won't run as already cached.
+ work.run(value=1)
+ work.run(value=1)
+ work.run(value=1)
+ work.run(value=1)
+
+ # Changing the provided value. This isn't cached and will run again.
+ work.run(value=10)
+
+And you should see the following by running the code above:
+
+.. code-block:: console
+
+ $ python example.py
+ INFO: Your app has started. View it in your browser: http://127.0.0.1:7501/view
+ # After you have clicked `run` on the UI.
+ I received the following props: args: () kwargs: {'value': 1}
+ I received the following props: args: () kwargs: {'value': 10}
+
+As you can see, the intermediate run didn't execute, as we would expected when ``cache_calls=True``.
+
+***********************************
+Implications of turning caching off
+***********************************
+
+By setting ``cache_calls=False``, Lightning won't cache the return value and re-execute the run method on every call.
+
+.. code:: python
+ :emphasize-lines: 7
+
+ from lightning_app import LightningWork
+
+
+ class ExampleWork(LightningWork):
+ def run(self, *args, **kwargs):
+ print(f"I received the following props: args: {args} kwargs: {kwargs}")
+
+
+ work = ExampleWork(cache_calls=False)
+ work.run(value=1)
+
+ # Providing the same value. This won't run as already cached.
+ work.run(value=1)
+ work.run(value=1)
+ work.run(value=1)
+ work.run(value=1)
+
+ # Changing the provided value. This isn't cached and will run again.
+ work.run(value=10)
+
+.. code-block:: console
+
+ $ python example.py
+ INFO: Your app has started. View it in your browser: http://127.0.0.1:7501/view
+ # After you have clicked `run` on the UI.
+ I received the following props: args: () kwargs: {'value': 1}
+ I received the following props: args: () kwargs: {'value': 1}
+ I received the following props: args: () kwargs: {'value': 1}
+ I received the following props: args: () kwargs: {'value': 1}
+ I received the following props: args: () kwargs: {'value': 1}
+ I received the following props: args: () kwargs: {'value': 10}
+
+Be aware than when setting both ``cache_calls=False`` and ``parallel=False`` to a work, the code after the ``self.work.run()`` is unreachable
+as the work continuously execute in a blocking way.
+
+.. code-block:: python
+ :emphasize-lines: 9-10
+
+ from lightning_app import LightningApp, LightningFlow, LightningWork
+
+
+ class Flow(LightningFlow):
+ def __init__(self):
+ super().__init__()
+
+ self.work = Work(cache_calls=False, parallel=False)
+
+ def run(self):
+ print("HERE BEFORE")
+ self.work.run()
+ print("HERE AFTER")
+
+
+ app = LightningApp(Flow())
+
+.. code-block:: console
+
+ $ lightning run app app.py
+ INFO: Your app has started. View it in your browser: http://127.0.0.1:7501/view
+ print("HERE BEFORE")
+ print("HERE BEFORE")
+ print("HERE BEFORE")
+ ...
diff --git a/docs/source-app/workflows/schedule_apps.rst b/docs/source-app/workflows/schedule_apps.rst
index e64c64872e..7b596cd08b 100644
--- a/docs/source-app/workflows/schedule_apps.rst
+++ b/docs/source-app/workflows/schedule_apps.rst
@@ -1,3 +1,5 @@
+:orphan:
+
#################
Schedule App Runs
#################
diff --git a/docs/source-app/workflows/share_app.rst b/docs/source-app/workflows/share_app.rst
index 7dd6be7c37..87045bde8d 100644
--- a/docs/source-app/workflows/share_app.rst
+++ b/docs/source-app/workflows/share_app.rst
@@ -30,4 +30,4 @@ Run local:
lightning run app app.py
-then use one of the many guides to `expose a tunnel `.
+And then, use one of the many guides to `expose a tunnel `_.
diff --git a/docs/source-app/workflows/share_files_between_components.rst b/docs/source-app/workflows/share_files_between_components.rst
index 7292236a18..15108515b3 100644
--- a/docs/source-app/workflows/share_files_between_components.rst
+++ b/docs/source-app/workflows/share_files_between_components.rst
@@ -62,7 +62,7 @@ To use a file, pass the reference to the file:
******************************
Use a directory - coming soon
- ***************
+ ******************************
TODO
----
@@ -73,57 +73,32 @@ Example: Share a model checkpoint
A common workflow in ML is to use a checkpoint created by another component.
First, define a component that saves a checkpoint:
-.. code:: python
-
- import lightning_app as lalit
- from lightning_app.storage.path import Path
- import torch
- import os
-
-
- class ModelTraining(lit.LightningWork):
- def __init__(self, *args, **kwargs):
- super().__init__(*args, **kwargs)
- self.model_checkpoints_path = Path("/checkpoints")
-
- def run(self):
- # make fake checkpoints
- checkpoint_1 = torch.tensor([0, 1, 2, 3, 4])
- checkpoint_2 = torch.tensor([0, 1, 2, 3, 4])
- torch.save(checkpoint_1, self.model_checkpoints_path + "checkpoint_1.ckpt")
- torch.save(checkpoint_2, self.model_checkpoints_path + "checkpoint_2.ckpt")
-
+.. literalinclude:: ./share_files_between_components/app.py
+ :lines: -19
Next, define a component that needs the checkpoints:
-.. code:: python
-
- class ModelDeploy(lit.LightningWork):
- def __init__(self, ckpt_path, *args, **kwargs):
- super().__init__()
- self.ckpt_path = ckpt_path
-
- def run(self):
- ckpts = os.list_dir(self.ckpt_path)
- checkpoint_1 = torch.load(ckpts[0])
- checkpoint_2 = torch.load(ckpts[1])
+.. literalinclude:: ./share_files_between_components/app.py
+ :lines: 20-31
Link both components via a parent component:
-.. code:: python
-
- class Root(lit.LightningFlow):
- def __init__(self):
- super().__init__()
- self.train = ModelTraining()
- self.deploy = ModelDeploy(ckpt_path=self.train.model_checkpoints_path)
-
- def run(self):
- self.train.run()
- self.deploy.run()
+.. literalinclude:: ./share_files_between_components/app.py
+ :lines: 32-
- app = lit.LightningApp(Root())
+Run the app above with the following command:
+
+.. code-block:: bash
+
+ lightning run app docs/source-app/workflows/share_files_between_components/app.py
+
+.. code-block:: console
+
+ Your Lightning App is starting. This won't take long.
+ INFO: Your app has started. View it in your browser: http://127.0.0.1:7501/view
+ Loaded checkpoint_1: tensor([0, 1, 2, 3, 4])
+ Loaded checkpoint_2: tensor([0, 1, 2, 3, 4])
For example, here we save a file on one component and use it in another component:
@@ -136,7 +111,7 @@ For example, here we save a file on one component and use it in another componen
class ComponentA(LightningWork):
def __init__(self):
super().__init__()
- self.boring_path = Path("boring_file.txt")
+ self.boring_path = None
def run(self):
# This should be used as a REFERENCE to the file.
diff --git a/docs/source-app/workflows/share_files_between_components/app.py b/docs/source-app/workflows/share_files_between_components/app.py
new file mode 100644
index 0000000000..c087fc8117
--- /dev/null
+++ b/docs/source-app/workflows/share_files_between_components/app.py
@@ -0,0 +1,48 @@
+import os
+
+import torch
+
+import lightning as L
+from lightning.app.storage.path import Path
+
+
+class ModelTraining(L.LightningWork):
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+ self.checkpoints_path = Path("./checkpoints")
+
+ def run(self):
+ # make fake checkpoints
+ checkpoint_1 = torch.tensor([0, 1, 2, 3, 4])
+ checkpoint_2 = torch.tensor([0, 1, 2, 3, 4])
+ os.makedirs(self.checkpoints_path, exist_ok=True)
+ checkpoint_path = str(self.checkpoints_path / "checkpoint_{}.ckpt")
+ torch.save(checkpoint_1, str(checkpoint_path).format("1"))
+ torch.save(checkpoint_2, str(checkpoint_path).format("2"))
+
+
+class ModelDeploy(L.LightningWork):
+ def __init__(self, ckpt_path, *args, **kwargs):
+ super().__init__()
+ self.ckpt_path = ckpt_path
+
+ def run(self):
+ ckpts = os.listdir(self.ckpt_path)
+ checkpoint_1 = torch.load(os.path.join(self.ckpt_path, ckpts[0]))
+ checkpoint_2 = torch.load(os.path.join(self.ckpt_path, ckpts[1]))
+ print(f"Loaded checkpoint_1: {checkpoint_1}")
+ print(f"Loaded checkpoint_2: {checkpoint_2}")
+
+
+class LitApp(L.LightningFlow):
+ def __init__(self):
+ super().__init__()
+ self.train = ModelTraining()
+ self.deploy = ModelDeploy(ckpt_path=self.train.checkpoints_path)
+
+ def run(self):
+ self.train.run()
+ self.deploy.run()
+
+
+app = L.LightningApp(LitApp())
diff --git a/docs/source-app/workflows/test_an_app.rst b/docs/source-app/workflows/test_an_app.rst
index d8e48e2b58..c51ae3aa8f 100644
--- a/docs/source-app/workflows/test_an_app.rst
+++ b/docs/source-app/workflows/test_an_app.rst
@@ -1,3 +1,5 @@
+:orphan:
+
###########
Test an App
###########
diff --git a/docs/source-pytorch/Makefile b/docs/source-pytorch/Makefile
new file mode 100644
index 0000000000..68be4c930e
--- /dev/null
+++ b/docs/source-pytorch/Makefile
@@ -0,0 +1,19 @@
+# Minimal makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line.
+SPHINXOPTS =
+SPHINXBUILD = sphinx-build
+SOURCEDIR = .
+BUILDDIR = ../build
+
+# Put it first so that "make" without argument is like "make help".
+help:
+ @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
+
+.PHONY: help Makefile
+
+# Catch-all target: route all unknown targets to Sphinx using the new
+# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
+%: Makefile
+ @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
diff --git a/docs/source-pytorch/conf.py b/docs/source-pytorch/conf.py
index 6ebb32ce87..e75c2ed863 100644
--- a/docs/source-pytorch/conf.py
+++ b/docs/source-pytorch/conf.py
@@ -188,7 +188,7 @@ html_theme_path = [pt_lightning_sphinx_theme.get_html_theme_path()]
html_theme_options = {
"pytorch_project": "https://pytorchlightning.ai",
- "canonical_url": pytorch_lightning.__docs_url__,
+ "canonical_url": pytorch_lightning.__about__.__docs_url__,
"collapse_navigation": False,
"display_version": True,
"logo_only": False,
diff --git a/docs/source-pytorch/make.bat b/docs/source-pytorch/make.bat
new file mode 100644
index 0000000000..9b565142ae
--- /dev/null
+++ b/docs/source-pytorch/make.bat
@@ -0,0 +1,35 @@
+@ECHO OFF
+
+pushd %~dp0
+
+REM Command file for Sphinx documentation
+
+if "%SPHINXBUILD%" == "" (
+ set SPHINXBUILD=sphinx-build
+)
+set SOURCEDIR=.
+set BUILDDIR=../build
+
+if "%1" == "" goto help
+
+%SPHINXBUILD% >NUL 2>NUL
+if errorlevel 9009 (
+ echo.
+ echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
+ echo.installed, then set the SPHINXBUILD environment variable to point
+ echo.to the full path of the 'sphinx-build' executable. Alternatively you
+ echo.may add the Sphinx directory to PATH.
+ echo.
+ echo.If you don't have Sphinx installed, grab it from
+ echo.http://sphinx-doc.org/
+ exit /b 1
+)
+
+%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
+goto end
+
+:help
+%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS%
+
+:end
+popd
diff --git a/src/lightning_app/CHANGELOG.md b/src/lightning_app/CHANGELOG.md
new file mode 100644
index 0000000000..17ad3a0cde
--- /dev/null
+++ b/src/lightning_app/CHANGELOG.md
@@ -0,0 +1,17 @@
+# Changelog
+
+All notable changes to this project will be documented in this file.
+
+The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
+
+## \[0.6.0\] - 2022-MM-DD
+
+### Added
+
+- Update the Lightning App docs ([#13537](https://github.com/PyTorchLightning/pytorch-lightning/pull/13537))
+
+### Changed
+
+### Deprecated
+
+### Fixed