Skip to content

Commit

Permalink
Added mlflow server
Browse files Browse the repository at this point in the history
  • Loading branch information
axsaucedo committed Aug 9, 2019
1 parent 1b95192 commit 344d932
Show file tree
Hide file tree
Showing 8 changed files with 883 additions and 0 deletions.
21 changes: 21 additions & 0 deletions servers/mlflowserver/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
VERSION=0.1
IMAGE_BASE=seldonio/mlflowserver

build_rest:
s2i build -E environment_rest ./mlflowserver seldonio/seldon-core-s2i-python37:0.11-SNAPSHOT ${IMAGE_BASE}_rest:${VERSION}

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

build_grpc:
s2i build -E environment_grpc ./mlflowserver seldonio/seldon-core-s2i-python37:0.11-SNAPSHOT ${IMAGE_BASE}_grpc:${VERSION}

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


.PHONY: push_all
push_all: push_rest push_grpc

.PHONY: build_all
build_all: build_rest build_grpc
4 changes: 4 additions & 0 deletions servers/mlflowserver/environment_grpc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
MODEL_NAME=MLFlowServer
API_TYPE=GRPC
SERVICE_TYPE=MODEL
PERSISTENCE=0
4 changes: 4 additions & 0 deletions servers/mlflowserver/environment_rest
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
MODEL_NAME=MLFlowServer
API_TYPE=REST
SERVICE_TYPE=MODEL
PERSISTENCE=0
46 changes: 46 additions & 0 deletions servers/mlflowserver/mlflowserver/MLFlowServer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from mlflow import pyfunc
import seldon_core
from seldon_core.user_model import SeldonComponent
from typing import Dict, List, Union, Iterable
import numpy as np
import os
import logging
import requests
import pandas as pd

log = logging.getLogger()

class MLFlowServer(SeldonComponent):

def __init__(self, model_uri: str):
super().__init__()
log.info(f"Creating MLFLow server with URI: {model_uri}")
self.model_uri = model_uri
self.ready = False

def load(self):
log.info("Loading model")
self._model = pyfunc.load_model(self.model_uri)
self.ready = True

def predict(
self,
X: np.ndarray,
feature_names: Iterable[str] = [],
meta: Dict = None
) -> Union[np.ndarray, List, Dict, str, bytes]:

log.info(f"Requesting prediction with: {X}")
if not self.ready:
self.load()
# TODO: Make sure this doesn't get called from here, but
# from the actual python wrapper. Raise exception instead
#raise requests.HTTPError("Model not loaded yet")
if not feature_names is None and len(feature_names)>0:
df = pd.DataFrame(data=X, columns=feature_names)
else:
df = pd.DataFrame(data=X)
result = self._model.predict(df)
log.info(f"Prediction result: {result}")
return result

3 changes: 3 additions & 0 deletions servers/mlflowserver/mlflowserver/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mlflow
sklearn
pandas
2 changes: 2 additions & 0 deletions servers/mlflowserver/test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mlflow
mlruns
81 changes: 81 additions & 0 deletions servers/mlflowserver/test/contract.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"features":[
{
"name":"fixed_acidity",
"dtype":"FLOAT",
"ftype":"continuous",
"range":[4,8]
},
{
"name":"volatile_acidity",
"dtype":"FLOAT",
"ftype":"continuous",
"range":[1,10]
},
{
"name":"citric_acid",
"dtype":"FLOAT",
"ftype":"continuous",
"range":[0,3]
},
{
"name":"residual_sugar",
"dtype":"FLOAT",
"ftype":"continuous",
"range":[0,3]
},
{
"name":"chlorides",
"dtype":"FLOAT",
"ftype":"continuous",
"range":[0,3]
},
{
"name":"free_sulfur",
"dtype":"FLOAT",
"ftype":"continuous",
"range":[0,3]
},
{
"name":"total_sulfur",
"dtype":"FLOAT",
"ftype":"continuous",
"range":[0,3]
},
{
"name":"density",
"dtype":"FLOAT",
"ftype":"continuous",
"range":[0,3]
},
{
"name":"ph",
"dtype":"FLOAT",
"ftype":"continuous",
"range":[0,3]
},
{
"name":"sulphates",
"dtype":"FLOAT",
"ftype":"continuous",
"range":[0,3]
},
{
"name":"alcohol",
"dtype":"FLOAT",
"ftype":"continuous",
"range":[0,3]
}
],
"targets":[
{
"name":"class",
"dtype":"FLOAT",
"ftype":"continuous",
"range":[0,10],
"repeat": 1
}
]
}


Loading

0 comments on commit 344d932

Please sign in to comment.