-
Notifications
You must be signed in to change notification settings - Fork 835
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
883 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mlflow | ||
sklearn | ||
pandas |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
mlflow | ||
mlruns |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
] | ||
} | ||
|
||
|
Oops, something went wrong.