Skip to content

Commit b8f3929

Browse files
ethanwharrisBordajustusschock
authored
Simplify store (#18234)
Co-authored-by: Jirka Borovec <[email protected]> Co-authored-by: Justus Schock <[email protected]>
1 parent 41205bb commit b8f3929

21 files changed

+341
-1250
lines changed

.azure/app-cloud-store.yml

Lines changed: 0 additions & 71 deletions
This file was deleted.

.github/checkgroup.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,18 +302,18 @@ subprojects:
302302

303303
- id: "lightning: Store"
304304
paths:
305-
- ".azure/app-cloud-store.yml"
305+
- ".github/workflows/ci-tests-store.yml"
306306
- "src/lightning/__about__.py"
307307
- "src/lightning/__init__.py"
308308
- "src/lightning/__main__.py"
309309
- "src/lightning/__setup__.py"
310310
- "src/lightning/__version__.py"
311311
- "src/lightning/store/**"
312-
- "tests/tests_cloud/**"
312+
- "tests/tests_store/**"
313313
checks:
314-
- "Store.cloud (test_store Linux)"
315-
- "Store.cloud (test_store Mac)"
316-
- "Store.cloud (test_store Windows)"
314+
- "store-cpu (macOS-11, lightning, 3.10, 2.0)"
315+
- "store-cpu (ubuntu-20.04, lightning, 3.10, 2.0)"
316+
- "store-cpu (windows-2022, lightning, 3.10, 2.0)"
317317

318318
# FixMe: re-enable when BE stabilize
319319
# - id: "lightning_app: Azure"

.github/workflows/ci-tests-store.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
name: Test Store
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+
- ".actions/*"
12+
- "requirements/store/**"
13+
- "src/lightning/store/**"
14+
- "tests/tests_store/**"
15+
- "pyproject.toml" # includes pytest config
16+
- ".github/workflows/ci-tests-store.yml"
17+
- "!requirements/*/docs.txt"
18+
- "!*.md"
19+
- "!**/*.md"
20+
21+
concurrency:
22+
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.head_ref }}
23+
cancel-in-progress: ${{ ! (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release/')) }}
24+
25+
defaults:
26+
run:
27+
shell: bash
28+
29+
jobs:
30+
store-cpu:
31+
runs-on: ${{ matrix.os }}
32+
if: github.event.pull_request.draft == false
33+
strategy:
34+
fail-fast: false
35+
matrix:
36+
os: ["macOS-11", "ubuntu-20.04", "windows-2022"]
37+
pkg-name: ["lightning"]
38+
python-version: ["3.10"]
39+
pytorch-version: ["2.0"]
40+
timeout-minutes: 25 # because of building grpcio on Mac
41+
env:
42+
PACKAGE_NAME: ${{ matrix.pkg-name }}
43+
FREEZE_REQUIREMENTS: ${{ ! (github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/heads/release/')) }}
44+
# PYPI_CACHE_DIR: "_pip-wheels"
45+
TORCH_URL_STABLE: "https://download.pytorch.org/whl/cpu/torch_stable.html"
46+
steps:
47+
- uses: actions/checkout@v3
48+
49+
- name: Set up Python ${{ matrix.python-version }}
50+
uses: actions/setup-python@v4
51+
with:
52+
python-version: ${{ matrix.python-version }}
53+
54+
- name: Adjust PyTorch versions in requirements files
55+
if: ${{ matrix.requires != 'oldest' && matrix.release != 'pre' }}
56+
run: |
57+
pip install -q wget packaging
58+
python -m wget https://raw.githubusercontent.com/Lightning-AI/utilities/main/scripts/adjust-torch-versions.py
59+
for fpath in `ls requirements/store/*.txt`; do \
60+
python ./adjust-torch-versions.py $fpath ${{ matrix.pytorch-version }}; \
61+
done
62+
63+
- name: Install package & dependencies
64+
run: |
65+
python -m pip install -q pip -U
66+
pip install -e ".[store-test]" "pytest-timeout" -U -f ${TORCH_URL} --prefer-binary
67+
pip list
68+
69+
- name: Testing Store
70+
working-directory: tests/tests_store
71+
# NOTE: do not include coverage report here, see: https://github.com/nedbat/coveragepy/issues/1003
72+
run: |
73+
python -m coverage run --source lightning \
74+
-m pytest -v --timeout=60 --durations=60
75+
76+
- name: Statistics
77+
if: success()
78+
working-directory: tests/tests_store
79+
run: |
80+
coverage report
81+
coverage xml
82+
83+
- name: Upload coverage to Codecov
84+
uses: codecov/codecov-action@v3
85+
# see: https://github.com/actions/toolkit/issues/399
86+
continue-on-error: true
87+
with:
88+
token: ${{ secrets.CODECOV_TOKEN }}
89+
file: tests/tests_store/coverage.xml
90+
flags: lightning,cpu,pytest,python${{ matrix.python-version }}
91+
name: CPU-coverage
92+
fail_ci_if_error: false

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ known_first_party = [
3535
"parity_pytorch",
3636
"integrations_app",
3737
"tests_app",
38-
"tests_cloud",
38+
"tests_store",
3939
"tests_fabric",
4040
"tests_pytorch",
4141
]

requirements/store/test.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
coverage ==7.2.7
2+
pytest ==7.4.0
3+
pytest-cov ==4.1.0
4+
pytest-rerunfailures ==10.3
5+
pytest-random-order ==1.1.0

src/lightning/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from lightning.pytorch.trainer import Trainer # noqa: E402
3030

3131
import lightning.app # isort: skip # noqa: E402
32+
import lightning.store # isort: skip # noqa: E402
3233

3334
lightning.app._PROJECT_ROOT = os.path.dirname(lightning.app._PROJECT_ROOT)
3435

src/lightning/store/README.md

Lines changed: 11 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
- Store your models on the cloud \<-- simple call: `upload_model(...)`. 🗳️
55
- Share it with your friends \<-- just share the "username/model_name" (and version if required) format. :handshake:
66
- They download using a simple call: `download_model("username/model_name", version="your_version")`. :wink:
7-
- They load your cool model. `load_model("username/model_name", version="your_version")`. :tada:
87
- Lightning :zap: fast, isn't it?. :heart:
98

109
## Usage
@@ -13,87 +12,30 @@
1312

1413
```python
1514
import lightning as L
16-
from sample.model import LitAutoEncoder, Encoder, Decoder
1715

18-
# Initialize your model here
19-
autoencoder = LitAutoEncoder(Encoder(), Decoder())
16+
# Upload a checkpoint:
17+
L.store.upload_model("mnist_model", "mnist_model.ckpt")
2018

21-
# Pass the model object:
22-
# No need to pass the username (we'll deduce ourselves), just pass the model name you want as the first argument (with an optional version):
23-
# format: `model_name:version` (version can either be latest or combination of digits and full-stops: 1.0.0 for example)
24-
L.store.upload_model("unique_model_mnist", model=autoencoder, source_code_path="sample")
25-
26-
# version:
27-
L.store.upload_model(
28-
"unique_model_mnist",
29-
version="1.0.0",
30-
model=autoencoder,
31-
source_code_path="sample/model.py",
32-
)
33-
34-
# OR: (this will save the file which has the model defined)
35-
L.store.upload_model("krshrimali/unique_model_mnist", model=autoencoder)
36-
```
37-
38-
You can also pass the checkpoint path: `upload_model("model_name", version="latest", checkpoint_path=...)`.
39-
40-
**Downloading from the cloud**
41-
42-
At first, you need to download the model to your local machine.
43-
44-
```python
45-
import lightning as L
46-
47-
L.store.download_model(
48-
"krshrimali/unique_model_mnist",
49-
output_dir="your_output_dir",
50-
)
51-
# OR: (default to model_storage
52-
# $HOME
53-
# |- .lightning
54-
# | |- model_store
55-
# | | |- username
56-
# | | | |- <model_name>
57-
# | | | | |- version_<version_with_dots_replaced_by_underscores>
58-
# folder)
59-
L.store.download_model("krshrimali/unique_model_mnist")
19+
# Optionally provide a version:
20+
L.store.upload_model("mnist_model", "mnist_model.ckpt", version="1.0.0")
6021
```
6122

62-
**Loading model**
63-
64-
Then you can load the model to your program.
23+
**List your models**
6524

6625
```python
6726
import lightning as L
6827

69-
# from <username>.<model_name>.version_<version_with_dots_replaced_by_underscores>.<model_source_file> import LitAutoEncoder, Encoder, Decoder
70-
model = L.store.load_model("<username>/<model_name>>", version="version") # version is optional (defaults to latest)
28+
models = L.store.list_models()
7129

72-
# OR: load weights or checkpoint (if they were uploaded)
73-
L.store.load_model(
74-
"<username>/<model_name>", version="version", load_weights=True | False, load_checkpoint=True | False
75-
)
76-
print(model)
30+
print([model.name for model in models])
31+
# ['username/mnist_model']
7732
```
7833

79-
**Loading model weights**
34+
**Downloading from the cloud**
8035

8136
```python
8237
import lightning as L
83-
from sample.model import LitAutoEncoder, Encoder, Decoder
84-
85-
# If you had passed an `output_dir=...` to download_model(...), then you can just do:
86-
# from output_dir.<model_source_file> import LitAutoEncoder, Encoder, Decoder
8738

88-
model = LitAutoEncoder(Encoder(), Decoder())
89-
90-
model = L.store.load_model(load_weights=True, model=model)
91-
print("State dict: ", model.state_dict())
39+
# Download a checkpoint
40+
L.store.download_model("username/mnist_model", "any_path.ckpt")
9241
```
93-
94-
Loading checkpoint is similar, just do: `load_checkpoint=True`.
95-
96-
## Known limitations
97-
98-
- missing web UI for user to brows his uploads
99-
- missing CLI/API to list and delete uploaded models

src/lightning/store/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from lightning.store.cloud_api import download_model, load_model, upload_model
1+
from lightning.store.store import download_model, list_models, upload_model
22

3-
__all__ = ["download_model", "load_model", "upload_model"]
3+
__all__ = ["download_model", "upload_model", "list_models"]

src/lightning/store/authentication.py

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)