Skip to content

Commit cc457fe

Browse files
Bordalantiga
authored andcommitted
enable import lightning.app if it is installed (#20059)
1 parent 249230a commit cc457fe

File tree

7 files changed

+87
-4
lines changed

7 files changed

+87
-4
lines changed

.github/workflows/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ Brief description of all our automation tools used for boosting development perf
1414
| .azure-pipelines/gpu-tests-fabric.yml | Run only GPU-specific tests, standalone\*, and examples. | GPU |
1515
| .azure-pipelines/gpu-tests-pytorch.yml | Run only GPU-specific tests, standalone\*, and examples. | GPU |
1616
| .azure-pipelines/gpu-benchmarks.yml | Run speed/memory benchmarks for parity with vanila PyTorch. | GPU |
17-
| .github/workflows/ci-flagship-apps.yml | Run end-2-end tests with full applications, including deployment to the production cloud. | CPU |
1817
| .github/workflows/ci-tests-pytorch.yml | Run all tests except for accelerator-specific, standalone and slow tests. | CPU |
1918
| .github/workflows/tpu-tests.yml | Run only TPU-specific tests. Requires that the PR title contains '\[TPU\]' | TPU |
2019

.github/workflows/ci-pkg-extend.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Package extras
2+
3+
# see: https://help.github.com/en/actions/reference/events-that-trigger-workflows
4+
on:
5+
push:
6+
branches: [master, "release/*"]
7+
pull_request:
8+
branches: [master, "release/*"]
9+
types: [opened, reopened, ready_for_review, synchronize] # added `ready_for_review` since draft is skipped
10+
paths:
11+
- ".github/workflows/ci-pkg-extend.yml"
12+
- "requirements/ci.txt"
13+
- "requirements/app/*"
14+
- "requirements/data/*"
15+
- "src/lightning/app/*"
16+
- "src/lightning/data/*"
17+
- "!*.md"
18+
- "!**/*.md"
19+
20+
concurrency:
21+
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.head_ref }}
22+
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
23+
24+
defaults:
25+
run:
26+
shell: bash
27+
28+
jobs:
29+
30+
import-pkg:
31+
runs-on: ${{ matrix.os }}
32+
strategy:
33+
fail-fast: true
34+
matrix:
35+
os: ["ubuntu-22.04", "macOS-12", "windows-2022"]
36+
pkg-name: ["app", "data"]
37+
python-version: ["3.8", "3.11"]
38+
env:
39+
TORCH_URL: "https://download.pytorch.org/whl/cpu/torch_stable.html"
40+
steps:
41+
- uses: actions/checkout@v4
42+
- uses: actions/setup-python@v5
43+
with:
44+
python-version: ${{ matrix.python-version }}
45+
46+
- name: Install package
47+
run: pip install lightning[${{ matrix.pkg-name }}] -f $TORCH_URL
48+
timeout-minutes: 10
49+
50+
- name: Try importing
51+
run: from lightning.${{ matrix.pkg-name }} import *
52+
shell: python
53+

.github/workflows/ci-pkg-install.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ jobs:
8888
if: ${{ matrix.pkg-name == 'lightning' || matrix.pkg-name == 'notset' }}
8989
working-directory: src/lit
9090
run: |
91-
items=("data")
91+
items=("app" "data")
9292
for item in "${items[@]}"; do
9393
echo "Removing $item"
9494
rm -rf $item

examples/fabric/tensor_parallel/train.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import lightning as L
22
import torch
33
import torch.nn.functional as F
4-
from data import RandomTokenDataset
54
from lightning.fabric.strategies import ModelParallelStrategy
65
from model import ModelArgs, Transformer
76
from parallelism import parallelize
87
from torch.distributed.tensor.parallel import loss_parallel
98
from torch.utils.data import DataLoader
109

10+
from data import RandomTokenDataset
11+
1112

1213
def train():
1314
strategy = ModelParallelStrategy(

examples/pytorch/tensor_parallel/train.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import lightning as L
22
import torch
33
import torch.nn.functional as F
4-
from data import RandomTokenDataset
54
from lightning.pytorch.strategies import ModelParallelStrategy
65
from model import ModelArgs, Transformer
76
from parallelism import parallelize
87
from torch.distributed.tensor.parallel import loss_parallel
98
from torch.utils.data import DataLoader
109

10+
from data import RandomTokenDataset
11+
1112

1213
class Llama3(L.LightningModule):
1314
def __init__(self):

requirements/app/app.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# NOTE: this is here only to expose `pip install lightning[app]`. we don't install or test it in this project's CI
2+
3+
lightning_app >= 2.3.3, <2.3.4

src/lightning/app/__init__.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import sys
2+
3+
from lightning_utilities.core.imports import RequirementCache, module_available
4+
5+
__all__ = []
6+
7+
if not RequirementCache("lightning_app"):
8+
raise ModuleNotFoundError("Please, run `pip install lightning-app`") # E111
9+
10+
else:
11+
import lightning_app
12+
13+
# Enable resolution at least for lower data namespace
14+
sys.modules["lightning.app"] = lightning_app
15+
16+
from lightning_app.core.app import LightningApp # noqa: E402
17+
from lightning_app.core.flow import LightningFlow # noqa: E402
18+
from lightning_app.core.work import LightningWork # noqa: E402
19+
from lightning_app.plugin.plugin import LightningPlugin # noqa: E402
20+
from lightning_app.utilities.packaging.build_config import BuildConfig # noqa: E402
21+
from lightning_app.utilities.packaging.cloud_compute import CloudCompute # noqa: E402
22+
23+
if module_available("lightning_app.components.demo"):
24+
from lightning.app.components import demo # noqa: F401
25+
26+
__all__ = ["LightningApp", "LightningFlow", "LightningWork", "LightningPlugin", "BuildConfig", "CloudCompute"]

0 commit comments

Comments
 (0)