Skip to content

Commit

Permalink
code review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
RafalSkolasinski committed Jun 11, 2020
1 parent 6acdcaa commit f10d22c
Show file tree
Hide file tree
Showing 14 changed files with 230 additions and 185 deletions.
247 changes: 146 additions & 101 deletions doc/source/reference/apis/metadata.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
![metadata](./metadata.svg)



## Incubating feature note
The model metadata feature has currently "incubating" status.
This means that we are currently exploring the best possible interface and functionality for this feature.
Expand All @@ -15,7 +16,8 @@ Incubating update 1:
- definition through environmental variables now accepts both `yaml` and `json` input


## Examples:

## Examples
- [Basic Examples for Model with Metadata](../../examples/metadata.html)
- [SKLearn Server example with MinIO](../../examples/minio-sklearn.html)
- [Deployment Level Metadata](../../examples/graph-metadata.html).
Expand All @@ -24,16 +26,153 @@ Incubating update 1:
- [Deploying models trained with DVC](../../examples/dvc.html)



## Model Metadata (incubating)

With Seldon you can easily add metadata to your models.

### Prepackaged model servers

To add metadata to your prepackaged model servers simply add a file named `metadata.yaml`
to the S3 bucket with your model:
```YAML
name: my-model
versions: [my-model/v1]
platform: platform-name
inputs:
- datatype: BYTES
name: input
shape: [ 1, 4 ]
outputs:
- datatype: BYTES
name: output
shape: [ 3 ]
```
See [SKLearn Server example with MinIO](../../examples/minio-sklearn.html) for more details.
### Python Language Wrapper
You can add model metadata you your custom Python model by implementing `init_metadata` method:

```python
class Model:
...
def init_metadata(self):
meta = {
"name": "my-model",
"versions": ["my-model/v1"],
"platform": "platform-name",
"inputs": [{"name": "input", "datatype": "BYTES", "shape": [1, 4]}],
"outputs": [{"name": "output", "datatype": "BYTES", "shape": [1]}],
}
return meta
```

See [Python wrapper](../../python/python_component.html#incubating-features) documentation for more details and
notebook [Basic Examples for Model with Metadata](../../examples/metadata.html).


### Overwrite via environmental variable

You can also always specify `MODEL_METADATA` environmental variable which takes ultimate priority.

```YAML
apiVersion: machinelearning.seldon.io/v1
kind: SeldonDeployment
metadata:
name: seldon-model
spec:
name: test-deployment
predictors:
- componentSpecs:
- spec:
containers:
- name: my-model
image: ...
env:
- name: MODEL_METADATA
value: |
---
name: my-model-name
versions: [ my-model-version ]
platform: seldon
inputs:
- datatype: BYTES
name: input
shape: [ 1, 4 ]
outputs:
- datatype: BYTES
name: output
shape: [ 3 ]
graph:
name: my-model
...
name: example
replicas: 1
```

## Deployment Metadata (incubating)
Model metadata allow you to specify metadata for each of the components (nodes) in your graph.
New orchestrator engine will probe all nodes for their metadata and derive global `inputs` and `outputs` of your graph.
It will then expose them together with all nodes' metadata at a single endpoint `/api/v1.0/metadata/` of your deployment.

![graph-metadata](./graph-metadata.svg)

Example response:
```json
{
"name": "example",
"models": {
"model-1": {
"name": "Model 1",
"platform": "platform-name",
"versions": ["model-version"],
"inputs": [{"datatype": "BYTES", "name": "input", "shape": [1, 5]}],
"outputs": [{"datatype": "BYTES", "name": "output", "shape": [1, 3]}]
},
"model-2": {
"name": "Model 2",
"platform": "platform-name",
"versions": ["model-version"],
"inputs": [{"datatype": "BYTES", "name": "input", "shape": [1, 3]}],
"outputs": [{"datatype": "BYTES", "name": "output", "shape": [3]}]
}
},
"graphinputs": [{"datatype": "BYTES", "name": "input", "shape": [1, 5]}],
"graphoutputs": [{"datatype": "BYTES", "name": "output", "shape": [3]}]
}
```

See example [notebook](../../examples/graph-metadata.html) for more details.



## Metadata endpoint

Model metadata can be obtained through GET request at `/api/v1.0/metadata/{MODEL_NAME}` endpoint of your deployment.

Example response:
```json
{
"name": "my-model",
"versions": ["my-model/v1"],
"platform": "platform-name",
"inputs": [{"datatype": "BYTES", "name": "input", "shape": [1, 5]}],
"outputs": [{"datatype": "BYTES", "name": "output", "shape": [1, 3]}],
}
```


## V1/V2 format reference

You can add metadata using one of two formats:
- `v1` format that closely correlate to the current structure of `SeldonMessage`
- `v2` format that is future-proof and fully compatible with `kfserving` dataplane proposal
- `v1` format that closely correlates to the current structure of `SeldonMessage`
- `v2` format that is future-proof and fully compatible with [kfserving dataplane proposal](https://github.com/kubeflow/kfserving/blob/master/docs/predict-api/v2/required_api.md#model-metadata) dataplane proposal

As you will see in following sections difference is minimal and mostly relates to the input/output format.


### V1 DataPlane

In order to use `v1` metadata format you need to specify `apiVersion: v1`.
Expand All @@ -43,7 +182,7 @@ In order to use `v1` metadata format you need to specify `apiVersion: v1`.
apiVersion: v1
name: my-model-name
versions: [ my-model-version-01 ]
platform: seldon-custom
platform: seldon
inputs:
datatype: array
shape: [ 2, 2 ]
Expand All @@ -65,7 +204,7 @@ and
apiVersion: v1
name: my-model-name
versions: [ my-model-version-01 ]
platform: seldon-custom
platform: seldon
inputs:
datatype: jsonData
schema:
Expand Down Expand Up @@ -94,13 +233,12 @@ The `schema` field is optional and can leaves user total freedom over its struct

Note: as you can see you can mix inputs and outputs of different types!


#### strData input/output
```YAML
apiVersion: v1
name: my-model-name
versions: [ my-model-version-01 ]
platform: seldon-custom
platform: seldon
inputs:
datatype: strData
outputs:
Expand All @@ -114,7 +252,6 @@ Example model input:
```



### V2 DataPlane
You can easily define metadata for your models that is compatible with [kfserving dataplane proposal](https://github.com/kubeflow/kfserving/blob/master/docs/predict-api/v2/required_api.md#model-metadata) specification.
```
Expand All @@ -138,95 +275,3 @@ $metadata_tensor =
```
Note: this the default format so you do not need to specify `apiVersion`.

### Metadata endpoint

Model metadata can be obtained through GET request at `/api/v1.0/metadata/{MODEL_NAME}` endpoint of your deployment.

Example response:
```json
{
"name": "my-model",
"versions": ["my-model/v1"],
"platform": "platform-name",
"inputs": [{"datatype": "BYTES", "name": "input", "shape": [1, 5]}],
"outputs": [{"datatype": "BYTES", "name": "output", "shape": [1, 3]}],
}
```

### Prepackaged model servers

To add metadata to your prepackaged model servers simply add a file named `metadata.yaml`
to the S3 bucket with your model:
```YAML
name: my-model
versions: [my-model/v1]
platform: platform-name
inputs:
- datatype: BYTES
name: input
shape: [ 1, 4 ]
outputs:
- datatype: BYTES
name: output
shape: [ 3 ]
```
See [SKLearn Server example with MinIO](../../examples/minio-sklearn.html) for more details.
### Python Language Wrapper
You can add model metadata you your custom Python model by implementing `init_metadata` method:

```python
class Model:
...
def init_metadata(self):
meta = {
"name": "my-model",
"versions": ["my-model/v1"],
"platform": "platform-name",
"inputs": [{"name": "input", "datatype": "BYTES", "shape": [1, 4]}],
"outputs": [{"name": "output", "datatype": "BYTES", "shape": [1]}],
}
return meta
```

See [Python wrapper](../../python/python_component.html#incubating-features) documentation for more details and
notebook [Basic Examples for Model with Metadata](../../examples/metadata.html).


## Deployment Metadata (incubating)
Model metadata allow you to specify metadata for each of the components (nodes) in your graph.
New orchestrator engine will probe all nodes for their metadata and derive global `inputs` and `outputs` of your graph.
It will then expose them together with all nodes' metadata at a single endpoint `/api/v1.0/metadata/` of your deployment.

![graph-metadata](./graph-metadata.svg)

Example response:
```json
{
"name": "example",
"models": {
"model-1": {
"name": "Model 1",
"platform": "platform-name",
"versions": ["model-version"],
"inputs": [{"datatype": "BYTES", "name": "input", "shape": [1, 5]}],
"outputs": [{"datatype": "BYTES", "name": "output", "shape": [1, 3]}]
},
"model-2": {
"name": "Model 2",
"platform": "platform-name",
"versions": ["model-version"],
"inputs": [{"datatype": "BYTES", "name": "input", "shape": [1, 3]}],
"outputs": [{"datatype": "BYTES", "name": "output", "shape": [3]}]
}
},
"graphinputs": [{"datatype": "BYTES", "name": "input", "shape": [1, 5]}],
"graphoutputs": [{"datatype": "BYTES", "name": "output", "shape": [3]}]
}
```

See example [notebook](../../examples/graph-metadata.html) for more details.
8 changes: 4 additions & 4 deletions examples/models/metadata/graph-metadata/combiner.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec:
value: |
{"name": "node-combiner",
"versions": ["generic-node/v0.2"],
"platform": "seldon-custom",
"platform": "seldon",
"inputs": [
{"name": "input-1", "datatype": "BYTES", "shape": [1, 20]},
{"name": "input-2", "datatype": "BYTES", "shape": [1, 30]}
Expand All @@ -29,7 +29,7 @@ spec:
value: |
{"name": "node-one",
"versions": ["generic-node/v0.2"],
"platform": "seldon-custom",
"platform": "seldon",
"inputs": [{"name": "input", "datatype": "BYTES", "shape": [1, 10]}],
"outputs": [{"name": "output", "datatype": "BYTES", "shape": [1, 20]}]}
- image: seldonio/metadata-generic-node:0.2
Expand All @@ -39,7 +39,7 @@ spec:
value: |
{"name": "node-two",
"versions": ["generic-node/v0.2"],
"platform": "seldon-custom",
"platform": "seldon",
"inputs": [{"name": "input", "datatype": "BYTES", "shape": [1, 10]}],
"outputs": [{"name": "output", "datatype": "BYTES", "shape": [1, 30]}]}
graph:
Expand All @@ -53,4 +53,4 @@ spec:
type: MODEL
children: []
name: example
replicas: 1
replicas: 1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec:
value: |
{"name": "node-input-transformer",
"versions": ["generic-node/v0.2"],
"platform": "seldon-custom",
"platform": "seldon",
"inputs": [{"name": "input", "datatype": "BYTES", "shape": [1, 10]}],
"outputs": [{"name": "output", "datatype": "BYTES", "shape": [1, 20]}]}
- image: seldonio/metadata-generic-node:0.2
Expand All @@ -26,7 +26,7 @@ spec:
value: |
{"name": "node",
"versions": ["generic-node/v0.2"],
"platform": "seldon-custom",
"platform": "seldon",
"inputs": [{"name": "input", "datatype": "BYTES", "shape": [1, 20]}],
"outputs": [{"name": "output", "datatype": "BYTES", "shape": [1]}]}
graph:
Expand All @@ -37,4 +37,4 @@ spec:
type: MODEL
children: []
name: example
replicas: 1
replicas: 1
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec:
value: |
{"name": "node-output-transformer",
"versions": ["generic-node/v0.2"],
"platform": "seldon-custom",
"platform": "seldon",
"inputs": [{"name": "input", "datatype": "BYTES", "shape": [1, 20]}],
"outputs": [{"name": "output", "datatype": "BYTES", "shape": [1]}]}
- image: seldonio/metadata-generic-node:0.2
Expand All @@ -26,7 +26,7 @@ spec:
value: |
{"name": "node",
"versions": ["generic-node/v0.2"],
"platform": "seldon-custom",
"platform": "seldon",
"inputs": [{"name": "input", "datatype": "BYTES", "shape": [1, 10]}],
"outputs": [{"name": "output", "datatype": "BYTES", "shape": [1, 20]}]}
graph:
Expand All @@ -37,4 +37,4 @@ spec:
type: MODEL
children: []
name: example
replicas: 1
replicas: 1
Loading

0 comments on commit f10d22c

Please sign in to comment.