Skip to content

Commit

Permalink
add backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
meori lehr authored and seldondev committed Jul 20, 2020
1 parent 94538b4 commit c7458cf
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
26 changes: 26 additions & 0 deletions doc/source/servers/mlflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,32 @@ spec:
replicas: 1
```
## MLFlow xtype
By default the server will call your loaded model's predict function with a `numpy.ndarray`. If you wish for it to call it with `pandas.DataFrame` instead, you can pass a parameter `X_type` and set it to `DataFrame`. For example:

```yaml
apiVersion: machinelearning.seldon.io/v1alpha2
kind: SeldonDeployment
metadata:
name: mlflow
spec:
name: wines
predictors:
- graph:
children: []
implementation: MLFLOW_SERVER
modelUri: gs://seldon-models/mlflow/elasticnet_wine
name: classifier
parameters:
- name: xtype
type: STRING
value: DataFrame
name: default
replicas: 1
```

```
You can also try out a [worked
notebook](../examples/server_examples.html#Serve-MLflow-Elasticnet-Wines-Model)
or check our [talk at the Spark + AI Summit
Expand Down
16 changes: 11 additions & 5 deletions servers/mlflowserver/mlflowserver/MLFlowServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@


class MLFlowServer(SeldonComponent):
def __init__(self, model_uri: str):
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}")
self.model_uri = model_uri
self.xtype = xtype
self.ready = False

def load(self):
Expand All @@ -34,11 +36,15 @@ def predict(

if not self.ready:
raise requests.HTTPError("Model not loaded yet")
if feature_names is not None and len(feature_names) > 0:
df = pd.DataFrame(data=X, columns=feature_names)

if self.xtype == "ndarray":
result = self._model.predict(X)
else:
df = pd.DataFrame(data=X)
result = self._model.predict(df)
if feature_names is not 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)
logger.info(f"Prediction result: {result}")
return result

Expand Down

0 comments on commit c7458cf

Please sign in to comment.