Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update MLflow in MLFLOW_SERVER #2412

Merged
merged 4 commits into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ examples/models/r_mnist/t10k-labels-idx1-ubyte
examples/models/r_mnist/train-images-idx3-ubyte
examples/models/r_mnist/train-labels-idx1-ubyte
examples/models/sklearn_iris_fbs/IrisClassifier.sav
examples/models/mlflow_server_ab_test_ambassador/mlruns

# Pickle files
*.pickle
Expand Down Expand Up @@ -219,4 +220,4 @@ examples/models/autoscaling/autoscaling_example.py
*.log

# vscode local history
.history/
.history/
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@
"outputs": [],
"source": [
"!curl -X POST -H 'Content-Type: application/json' \\\n",
" -d \"{'data': {'names': [], 'ndarray': [[7.0, 0.27, 0.36, 20.7, 0.045, 45.0, 170.0, 1.001, 3.0, 0.45, 8.8]]}}\" \\\n",
" http://localhost:80/seldon/seldon/mlflow-deployment/api/v0.1/predictions"
" -d '{\"data\": {\"names\": [], \"ndarray\": [[7.0, 0.27, 0.36, 20.7, 0.045, 45.0, 170.0, 1.001, 3.0, 0.45, 8.8]]}}' \\\n",
" http://localhost:8003/seldon/seldon/mlflow-deployment/api/v0.1/predictions"
]
},
{
Expand Down Expand Up @@ -550,6 +550,12 @@
"metadata": {},
"outputs": [],
"source": [
"sc = SeldonClient(\n",
" gateway=\"ambassador\", \n",
" namespace=\"seldon\",\n",
" deployment_name='wines-classifier'\n",
")\n",
"\n",
"def _get_reward(y, y_pred):\n",
" if y == y_pred:\n",
" return 500 \n",
Expand All @@ -568,7 +574,7 @@
" data=X,\n",
" names=feature_names)\n",
" \n",
" y_pred = r.response.data.tensor.values\n",
" y_pred = r.response['data']['tensor']['values']\n",
" reward = _get_reward(y, y_pred)\n",
" sc.feedback(\n",
" deployment_name=\"mlflow-deployment\",\n",
Expand Down Expand Up @@ -625,7 +631,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.8"
"version": "3.7.8"
},
"varInspector": {
"cols": {
Expand Down
18 changes: 10 additions & 8 deletions servers/mlflowserver/mlflowserver/MLFlowServer.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import numpy as np
import yaml
import os
import logging
import requests
import numpy as np
import pandas as pd

from mlflow import pyfunc
from seldon_core import Storage
from seldon_core.user_model import SeldonComponent
from typing import Dict, List, Union, Iterable
import yaml
import os
from typing import Dict, List, Union

logger = logging.getLogger()

MLFLOW_SERVER = "model"


class MLFlowServer(SeldonComponent):
def __init__(self, model_uri: str, xtype: str = 'ndarray'):
def __init__(self, model_uri: str, xtype: str = "ndarray"):
super().__init__()
logger.info(f"Creating MLFLow server with URI {model_uri}")
logger.info(f"xtype: {xtype}")
Expand All @@ -30,9 +31,9 @@ def load(self):
self.ready = True

def predict(
self, X: np.ndarray, feature_names: Iterable[str] = [], meta: Dict = None
self, X: np.ndarray, feature_names: List[str] = [], meta: Dict = None
) -> Union[np.ndarray, List, Dict, str, bytes]:
logger.info(f"Requesting prediction with: {X}")
logger.debug(f"Requesting prediction with: {X}")

if not self.ready:
raise requests.HTTPError("Model not loaded yet")
Expand All @@ -45,7 +46,8 @@ def predict(
else:
df = pd.DataFrame(data=X)
result = self._model.predict(df)
logger.info(f"Prediction result: {result}")

logger.debug(f"Prediction result: {result}")
return result

def init_metadata(self):
Expand Down
8 changes: 4 additions & 4 deletions servers/mlflowserver/mlflowserver/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pyyaml==5.1.2
requests==2.22.0
mlflow>=1.4.0,<1.9.0
pandas
pyyaml<5.4.0
requests<2.25.0
mlflow<1.12.0
pandas<1.2.0

# local seldon-core inside the s2i image
/microservice/python