Skip to content

Commit

Permalink
Make storage dependency as an optional dependency (kubeflow#2700)
Browse files Browse the repository at this point in the history
* move storage from kserve sdk to seperate module

Signed-off-by: Andrews Arokiam <andrews.arokiam@ideas2it.com>

* add unit test for storage in workflow

Signed-off-by: Andrews Arokiam <andrews.arokiam@ideas2it.com>

* update python model runtimes

Signed-off-by: Andrews Arokiam <andrews.arokiam@ideas2it.com>

* fix linting errors

Signed-off-by: Andrews Arokiam <andrews.arokiam@ideas2it.com>

* refactor storage as kserve optional dependency

Signed-off-by: Andrews Arokiam <andrews.arokiam@ideas2it.com>

---------

Signed-off-by: Andrews Arokiam <andrews.arokiam@ideas2it.com>
  • Loading branch information
andyi2it authored Mar 10, 2023
1 parent 38d9a56 commit adddf8c
Show file tree
Hide file tree
Showing 33 changed files with 178 additions and 138 deletions.
57 changes: 29 additions & 28 deletions .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ on:
push:
branches: [ master ]
pull_request:
branches: []
branches: [ ]
jobs:
flake8-lint:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9"]
python-version: [ "3.7", "3.8", "3.9" ]
name: Lint
steps:
- name: Check out source repository
Expand All @@ -28,30 +28,31 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, "3.8", "3.9"]
python-version: [ "3.7", "3.8", "3.9" ]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
- name: Test with pytest
run: |
cd python
pip install -e ./kserve[test]
pytest --cov=kserve ./kserve
pip install -e ./sklearnserver
pytest --cov=sklearnserver ./sklearnserver
pip install -e ./xgbserver
pytest --cov=xgbserver ./xgbserver
pip install -e ./pmmlserver
pytest --cov=pmmlserver ./pmmlserver
pip install -e ./lgbserver
pytest --cov=lgbserver ./lgbserver
pip install -e ./paddleserver[test]
pytest --cov=paddleserver ./paddleserver
pip install -e ./alibiexplainer
pytest --cov=alibiexplainer ./alibiexplainer
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
- name: Test with pytest
run: |
cd python
pip install -e ./kserve[storage]
pip install -e ./kserve[test]
pytest --cov=kserve ./kserve
pip install -e ./sklearnserver[test]
pytest --cov=sklearnserver ./sklearnserver
pip install -e ./xgbserver[test]
pytest --cov=xgbserver ./xgbserver
pip install -e ./pmmlserver[test]
pytest --cov=pmmlserver ./pmmlserver
pip install -e ./lgbserver[test]
pytest --cov=lgbserver ./lgbserver
pip install -e ./paddleserver[test]
pytest --cov=paddleserver ./paddleserver
pip install -e ./alibiexplainer[test]
pytest --cov=alibiexplainer ./alibiexplainer
2 changes: 1 addition & 1 deletion python/alibiexplainer.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ COPY third_party third_party

COPY kserve kserve
COPY VERSION VERSION
RUN pip install --no-cache-dir --upgrade pip && pip install --no-cache-dir -e ./kserve
RUN pip install --no-cache-dir --upgrade pip && pip install --no-cache-dir -e ./kserve[storage]

COPY alibiexplainer alibiexplainer
RUN pip install --no-cache-dir -e ./alibiexplainer
Expand Down
3 changes: 2 additions & 1 deletion python/alibiexplainer/alibiexplainer/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from alibiexplainer.parser import parse_args

import kserve
from kserve.storage import Storage

logging.basicConfig(level=kserve.constants.KSERVE_LOGLEVEL)

Expand All @@ -35,7 +36,7 @@ def main():
alibi_model = None
if args.storage_uri is not None:
alibi_model = os.path.join(
kserve.Storage.download(args.storage_uri), EXPLAINER_FILENAME
Storage.download(args.storage_uri), EXPLAINER_FILENAME
)
with open(alibi_model, "rb") as f:
logging.info("Loading Alibi model")
Expand Down
2 changes: 1 addition & 1 deletion python/alibiexplainer/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
python_requires='>=3.7',
packages=find_packages("alibiexplainer"),
install_requires=[
f"kserve>={version}",
f"kserve[storage]>={version}",
"nest_asyncio>=1.4.0",
"alibi==0.6.4",
"joblib>=0.13.2",
Expand Down
4 changes: 2 additions & 2 deletions python/alibiexplainer/tests/test_anchor_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import tensorflow as tf
import json
import numpy as np
import kserve
import dill
from kserve.storage import Storage


CIFAR10_EXPLAINER_URI = "gs://seldon-models/tfserving/cifar10/explainer-py36-0.5.2"
Expand All @@ -28,7 +28,7 @@
def test_cifar10_images(): # pylint: disable-msg=too-many-locals
os.environ.clear()
alibi_model = os.path.join(
kserve.Storage.download(CIFAR10_EXPLAINER_URI), EXPLAINER_FILENAME
Storage.download(CIFAR10_EXPLAINER_URI), EXPLAINER_FILENAME
)
with open(alibi_model, "rb") as f:
alibi_model = dill.load(f)
Expand Down
4 changes: 2 additions & 2 deletions python/alibiexplainer/tests/test_anchor_tabular.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
# limitations under the License.

from alibiexplainer.anchor_tabular import AnchorTabular
import kserve
import os
import dill
from sklearnserver.model import SKLearnModel
from alibi.datasets import fetch_adult
import numpy as np
import json
from .utils import Predictor
from kserve.storage import Storage

ADULT_EXPLAINER_URI = "gs://kfserving-examples/models/sklearn/1.0/income/explainer-py37-0.6.2"
ADULT_MODEL_URI = "gs://kfserving-examples/models/sklearn/1.0/income/model"
Expand All @@ -30,7 +30,7 @@
def test_anchor_tabular():
os.environ.clear()
alibi_model = os.path.join(
kserve.Storage.download(ADULT_EXPLAINER_URI), EXPLAINER_FILENAME
Storage.download(ADULT_EXPLAINER_URI), EXPLAINER_FILENAME
)
with open(alibi_model, "rb") as f:
skmodel = SKLearnModel("adult", ADULT_MODEL_URI)
Expand Down
5 changes: 5 additions & 0 deletions python/kserve/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ KServe Python SDK can be installed by `pip` or `Setuptools`.
pip install kserve
```

To install Kserve with storage support
```sh
pip install kserve[storage]
```

### Setuptools

Install via [Setuptools](http://pypi.python.org/pypi/setuptools).
Expand Down
1 change: 0 additions & 1 deletion python/kserve/kserve/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from .inference_client import InferenceServerClient
from .protocol.infer_type import InferRequest, InferInput, InferResponse, InferOutput
from .model_repository import ModelRepository
from .storage import Storage
from .constants import constants
from .utils import utils

Expand Down
17 changes: 17 additions & 0 deletions python/kserve/kserve/storage/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2023 The KServe Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# flake8: noqa

from kserve.storage.storage import Storage
7 changes: 7 additions & 0 deletions python/kserve/kserve/storage/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
urllib3>=1.26.8
azure-storage-blob==12.9.0
azure-storage-file-share==12.7.0
azure-identity>=1.8.0
boto3~=1.21
google-cloud-storage>=1.20.0
requests>=2.20.0
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2021 The KServe Authors.
# Copyright 2023 The KServe Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -38,7 +38,7 @@
from google.auth import exceptions
from google.cloud import storage

from .model_repository import MODEL_MOUNT_DIRS
MODEL_MOUNT_DIRS = "/mnt/models"

_GCS_PREFIX = "gs://"
_S3_PREFIX = "s3://"
Expand Down
Loading

0 comments on commit adddf8c

Please sign in to comment.