Fix model serving part of xgboost_ams_housing example. (#478)

* Fix model serving for ames house example

* change the step instructions

* add public image
This commit is contained in:
Zhenghui Wang 2019-01-15 12:30:51 -08:00 committed by Kubernetes Prow Robot
parent 46a795693a
commit 1ed08b9af2
2 changed files with 23 additions and 23 deletions

View File

@ -93,30 +93,18 @@ The model is exported to the location `/tmp/ames/housing.dat`. We will use [Seld
* `requirements.txt`
## Model Serving Locally
We are going to use [seldon-core](https://github.com/SeldonIO/seldon-core/) to serve the model. [HousingServe.py](seldon_serve/HousingServe.py) contains the code to serve the model. Run the following command to create a microservice
We are going to use [seldon-core](https://github.com/SeldonIO/seldon-core/) to serve the model. [HoussingServe.py](seldon_serve/HousingServe.py) contains the code to serve the model. You can find seldon core model wrapping details [here](https://github.com/SeldonIO/seldon-core/blob/master/docs/wrappers/python.md). The seldon-core microservice image can be built by the following command.
```
docker run -v $(pwd):/seldon_serve seldonio/core-python-wrapper:0.7 /seldon_serve HousingServe 0.1 gcr.io --base-image=python:3.6 --image-name=${PROJECT_ID}/housingserve
cd seldon_serve && s2i build . seldonio/seldon-core-s2i-python2:0.4 gcr.io/${PROJECT_ID}/housingserve:latest --loglevel=3
```
Let's build the seldon-core microservice image. You can find seldon core model wrapping details [here](https://github.com/SeldonIO/seldon-core/blob/master/docs/wrappers/python.md).
Let's run the docker image locally.
```
cd build
./build_image.sh
```
You should see the docker image locally `gcr.io/cloudmlplat/housingserve` which can be run locally to serve the model. Before running the image locally push it to `gcr.io`
```
gcloud auth configure-docker
docker push gcr.io/${PROJECT_ID}/housingserve:0.1
```
Let's run the docker image now
```
docker run -p 5000:5000 gcr.io/cloudmlplat/housingserve:0.1
docker run -p 5000:5000 gcr.io/${PROJECT_ID}/housingserve:latest
```
Now you are ready to send requests on `localhost:5000`
@ -125,6 +113,7 @@ Now you are ready to send requests on `localhost:5000`
curl -H "Content-Type: application/x-www-form-urlencoded" -d 'json={"data":{"tensor":{"shape":[1,37],"values":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37]}}}' http://localhost:5000/predict
```
The response looks like this.
```
{
"data": {
@ -147,9 +136,9 @@ curl -H "Content-Type: application/x-www-form-urlencoded" -d 'json={"data":{"ten
```
## Model serving on GKE
One of the amazing features of Kubernetes is that you can run it anywhere i.e., local, on-prem and cloud. We will show you how to run your code on Google Kubernetes Engine. First off, start a GKE cluster.
One of the amazing features of Kubernetes is that you can run it anywhere i.e., local, on-prem and cloud. We will show you how to run your code on Google Kubernetes Engine. First off, start a GKE cluster.
Deploy Seldon core to your GKE cluster by following the instructions in the Deploy Seldon Core section [here](https://github.com/kubeflow/examples/blob/fb2fb26f710f7c03996f08d81607f5ebf7d5af09/github_issue_summarization/serving_the_model.md#deploy-seldon-core). Once everything is successful you can verify it using `kubectl get pods -n${NAMESPACE}`.
Deploy Seldon core to your GKE cluster by following the instructions in the Deploy Seldon Core section [here](https://github.com/kubeflow/examples/blob/fb2fb26f710f7c03996f08d81607f5ebf7d5af09/github_issue_summarization/serving_the_model.md#deploy-seldon-core). Once everything is successful you can verify it using `kubectl get pods -n ${NAMESPACE}`.
```
NAME READY STATUS RESTARTS AGE
@ -163,12 +152,19 @@ tf-hub-0 1/1 Running 0 16m
tf-job-dashboard-7b57c549c8-bfpp8 1/1 Running 0 16m
tf-job-operator-594d8c7ddd-lqn8r 1/1 Running 0 16m
```
Deploy the XGBoost model
Second, we need to upload our previously built docker image to `gcr.io`. A public image is available at `gcr.io/kubeflow-examples/housingserve:latest`
```
ks generate seldon-serve-simple xgboost-ames \
gcloud auth configure-docker
docker push gcr.io/${PROJECT_ID}/housingserve:latest
```
Finally, we can deploy the XGBoost model
```
ks generate seldon-serve-simple-v1alpha2 xgboost-ames \
--name=xgboost-ames \
--image=gcr.io/cloudmlplat/housingserve:0.1 \
--image=gcr.io/${PROJECT_ID}/housingserve:latest \
--namespace=${NAMESPACE} \
--replicas=1

View File

@ -0,0 +1,4 @@
MODEL_NAME=HousingServe
API_TYPE=REST
SERVICE_TYPE=MODEL
PERSISTENCE=0