Skip to content

Commit

Permalink
add minimal example of deploying pachyderm-trained model
Browse files Browse the repository at this point in the history
  • Loading branch information
RafalSkolasinski authored and seldondev committed Apr 27, 2020
1 parent 401aead commit ef43d9e
Show file tree
Hide file tree
Showing 11 changed files with 1,100 additions and 0 deletions.
2 changes: 2 additions & 0 deletions examples/pachyderm/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
data.csv
model.joblib
19 changes: 19 additions & 0 deletions examples/pachyderm/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

apiVersion: machinelearning.seldon.io/v1
kind: SeldonDeployment
metadata:
name: pachyderm-sklearn
spec:
annotations:
seldon.io/executor: "true"
name: iris
predictors:
- componentSpecs:
graph:
children: []
implementation: SKLEARN_SERVER
modelUri: s3://pachyderm-iris
envSecretRefName: seldon-init-container-secret
name: classifier
name: default
replicas: 1
21 changes: 21 additions & 0 deletions examples/pachyderm/get-data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from sklearn import datasets
import pandas as pd
import numpy as np


def main():
print("Getting Iris Dataset")
iris = datasets.load_iris()
X, y = iris.data, iris.target

data = pd.DataFrame(
data=np.c_[iris["data"], iris["target"]],
columns=iris["feature_names"] + ["target"],
)

data.to_csv("data.csv", index=False)
print("Iris dataset saved to 'data.csv' file")


if __name__ == "__main__":
main()
6 changes: 6 additions & 0 deletions examples/pachyderm/iris-trainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM python:3.7

ADD requirements.txt .
RUN pip install -r requirements.txt

ADD train_iris.py .
14 changes: 14 additions & 0 deletions examples/pachyderm/iris-trainer/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
VERSION=0.1
IMAGE_BASE=seldonio/pachyderm-iris-trainer

KIND_NAME ?= kind


build:
docker build . -t ${IMAGE_BASE}:${VERSION}

push:
docker push ${IMAGE_BASE}:${VERSION}

kind_load:
kind load -v 3 docker-image ${IMAGE_BASE}:${VERSION} --name ${KIND_NAME}
5 changes: 5 additions & 0 deletions examples/pachyderm/iris-trainer/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
scikit-learn == 0.20.3
numpy >= 1.8.2
joblib >= 0.13.0
pandas >= 1.0.1
pyaml >= 5.3
33 changes: 33 additions & 0 deletions examples/pachyderm/iris-trainer/train_iris.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os
import yaml
import joblib
import pandas as pd
from sklearn.pipeline import Pipeline
from sklearn.linear_model import LogisticRegression


# /pfs/iris-data and /pfs/outs are special directories mounted by Pachyderm
INPUT_FILE = os.path.join("/pfs/iris-data", "data.csv")
OUTPUT_FILE = os.path.join("/pfs/out", "model.joblib")


def main():
clf = LogisticRegression(solver="liblinear", multi_class="ovr")
p = Pipeline([("clf", clf)])
print("Training model...")
p.fit(X, y)
print("Model trained!")

print(f"Saving model in {OUTPUT_FILE}")
joblib.dump(p, OUTPUT_FILE)
print("Model saved!")


if __name__ == "__main__":
print(f"Loading iris data set from {INPUT_FILE}")
data = pd.read_csv(INPUT_FILE)
y = data["target"]
X = data[(x for x in data.columns if x != "target")]
print("Dataset loaded!")

main()
12 changes: 12 additions & 0 deletions examples/pachyderm/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

name: iris
versions: [iris/pachyderm:789a6e406b90450185b4280ab16b7f14]
platform: sklearn
inputs:
- datatype: BYTES
name: input
shape: [ 1, 4 ]
outputs:
- datatype: BYTES
name: output
shape: [ 3 ]
11 changes: 11 additions & 0 deletions examples/pachyderm/secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

apiVersion: v1
kind: Secret
metadata:
name: seldon-init-container-secret
type: Opaque
stringData:
AWS_ACCESS_KEY_ID: minioadmin
AWS_SECRET_ACCESS_KEY: minioadmin
AWS_ENDPOINT_URL: http://minio.minio-system.svc.cluster.local:9000
USE_SSL: "false"
Loading

0 comments on commit ef43d9e

Please sign in to comment.