Skip to content

Commit

Permalink
Sync debug branch with master (#15983)
Browse files Browse the repository at this point in the history
* Simplify enabling CPU offload in FSDP (#15832)


Co-authored-by: Jirka Borovec <[email protected]>

* [App] Enable running with spawn context (#15923)

* Fix compiler support test (#15927)

* Enable back inference mode support with hpu & update links (#15918)

* Enable back inference mode support with hpu
* Remove unused
* Update document link and address comment

Signed-off-by: Jerome <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* [App] Introduce auto scaler (#15769)

* Exlucde __pycache__ in setuptools

* Add load balancer example

* wip

* Update example

* rename

* remove prints

* _LoadBalancer -> LoadBalancer

* AutoScaler(work)

* change var name

* remove locust

* Update docs

* include autoscaler in api ref

* docs typo

* docs typo

* docs typo

* docs typo

* remove unused loadtest

* remove unused device_type

* clean up

* clean up

* clean up

* Add docstring

* type

* env vars to args

* expose an API for users to override to customise autoscaling logic

* update example

* comment

* udpate var name

* fix scale mechanism and clean up

* Update exampl

* ignore mypy

* Add test file

* .

* update impl and update tests

* Update changlog

* .

* revert docs

* update test

* update state to keep calling 'flow.run()'

Co-authored-by: Aniket Maurya <[email protected]>

* Add aiohttp to base requirements

* Update docs

Co-authored-by: Luca Antiga <[email protected]>

* Use deserializer utility

* fake trigger

* wip: protect /system/* with basic auth

* read password at runtime

* Change env var name

* import torch as optional

* Don't overcreate works

* simplify imports

* Update example

* aiohttp

* Add work_args work_kwargs

* More docs

* remove FIXME

* Apply Jirka's suggestions

Co-authored-by: Jirka Borovec <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* clean example device

* add comment on init threshold value

* bad merge

* nit: logging format

* {in,out}put_schema -> {in,out}put_type

* lowercase

* docs on seconds

* process_time -> processing_time

* Dont modify work state from flow

* Update tests

* worker_url -> endpoint

* fix exampl

* Fix default scale logic

* Fix default scale logic

* Fix num_pending_works

* Update num_pending_works

* Fix bug creating too many works

* Remove up/downscale_threshold args

* Update example

* Add typing

* Fix example in docstring

* Fix default scale logic

* Update src/lightning_app/components/auto_scaler.py

Co-authored-by: Noha Alon <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* rename method

* rename locvar

* Add todo

* docs ci

* docs ci

* asdfafsdasdf pls docs

* Apply suggestions from code review

Co-authored-by: Ethan Harris <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* .

* doc

* Update src/lightning_app/components/auto_scaler.py

Co-authored-by: Noha Alon <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Revert "[pre-commit.ci] auto fixes from pre-commit.com hooks"

This reverts commit 24983a0.

* Revert "Update src/lightning_app/components/auto_scaler.py"

This reverts commit 56ea78b.

* Remove redefinition

* Remove load balancer run blocker

* raise RuntimeError

* remove has_sent

* lower the default timeout_batching from 10 to 1

* remove debug

* update the default timeout_batching

* .

* tighten condition

* fix endpoint

* typo in runtimeerror cond

* async lock update severs

* add a test

* {in,out}put_type typing

* Update examples/app_server_with_auto_scaler/app.py

Co-authored-by: Jirka Borovec <[email protected]>

* Update .actions/setup_tools.py

Co-authored-by: Aniket Maurya <[email protected]>
Co-authored-by: Luca Antiga <[email protected]>
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: Noha Alon <[email protected]>
Co-authored-by: Ethan Harris <[email protected]>
Co-authored-by: Akihiro Nitta <[email protected]>
Co-authored-by: thomas chaton <[email protected]>

* ENG-627: Docs for CloudCompute Mount Argument (#15182)

fixed conflicts

* Fix LRScheduler import for PyTorch 2.0 (#15940)

* Fix LRScheduler import for PyTorch 2.0
* Add comment for posterity

* CI: fix pypi flow (#15944)

* CI: fixing pypi syntax (#15943)
* connect
* input

* [App] Remove `SingleProcessRuntime` (#15933)

* Remove SingleProcessRuntime
* Remove unused queues
* Docs

* [App] Fix bug when using structures with works (#15911)

* Fix bug when using structures with works
* Add test
* Update CHANGELOG.md

* [App] Wait for full file to be transferred in Path / Payload (#15934)

* Wait for full file to be transferred in Path / Payload
* Fixes

* [docs] Include all components in the API reference (#15805)

* Update docs

Co-authored-by: Jirka Borovec <[email protected]>

* Bump playwright from 1.27.1 to 1.28.0 in /requirements (#15903)

* Bump playwright from 1.27.1 to 1.28.0 in /requirements

Bumps [playwright](https://github.com/Microsoft/playwright-python) from 1.27.1 to 1.28.0.
- [Release notes](https://github.com/Microsoft/playwright-python/releases)
- [Commits](microsoft/playwright-python@v1.27.1...v1.28.0)

---
updated-dependencies:
- dependency-name: playwright
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* 1.28

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jirka <[email protected]>

* [App] Add `configure_layout` method for works (#15926)

* Add `configure_layout` method for works
* Check for api access availability
* Updates from review
* Update CHANGELOG.md
* Apply suggestions from code review

Co-authored-by: Sherin Thomas <[email protected]>

* Make gradients available for all_gather on TPU (#15003)

* Make gradients available for all_gather on TPU
* Modify switch and tests
* Apply suggestions from code review
* Modify tests
* Fix test
* Drop test

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Jirka Borovec <[email protected]>
Co-authored-by: Adrian Wälchli <[email protected]>
Co-authored-by: Carlos Mocholí <[email protected]>
Co-authored-by: Jirka Borovec <[email protected]>

* Don't try to aggregate `requirements/__pycache__/base.txt` in setuptools (#15775)

Exlucde __pycache__ in setuptools

* [App] Multiprocessing-safe work pickling (#15836)

* Upgrade to HPU release 1.7.1 (#15956)

* Upgrade to HPU release 1.7.1
Update torch version check for hpu

Signed-off-by: Jerome <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Multinode on MPS (#15748)

* Fix restarting attribute for lr finder
* update lite executor
* update trainer executor
* update spawn executor
* add multinode component tests
* add testing helpers
* add lite tests
* add trainer tests
* update changelog
* update trainer
* update workflow
* update tests
* debug
* add reason for skipif
* Apply suggestions from code review
* switch skipif

Co-authored-by: Jirka <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Carlos Mocholí <[email protected]>
Co-authored-by: Adrian Wälchli <[email protected]>
Co-authored-by: Jirka Borovec <[email protected]>

* [App] Resolve PythonServer on M1 (#15949)


Co-authored-by: thomas <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Lite: Fix DataLoader shuffling when using DistributedSampler (#15931)


Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* [App] Temporarily disable ready (#15958)

* Fix restarting attribute for lr finder (#15620)

* [App] Improve pdb for multiprocessing (#15950)


Co-authored-by: thomas <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* [App] Improve debug triggering (#15951)

* [App] Add automatic conversion to structures (#15961)

* Make LightningModule torch.jit.script-able again (#15947)

* Make LightningModule torch.jit.script-able again
* remove skip

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* refactor: simplify Tensor import (#15959)

* Fix ImportErrors on Multinode if package not present (#15963)

* Fix typo in definition of world size in docs (#15954)

* [App] Enable running an app from the Gallery (#15941)


Co-authored-by: thomas <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Ethan Harris <[email protected]>
Co-authored-by: Jirka <[email protected]>

* Apply dynamo to training_step, validation_step, test_step, predict_step (#15957)

* Apply dynamo to training_step, validation_step, test_step, predict_step

* Add entry to CHANGELOG.md

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix merge conflict

* rename tpu workflow

Signed-off-by: Jerome <[email protected]>
Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Jirka Borovec <[email protected]>
Co-authored-by: thomas chaton <[email protected]>
Co-authored-by: Luca Antiga <[email protected]>
Co-authored-by: Jerome Anand <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Akihiro Nitta <[email protected]>
Co-authored-by: Aniket Maurya <[email protected]>
Co-authored-by: Noha Alon <[email protected]>
Co-authored-by: Ethan Harris <[email protected]>
Co-authored-by: Akihiro Nitta <[email protected]>
Co-authored-by: Rick Izzo <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Jirka <[email protected]>
Co-authored-by: Sherin Thomas <[email protected]>
Co-authored-by: stekiri <[email protected]>
Co-authored-by: Jirka Borovec <[email protected]>
Co-authored-by: Carlos Mocholí <[email protected]>
Co-authored-by: Justus Schock <[email protected]>
Co-authored-by: thomas <[email protected]>
  • Loading branch information
20 people authored Dec 9, 2022
1 parent 954f864 commit deac2b5
Show file tree
Hide file tree
Showing 122 changed files with 2,604 additions and 712 deletions.
2 changes: 1 addition & 1 deletion .actions/setup_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def _load_aggregate_requirements(req_dir: str = "requirements", freeze_requireme
load_requirements(d, file_name="base.txt", unfreeze=not freeze_requirements)
for d in glob.glob(os.path.join(req_dir, "*"))
# skip empty folder as git artefacts, and resolving Will's special issue
if os.path.isdir(d) and len(glob.glob(os.path.join(d, "*"))) > 0
if os.path.isdir(d) and len(glob.glob(os.path.join(d, "*"))) > 0 and "__pycache__" not in d
]
if not requires:
return None
Expand Down
2 changes: 1 addition & 1 deletion .azure/app-cloud-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
- job: App_cloud_e2e_testing
pool: azure-cpus
container:
image: mcr.microsoft.com/playwright/python:v1.27.1-focal
image: mcr.microsoft.com/playwright/python:v1.28.0-focal
options: "--shm-size=4gb"
strategy:
matrix:
Expand Down
2 changes: 1 addition & 1 deletion .azure/hpu-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
cancelTimeoutInMinutes: "2"
pool: intel-hpus
container:
image: "vault.habana.ai/gaudi-docker/1.7.0/ubuntu20.04/habanalabs/pytorch-installer-1.12.0:latest"
image: "vault.habana.ai/gaudi-docker/1.7.1/ubuntu20.04/habanalabs/pytorch-installer-1.13.0:latest"
options: "--runtime=habana -e HABANA_VISIBLE_DEVICES=all -e OMPI_MCA_btl_vader_single_copy_mechanism=none --cap-add=sys_nice --ipc=host --shm-size=4g -v /usr/bin/docker:/tmp/docker:ro"
workspace:
clean: all
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/pkg-publish/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ runs:
if: inputs.pypi-test-token != ''
with:
user: __token__
password: ${{ secrets.test_pypi_token_lai }}
password: ${{ inputs.pypi-test-token }}
repository_url: https://test.pypi.org/legacy/
packages_dir: pypi/
verbose: true
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci-app-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ name: Test App - examples
# see: https://help.github.com/en/actions/reference/events-that-trigger-workflows
on:
push:
branches: [master, "release/*"]
branches: [master, "release/*", "lite/debug"]
pull_request:
branches: [master, "release/*"]
branches: [master, "release/*", "lite/debug"]
types: [opened, reopened, ready_for_review, synchronize] # added `ready_for_review` since draft is skipped
paths:
- ".actions/**"
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci-app-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ name: Test App
# see: https://help.github.com/en/actions/reference/events-that-trigger-workflows
on:
push:
branches: [master, "release/*"]
branches: [master, "release/*", "lite/debug"]
pull_request:
branches: [master, "release/*"]
branches: [master, "release/*", "lite/debug"]
types: [opened, reopened, ready_for_review, synchronize] # added `ready_for_review` since draft is skipped
paths:
- ".actions/**"
Expand Down Expand Up @@ -94,7 +94,7 @@ jobs:

- name: Adjust tests
if: ${{ matrix.pkg-name == 'lightning' }}
run: python .actions/assistant.py copy_replace_imports --source_dir="./tests" --source_import="lightning_app" --target_import="lightning.app"
run: python .actions/assistant.py copy_replace_imports --source_dir="./tests" --source_import="lightning_app,lightning_lite,pytorch_lightning" --target_import="lightning.app,lightning.lite,lightning.pytorch"

- name: Adjust examples
if: ${{ matrix.pkg-name != 'lightning' }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci-pytorch-dockers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Docker

on:
push:
branches: [master, "release/*"]
branches: [master, "release/*", "lite/debug"]
pull_request:
branches: [master, "release/*"]
branches: [master, "release/*", "lite/debug"]
types: [opened, reopened, ready_for_review, synchronize] # added `ready_for_review` since draft is skipped
paths:
- ".actions/**"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/legacy-checkpoints.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ jobs:
working-directory: ./
env:
PACKAGE_NAME: pytorch
FREEZE_REQUIREMENTS: 1
run: |
pip install . -f https://download.pytorch.org/whl/cpu/torch_stable.html
pip list
Expand Down
9 changes: 3 additions & 6 deletions .github/workflows/release-pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ defaults:
run:
shell: bash

env:
PUBLISH: ${{ startsWith(github.event.ref, 'refs/tags') || github.event_name == 'release' }}

jobs:
init:
runs-on: ubuntu-20.04
Expand Down Expand Up @@ -184,7 +181,7 @@ jobs:

publish-packages:
runs-on: ubuntu-20.04
needs: waiting
needs: [build-packages, waiting]
if: startsWith(github.event.ref, 'refs/tags') || github.event_name == 'release'
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -215,8 +212,8 @@ jobs:
needs: [build-packages]
uses: ./.github/workflows/legacy-checkpoints.yml
with:
push_to_s3: ${{ env.PUBLISH }}
create_pr: ${{ env.PUBLISH }}
push_to_s3: ${{ startsWith(github.event.ref, 'refs/tags') || github.event_name == 'release' }}
create_pr: ${{ startsWith(github.event.ref, 'refs/tags') || github.event_name == 'release' }}
secrets:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_KEY_ID: ${{ secrets.AWS_SECRET_KEY_ID }}
File renamed without changes.
4 changes: 2 additions & 2 deletions dockers/ci-runner-hpu/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
# gaudi-docker-agent:latest

ARG DIST="latest"
ARG GAUDI_VERSION="1.7.0"
ARG PYTORCH_INSTALLER_VERSION="1.12.0"
ARG GAUDI_VERSION="1.7.1"
ARG PYTORCH_INSTALLER_VERSION="1.13.0"
FROM vault.habana.ai/gaudi-docker/${GAUDI_VERSION}/ubuntu20.04/habanalabs/pytorch-installer-${PYTORCH_INSTALLER_VERSION}:${DIST}

LABEL maintainer="https://vault.habana.ai/"
Expand Down
1 change: 0 additions & 1 deletion docs/source-app/api_reference/runners.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,4 @@ ______________
:template: classtemplate.rst

~cloud.CloudRuntime
~singleprocess.SingleProcessRuntime
~multiprocess.MultiProcessRuntime
9 changes: 9 additions & 0 deletions docs/source-app/api_reference/storage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ______________
~path.Path
~drive.Drive
~payload.Payload
~mount.Mount

----

Expand Down Expand Up @@ -56,6 +57,14 @@ Learn more about Storage
:height: 180
:tag: Intermediate

.. displayitem::
:header: The Mount Object.
:description: Mount an AWS S3 Bucket When Running on the Cloud.
:col_css: col-md-4
:button_link: ../workflows/mount_aws_s3_bucket.html
:height: 180
:tag: Intermediate

.. raw:: html

</div>
Expand Down
26 changes: 25 additions & 1 deletion docs/source-app/api_references.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,20 @@ ___________________
:nosignatures:
:template: classtemplate_no_index.rst

~database.client.DatabaseClient
~database.server.Database
~python.popen.PopenPythonScript
~python.tracer.TracerPythonScript
~training.LightningTrainerScript
~serve.gradio.ServeGradio
~serve.serve.ModelInferenceAPI
~serve.python_server.PythonServer
~serve.streamlit.ServeStreamlit
~multi_node.base.MultiNode
~multi_node.lite.LiteMultiNode
~multi_node.pytorch_spawn.PyTorchSpawnMultiNode
~multi_node.trainer.LightningTrainerMultiNode
~auto_scaler.AutoScaler

----

Expand Down Expand Up @@ -71,6 +80,7 @@ _______
~path.Path
~drive.Drive
~payload.Payload
~mount.Mount

Learn more about :ref:`Storage <storage>`.

Expand All @@ -87,5 +97,19 @@ _______
:template: classtemplate_no_index.rst

~cloud.CloudRuntime
~singleprocess.SingleProcessRuntime
~multiprocess.MultiProcessRuntime

----

lightning_app.utilities.packaging
_________________________________

.. currentmodule:: lightning_app.utilities.packaging

.. autosummary::
:toctree: generated/
:nosignatures:
:template: classtemplate_no_index.rst

~cloud_compute.CloudCompute
~build_config.BuildConfig
7 changes: 7 additions & 0 deletions docs/source-app/glossary/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ Glossary
:button_link: ../core_api/lightning_app/index.html
:height: 100

.. displayitem::
:header: Mounts
:description: Mount Cloud Data
:col_css: col-md-6
:button_link: mount.html
:height: 180

.. displayitem::
:header: Sharing Components
:description: Let's create an ecosystem altogether
Expand Down
1 change: 1 addition & 0 deletions docs/source-app/glossary/mount.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.. include:: ../workflows/mount_cloud_object_store.rst
3 changes: 0 additions & 3 deletions docs/source-app/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ We provide ``application_testing`` as a helper funtion to get your application u
os.path.join(_PROJECT_ROOT, "examples/app_v0/app.py"),
"--blocking",
"False",
"--multiprocess",
"--open-ui",
"False",
]
Expand All @@ -129,9 +128,7 @@ First in the list for ``command_line`` is the location of your script. It is an

Next there are a couple of options you can leverage:


* ``blocking`` - Blocking is an app status that says "Do not run until I click run in the UI". For our integration test, since we are not using the UI, we are setting this to "False".
* ``multiprocess/singleprocess`` - This is the runtime your app is expected to run under.
* ``open-ui`` - We set this to false since this is the routine that opens a browser for your local execution.

Once you have your commandline ready, you will then be able to kick off the test and gather results:
Expand Down
8 changes: 8 additions & 0 deletions docs/source-app/workflows/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,14 @@ How to:
:button_link: ssh/index.html
:height: 180

.. displayitem::
:header: Mount Cloud Data
:description: Learn how Lightning Mounts are used to make the contents of an cloud object store bucket available on disk when running in the cloud.
:col_css: col-md-4
:button_link: mount_cloud_object_store.html
:height: 180



.. raw:: html

Expand Down
141 changes: 141 additions & 0 deletions docs/source-app/workflows/mount_cloud_object_store.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
:orphan:

##############
Add Cloud Data
##############

**Audience:** Users who want to read files stored in a Cloud Object Bucket in an app.

******************************
Mounting Public AWS S3 Buckets
******************************

===================
Add Mount to a Work
===================

To mount data from a cloud bucket to your app compute, initialize a :class:`~lightning_app.storage.mount.Mount`
object with the source path of the s3 bucket and the absolute directory path where it should be mounted and
pass the :class:`~lightning_app.storage.mount.Mount` to the :class:`~lightning_app.utilities.packaging.cloud_compute.CloudCompute`
of the :class:`~lightning_app.core.work.LightningWork` it should be mounted on.

In this example, we will mount an S3 bucket: ``s3://ryft-public-sample-data/esRedditJson/`` to ``/content/esRedditJson/``.

.. code-block:: python
from lightning_app import CloudCompute
from lightning_app.storage import Mount
self.my_work = MyWorkClass(
cloud_compute=CloudCompute(
mounts=Mount(
source="s3://ryft-public-sample-data/esRedditJson/",
mount_path="/content/esRedditJson/",
),
)
)
You can also pass multiple mounts to a single work by passing a ``List[Mount(...), ...]`` to the
``CloudCompute(mounts=...)`` argument.

.. note::

* Mounts supported up to 1 Million files, 5GB per file. Need larger mounts? Contact [email protected]
* When adding multiple mounts, each one should have a unique ``mount_path``.
* A maximum of 10 :class:`~lightning_app.storage.mount.Mount`\s can be added to a :class:`~lightning_app.core.work.LightningWork`.

=======================
Read Files From a Mount
=======================

Once a :class:`~lightning_app.storage.mount.Mount` object is passed to :class:`~lightning_app.utilities.packaging.cloud_compute.CloudCompute`,
you can access, list, or read any file from the mount under the specified ``mount_path``, just like you would if it
was on your local machine.

Assuming your ``mount_path`` is ``"/content/esRedditJson/"`` you can do the following:

----------
Read Files
----------

.. code-block:: python
with open("/content/esRedditJson/esRedditJson1", "r") as f:
some_data = f.read()
# do something with "some_data"...
----------
List Files
----------

.. code-block:: python
files = os.listdir("/content/esRedditJson/")
--------------------
See the Full Example
--------------------

.. code-block:: python
:emphasize-lines: 10,15
import os
import lightning as L
from lightning_app import CloudCompute
from lightning_app.storage import Mount
class ReadMount(L.LightningWork):
def run(self):
# Print a list of files stored in the mounted S3 Bucket.
files = os.listdir("/content/esRedditJson/")
for file in files:
print(file)
# Read the contents of a particular file in the bucket "esRedditJson1"
with open("/content/esRedditJson/esRedditJson1", "r") as f:
some_data = f.read()
# do something with "some_data"...
class Flow(L.LightningFlow):
def __init__(self):
super().__init__()
self.my_work = ReadMount(
cloud_compute=CloudCompute(
mounts=Mount(
source="s3://ryft-public-sample-data/esRedditJson/",
mount_path="/content/esRedditJson/",
),
)
)
def run(self):
self.my_work.run()
.. note::

When running a Lighting App on your local machine, any :class:`~lightning_app.utilities.packaging.cloud_compute.CloudCompute`
configuration (including a :class:`~lightning_app.storage.mount.Mount`) is ignored at runtime. If you need access to
these files on your local disk, you should download a copy of them to your machine.

.. note::

Mounted files from an S3 bucket are ``read-only``. Any modifications, additions, or deletions
to files in the mounted directory will not be reflected in the cloud object store.

----

**********************************************
Mounting Private AWS S3 Buckets - Coming Soon!
**********************************************

We'll Let you know when this feature is ready!

----

************************************************
Mounting Google Cloud GCS Buckets - Coming Soon!
************************************************

We'll Let you know when this feature is ready!
Loading

0 comments on commit deac2b5

Please sign in to comment.