Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
truskovskiyk committed Sep 7, 2024
1 parent 807c3ec commit 392b7cb
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 115 deletions.
67 changes: 10 additions & 57 deletions .github/workflows/module-5.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,57 +9,9 @@ on:
branches:
- main
# paths:
# - 'module-4/**'
# - 'module-5/**'

jobs:
# build:
# runs-on: ubuntu-latest
# steps:
# - name: Checkout
# uses: actions/checkout@v2

# - name: Login to Docker Hub
# uses: docker/login-action@v1
# with:
# username: ${{ secrets.DOCKER_HUB_USERNAME }}
# password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}

# - name: Set up Docker Buildx
# uses: docker/setup-buildx-action@v1

# - name: Build app streamlit
# uses: docker/build-push-action@v2
# with:
# context: week-5/
# file: week-5/Dockerfile
# push: true
# target: app-streamlit
# tags: ${{ secrets.DOCKER_HUB_USERNAME }}/app-streamlit:latest
# cache-from: type=registry,ref=${{ secrets.DOCKER_HUB_USERNAME }}/app-streamlit:buildcache
# cache-to: type=registry,ref=${{ secrets.DOCKER_HUB_USERNAME }}/app-streamlit:buildcache,mode=max

# - name: Build app fastapi
# uses: docker/build-push-action@v2
# with:
# context: week-5/
# file: week-5/Dockerfile
# push: true
# target: app-fastapi
# tags: ${{ secrets.DOCKER_HUB_USERNAME }}/app-fastapi:latest
# cache-from: type=registry,ref=${{ secrets.DOCKER_HUB_USERNAME }}/app-fastapi:buildcache
# cache-to: type=registry,ref=${{ secrets.DOCKER_HUB_USERNAME }}/app-fastapi:buildcache,mode=max

# - name: Build app seldon
# uses: docker/build-push-action@v2
# with:
# context: week-5/
# file: week-5/Dockerfile
# push: true
# target: app-seldon
# tags: ${{ secrets.DOCKER_HUB_USERNAME }}/app-seldon:latest
# cache-from: type=registry,ref=${{ secrets.DOCKER_HUB_USERNAME }}/app-seldon:buildcache
# cache-to: type=registry,ref=${{ secrets.DOCKER_HUB_USERNAME }}/app-seldon:buildcache,mode=max


docker-builds:
runs-on: ubuntu-latest
Expand All @@ -77,12 +29,6 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

# - name: Extract metadata (tags, labels) for Docker
# id: meta
# uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
# with:
# images: ghcr.io/kyryl-opens-ml/app-streamlit

- name: Build and push app-streamlit
uses: docker/build-push-action@v6
with:
Expand All @@ -99,11 +45,18 @@ jobs:
target: app-fastapi
tags: ghcr.io/kyryl-opens-ml/app-fastapi:latest


- name: Build and push app-pytriton
uses: docker/build-push-action@v6
with:
context: module-5/
push: true
target: app-pytriton
tags: ghcr.io/kyryl-opens-ml/app-pytriton:latest
tags: ghcr.io/kyryl-opens-ml/app-pytriton:latest

- name: Build and push app-kserve
uses: docker/build-push-action@v6
with:
context: module-5/
push: true
target: app-kserve
tags: ghcr.io/kyryl-opens-ml/app-kserve:latest
29 changes: 3 additions & 26 deletions module-5/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,6 @@ FROM base AS app-pytriton
CMD python serving/pytriton_serving.py


# FROM base AS app-seldon

# # Port for GRPC
# EXPOSE 5000
# # Port for REST
# EXPOSE 9000

# # Define environment variables
# ENV MODEL_NAME SeldonAPI
# ENV SERVICE_TYPE MODEL
# # COPY /app/serving/seldon_api.py /app/SeldonAPI.py
# COPY serving/seldon_api.py /app/SeldonAPI.py

# RUN chown -R 8888 /app
# RUN mkdir /.cache
# RUN chmod 777 /.cache
# RUN mkdir /.config
# RUN chmod 777 /.config

# CMD exec seldon-core-microservice $MODEL_NAME --service-type $SERVICE_TYPE


# FROM base AS app-kserve
# ENV WANDB_API_KEY=cb86168a2e8db7edb905da69307450f5e7867d66
# RUN pip install protobuf==3.20.*
# ENTRYPOINT ["python", "serving/kserve_api.py"]
FROM base AS app-kserve
ENV WANDB_API_KEY=cb86168a2e8db7edb905da69307450f5e7867d66
ENTRYPOINT ["python", "serving/kserve_api.py"]
10 changes: 4 additions & 6 deletions module-5/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ build_pytriton:
run_pytriton: build_pytriton
docker run -it -p 8001:8001 -p 8000:8000 -p 8002:8002 -e WANDB_API_KEY=${WANDB_API_KEY} app-pytriton:latest

build_kserve:
docker build -f Dockerfile -t app-kserve:latest --target app-kserve .


run_kserve: build_kserve
docker run -e PORT=8080 -e WANDB_API_KEY=${WANDB_API_KEY} -p 8081:8080 app-kserve:latest


build_app_seldon:
Expand All @@ -29,10 +32,5 @@ build_app_seldon:
run_app_seldon: build_app_seldon
docker run -it -p 8081:8080 -e WANDB_API_KEY=${WANDB_API_KEY} app-seldon:latest

build_kserve:
docker build -f Dockerfile -t app-kserve:latest --target app-kserve .

run_kserve:
docker run -e PORT=8080 -e WANDB_API_KEY=${WANDB_API_KEY} -p 8081:8080 app-kserve:latest


25 changes: 5 additions & 20 deletions module-5/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ Install
curl -s "https://raw.githubusercontent.com/kserve/kserve/release-0.13/hack/quick_install.sh" | bash
```

Deploy iris
## IRIS

```
kubectl create -f k8s/kserve-iris.yaml
kubectl get inferenceservices sklearn-iris
```

Port forward iris
Port forward

```
kubectl get svc --namespace istio-system
Expand All @@ -126,26 +126,11 @@ kubectl port-forward --namespace istio-system svc/istio-ingressgateway 8080:80
Call API

```
kubectl get inferenceservice sklearn-iris
SERVICE_HOSTNAME=$(kubectl get inferenceservice sklearn-iris -o jsonpath='{.status.url}' | cut -d "/" -f 3)
export SERVICE_HOSTNAME=sklearn-iris.default.example.com
export INGRESS_HOST=localhost
export INGRESS_PORT=8080
curl -v -H "Host: ${SERVICE_HOSTNAME}" -H "Content-Type: application/json" "http://${INGRESS_HOST}:${INGRESS_PORT}/v1/models/sklearn-iris:predict" -d @./iris-input.json
```

Load test


curl -v -H "Host: sklearn-iris.default.example.com" -H "Content-Type: application/json" "http://localhost:8080/v1/models/sklearn-iris:predict" -d @data-samples/iris-input.json
```
kubectl create -f https://raw.githubusercontent.com/kserve/kserve/release-0.11/docs/samples/v1beta1/sklearn/v1/perf.yaml
```


## Custom

Custom model

- https://kserve.github.io/website/latest/modelserving/v1beta1/custom/custom_model/#build-custom-serving-image-with-buildpacks

Expand All @@ -154,7 +139,7 @@ docker build -f Dockerfile -t kyrylprojector/custom-model:latest --target app-ks
docker push kyrylprojector/custom-model:latest
docker run -e PORT=8080 -p 5000:8080 kyrylprojector/custom-model:latest
curl localhost:5000/v1/models/custom-model:predict -d @./kserve-input.json
curl localhost:5000/v1/models/custom-model:predict -d @data-samples/kserve-input.json
kubectl create -f k8s/kserve-custom.yaml
Expand Down
3 changes: 1 addition & 2 deletions module-5/k8s/kserve-custom.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@ spec:
predictor:
containers:
- name: kserve-container
image: kyrylprojector/custom-model:latest

image: ${DOCKER_USER}/custom-model:v1
3 changes: 0 additions & 3 deletions module-5/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,3 @@ kserve
torch==2.4.1
nvidia_pytriton==0.5.10
ipython
# seldon-core==1.14.1
# # kserve==0.10.1
# # ray==2.0.0
4 changes: 3 additions & 1 deletion module-5/serving/kserve_api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
from serving.predictor import Predictor
from typing import Dict
from kserve import Model, ModelServer
Expand All @@ -13,7 +14,8 @@ def load(self):
self.ready = True

def predict(self, payload: Dict, headers: Dict[str, str] = None) -> Dict:
instances = payload["instances"]
json_payload = json.loads(payload.decode('utf-8'))
instances = json_payload["instances"]
predictions = self.predictor.predict(instances)
return {"predictions": predictions.tolist()}

Expand Down

0 comments on commit 392b7cb

Please sign in to comment.