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

Issue/1638 model metadata #1671

Merged
merged 2 commits into from Apr 23, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/source/examples/metadata.nblink
@@ -0,0 +1,3 @@
{
"path": "../../../examples/models/metadata/metadata.ipynb"
}
50 changes: 47 additions & 3 deletions doc/source/python/python_component.md
Expand Up @@ -103,7 +103,7 @@ To return metrics associated with a call create a method with signature as shown
def metrics(self) -> List[Dict]:
```

This method should return a Dictionary of metrics as described in the [custom metrics](../analytics/custom_metrics.md) docs.
This method should return a Dictionary of metrics as described in the [custom metrics](../analytics/analytics.md#custom-metrics) docs.

An illustrative example is shown below:

Expand Down Expand Up @@ -443,9 +443,53 @@ class Model:

### REST Metadata Endpoint
The python wrapper will automatically expose a `/metadata` endpoint to return metadata about the loaded model.
It is up to the developer to implement a `metadata` method in their class to provide an arbitrary `dict` back containing the model metadata.
It is up to the developer to implement a `metadata` method in their class to provide a `dict` back containing the model metadata.

Note: future work will most likely standardize `/metadata` endpoint and change behaviour of this method. See [this](https://github.com/SeldonIO/seldon-core/issues/1638) GitHub issue for details.
#### Example format:
```python
class Model:
...

def init_metadata(self):

meta = {
"name": "model-name",
"versions": ["model-version"],
"platform": "platform-name",
"inputs": [{"name": "input", "datatype": "BYTES", "shape": [1]}],
"outputs": [{"name": "output", "datatype": "BYTES", "shape": [1]}],
}

return meta
```

#### Validation
Output of developer-defined `metadata` method will be validated to follow the [kfserving dataplane proposal](https://github.com/kubeflow/kfserving/blob/master/docs/predict-api/v2/required_api.md#model-metadata) protocol, see [this](https://github.com/SeldonIO/seldon-core/issues/1638) GitHub issue for details:
```
$metadata_model_response =
{
"name" : $string,
"versions" : [ $string, ... ] #optional,
"platform" : $string,
"inputs" : [ $metadata_tensor, ... ],
"outputs" : [ $metadata_tensor, ... ]
}
```
with
```
$metadata_tensor =
{
"name" : $string,
"datatype" : $string,
"shape" : [ $number, ... ]
}
```

If validation fails server will reply with `500` response `MICROSERVICE_BAD_METADATA` when requested for `metadata`.

#### Examples:
- [Basic Examples for Model with Metadata](../examples/metadata.html)
- [SKLearn Server example with MinIO](../examples/minio-sklearn.html)



Expand Down
9 changes: 9 additions & 0 deletions examples/dvc/.dvc/.gitignore
@@ -0,0 +1,9 @@
/config.local
/updater
/lock
/updater.lock
/tmp
/state-journal
/state-wal
/state
/cache
Empty file added examples/dvc/.dvc/config
Empty file.
2 changes: 2 additions & 0 deletions examples/dvc/.gitignore
@@ -0,0 +1,2 @@
.env
/model.joblib
9 changes: 9 additions & 0 deletions examples/dvc/Makefile
@@ -0,0 +1,9 @@
env:
python3 -m venv .env
./.env/bin/pip install --upgrade pip setuptools
./.env/bin/pip install -r requirements.txt

train:
.env/bin/python train_iris.py

model: env train
19 changes: 19 additions & 0 deletions examples/dvc/deploy.yaml
@@ -0,0 +1,19 @@

apiVersion: machinelearning.seldon.io/v1
kind: SeldonDeployment
metadata:
name: minio-dvc-sklearn
spec:
annotations:
seldon.io/executor: "true"
name: iris
predictors:
- componentSpecs:
graph:
children: []
implementation: SKLEARN_SERVER
modelUri: s3://dvc-iris
envSecretRefName: seldon-init-container-secret
name: classifier
name: default
replicas: 1
12 changes: 12 additions & 0 deletions examples/dvc/metadata.yaml
@@ -0,0 +1,12 @@

name: iris
versions: [iris/dvc:8104914e6936da9864603b9bc4be2114]
platform: sklearn
inputs:
- datatype: BYTES
name: input
shape: [ 1, 4 ]
outputs:
- datatype: BYTES
name: output
shape: [ 3 ]
15 changes: 15 additions & 0 deletions examples/dvc/model.dvc
@@ -0,0 +1,15 @@
md5: 99124ac10a601ab1d9f07f9c392b5d89
cmd: make model
deps:
- md5: 65fd61883993b68d1937bdc36c59b20c
path: Makefile
- md5: 7e8ce9f96492fee21db6a59c2b52f34d
path: requirements.txt
- md5: 49c19c3ea9deb642066c0a457181cfbf
path: train_iris.py
outs:
- md5: 8104914e6936da9864603b9bc4be2114
path: model.joblib
cache: true
metric: false
persist: false
4 changes: 4 additions & 0 deletions examples/dvc/requirements.txt
@@ -0,0 +1,4 @@
scikit-learn == 0.20.3
numpy >= 1.8.2
joblib >= 0.13.0

11 changes: 11 additions & 0 deletions examples/dvc/secret.yaml
@@ -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"