Skip to content

Commit

Permalink
enable import lightning.app if it is installed (#20059)
Browse files Browse the repository at this point in the history
  • Loading branch information
Borda authored and lantiga committed Jul 8, 2024
1 parent 249230a commit cc457fe
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 4 deletions.
1 change: 0 additions & 1 deletion .github/workflows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ Brief description of all our automation tools used for boosting development perf
| .azure-pipelines/gpu-tests-fabric.yml | Run only GPU-specific tests, standalone\*, and examples. | GPU |
| .azure-pipelines/gpu-tests-pytorch.yml | Run only GPU-specific tests, standalone\*, and examples. | GPU |
| .azure-pipelines/gpu-benchmarks.yml | Run speed/memory benchmarks for parity with vanila PyTorch. | GPU |
| .github/workflows/ci-flagship-apps.yml | Run end-2-end tests with full applications, including deployment to the production cloud. | CPU |
| .github/workflows/ci-tests-pytorch.yml | Run all tests except for accelerator-specific, standalone and slow tests. | CPU |
| .github/workflows/tpu-tests.yml | Run only TPU-specific tests. Requires that the PR title contains '\[TPU\]' | TPU |

Expand Down
53 changes: 53 additions & 0 deletions .github/workflows/ci-pkg-extend.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Package extras

# see: https://help.github.com/en/actions/reference/events-that-trigger-workflows
on:
push:
branches: [master, "release/*"]
pull_request:
branches: [master, "release/*"]
types: [opened, reopened, ready_for_review, synchronize] # added `ready_for_review` since draft is skipped
paths:
- ".github/workflows/ci-pkg-extend.yml"
- "requirements/ci.txt"
- "requirements/app/*"
- "requirements/data/*"
- "src/lightning/app/*"
- "src/lightning/data/*"
- "!*.md"
- "!**/*.md"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.head_ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

defaults:
run:
shell: bash

jobs:

import-pkg:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: ["ubuntu-22.04", "macOS-12", "windows-2022"]
pkg-name: ["app", "data"]
python-version: ["3.8", "3.11"]
env:
TORCH_URL: "https://download.pytorch.org/whl/cpu/torch_stable.html"
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install package
run: pip install lightning[${{ matrix.pkg-name }}] -f $TORCH_URL
timeout-minutes: 10

- name: Try importing
run: from lightning.${{ matrix.pkg-name }} import *
shell: python

2 changes: 1 addition & 1 deletion .github/workflows/ci-pkg-install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ jobs:
if: ${{ matrix.pkg-name == 'lightning' || matrix.pkg-name == 'notset' }}
working-directory: src/lit
run: |
items=("data")
items=("app" "data")
for item in "${items[@]}"; do
echo "Removing $item"
rm -rf $item
Expand Down
3 changes: 2 additions & 1 deletion examples/fabric/tensor_parallel/train.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import lightning as L
import torch
import torch.nn.functional as F
from data import RandomTokenDataset
from lightning.fabric.strategies import ModelParallelStrategy
from model import ModelArgs, Transformer
from parallelism import parallelize
from torch.distributed.tensor.parallel import loss_parallel
from torch.utils.data import DataLoader

from data import RandomTokenDataset


def train():
strategy = ModelParallelStrategy(
Expand Down
3 changes: 2 additions & 1 deletion examples/pytorch/tensor_parallel/train.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import lightning as L
import torch
import torch.nn.functional as F
from data import RandomTokenDataset
from lightning.pytorch.strategies import ModelParallelStrategy
from model import ModelArgs, Transformer
from parallelism import parallelize
from torch.distributed.tensor.parallel import loss_parallel
from torch.utils.data import DataLoader

from data import RandomTokenDataset


class Llama3(L.LightningModule):
def __init__(self):
Expand Down
3 changes: 3 additions & 0 deletions requirements/app/app.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# NOTE: this is here only to expose `pip install lightning[app]`. we don't install or test it in this project's CI

lightning_app >= 2.3.3, <2.3.4
26 changes: 26 additions & 0 deletions src/lightning/app/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import sys

from lightning_utilities.core.imports import RequirementCache, module_available

__all__ = []

if not RequirementCache("lightning_app"):
raise ModuleNotFoundError("Please, run `pip install lightning-app`") # E111

else:
import lightning_app

# Enable resolution at least for lower data namespace
sys.modules["lightning.app"] = lightning_app

from lightning_app.core.app import LightningApp # noqa: E402
from lightning_app.core.flow import LightningFlow # noqa: E402
from lightning_app.core.work import LightningWork # noqa: E402
from lightning_app.plugin.plugin import LightningPlugin # noqa: E402
from lightning_app.utilities.packaging.build_config import BuildConfig # noqa: E402
from lightning_app.utilities.packaging.cloud_compute import CloudCompute # noqa: E402

if module_available("lightning_app.components.demo"):
from lightning.app.components import demo # noqa: F401

__all__ = ["LightningApp", "LightningFlow", "LightningWork", "LightningPlugin", "BuildConfig", "CloudCompute"]

0 comments on commit cc457fe

Please sign in to comment.