Skip to content

Commit

Permalink
doc(model-registry): Added Model Registry CSI documentation to instal…
Browse files Browse the repository at this point in the history
…lation and getting started sections (#3922)

* feat(mr): added csi mr docs

Signed-off-by: Alessio Pragliola <[email protected]>

* chore(mr): bump model-registry/csi to 0.2.10

Signed-off-by: Alessio Pragliola <[email protected]>

* chore(mr): apply suggestions from code review

Co-authored-by: Matteo Mortari <[email protected]>
Signed-off-by: Alessio Pragliola <[email protected]>

---------

Signed-off-by: Alessio Pragliola <[email protected]>
Signed-off-by: Alessio Pragliola <[email protected]>
Co-authored-by: Matteo Mortari <[email protected]>
  • Loading branch information
Al-Pragliola and tarilabs authored Nov 11, 2024
1 parent 90f4b7e commit 42e0e45
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 20 deletions.
67 changes: 52 additions & 15 deletions content/en/docs/components/model-registry/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ To follow along the examples in this guide, you will need a Kubeflow installatio
To use Model Registry on a notebook you should first install the Python client:

```raw
!pip install --pre model-registry=="0.2.3a1"
!pip install model-registry=="0.2.10"
!pip install kserve=="0.13"
```

Note that depending on your environment there might be conflicting dependency versions for packages that depend on
Expand Down Expand Up @@ -58,15 +59,15 @@ You can use the `register_model` method to index a model's artifacts and its met

```python
rm = registry.register_model(
"mnist",
"https://github.com/tarilabs/demo20231212/raw/main/v1.nb20231206162408/mnist.onnx",
model_format_name="onnx",
"iris",
"gs://kfserving-examples/models/sklearn/1.0/model",
model_format_name="sklearn",
model_format_version="1",
version="v0.1",
description="lorem ipsum mnist",
version="v1",
description="Iris scikit-learn model",
metadata={
"accuracy": 3.14,
"license": "apache-2.0",
"license": "BSD 3-Clause License",
}
)
```
Expand All @@ -76,13 +77,13 @@ rm = registry.register_model(
Continuing on the previous example, you can use the following methods to retrieve the metadata associated with a given Model Artifact:

```python
model = registry.get_registered_model("mnist")
model = registry.get_registered_model("iris")
print("Registered Model:", model, "with ID", model.id)

version = registry.get_model_version("mnist", "v0.1")
version = registry.get_model_version("iris", "v1")
print("Model Version:", version, "with ID", version.id)

art = registry.get_model_artifact("mnist", "v0.1")
art = registry.get_model_artifact("iris", "v1")
print("Model Artifact:", art, "with ID", art.id)
```

Expand All @@ -92,9 +93,11 @@ These can be used to create a KServe inference endpoint.

Normally you would need to provide your deployment metadata manually resulting in an error-prone process, especially
when such data has to be gathered from several sources.
Using Model Registry ensures simplified access to accurate metadata, and enables you to automate deployment based on the Model Registry values, as also shown in the example below.
Using Model Registry ensures simplified access to accurate metadata, and enables you to automate deployment based on the Model Registry values, as also shown in the examples below.

Note: the provided example uses the Model Registry Python client and KServe Python SDK. You can analogously make use of the Model Registry REST APIs, and your own Add-on SDK as needed.
Note: the provided examples uses the Model Registry Python client and KServe Python SDK. You can analogously make use of the Model Registry REST APIs, and your own Add-on SDK as needed.

### Using Model Registry metadata

You can use the retrieved metadata from the previous step with the KServe Python SDK to create an inference endpoint, for example:

Expand All @@ -106,7 +109,7 @@ isvc = kserve.V1beta1InferenceService(
api_version=kserve.constants.KSERVE_GROUP + "/v1beta1",
kind=kserve.constants.KSERVE_KIND,
metadata=client.V1ObjectMeta(
name="mnist",
name="iris-model",
namespace=kserve.utils.get_default_target_namespace(),
labels={
"modelregistry/registered-model-id": model.id,
Expand All @@ -120,8 +123,6 @@ isvc = kserve.V1beta1InferenceService(
model_format=kserve.V1beta1ModelFormat(
name=art.model_format_name, version=art.model_format_version
),
runtime="kserve-ovms",
protocol_version="v2",
)
)
),
Expand All @@ -133,6 +134,42 @@ ks_client.create(isvc)
An inference endpoint is now created, using the artifact metadata retrieved from the Model Registry (previous step),
specifying the serving runtime to be used to serve the model, and references to the original entities in Model Registry.

### Using Model Registry Custom Storage Initializer

The Model Registry Custom Storage Initializer (CSI) is a custom implementation of the KServe Storage Initializer that allows you to use Model Registry metadata to download and deploy models (see [Installation instructions](installation.md)). You can create an InferenceService that references the model and version in the Model Registry:

```python
from kubernetes import client
import kserve

isvc = kserve.V1beta1InferenceService(
api_version=kserve.constants.KSERVE_GROUP + "/v1beta1",
kind=kserve.constants.KSERVE_KIND,
metadata=client.V1ObjectMeta(
name="iris-model",
namespace=kserve.utils.get_default_target_namespace(),
labels={
"modelregistry/registered-model-id": model.id,
"modelregistry/model-version-id": version.id,
},
),
spec=kserve.V1beta1InferenceServiceSpec(
predictor=kserve.V1beta1PredictorSpec(
model=kserve.V1beta1ModelSpec(
storage_uri="model-registry://iris/v1", # The protocol is model-registry://{modelName}/{modelVersion}
model_format=kserve.V1beta1ModelFormat(
name=art.model_format_name, version=art.model_format_version
),
)
)
),
)
ks_client = kserve.KServeClient()
ks_client.create(isvc)
```

The InferenceService is now created, the CSI retrieves the latest artifact data associated with the model version from the Model Registry, and then downloads the model from its URI.

## Next steps

- Get involved:
Expand Down
15 changes: 10 additions & 5 deletions content/en/docs/components/model-registry/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,27 @@ of Model Registry, you can install the Model Registry manifests directly from th

By default, the manifests deploy the Model Registry in the `kubeflow` namespace;
you must ensure the `kubeflow` namespace is available (for example: `kubectl create namespace kubeflow`)
or modify [the kustomization file](https://github.com/kubeflow/model-registry/blob/v0.2.3-alpha/manifests/kustomize/overlays/db/kustomization.yaml#L3) to your desired namespace.
or modify [the kustomization file](https://github.com/kubeflow/model-registry/blob/v0.2.10/manifests/kustomize/overlays/db/kustomization.yaml#L3) to your desired namespace.

See the list of available versions on the [GitHub releases](https://github.com/kubeflow/model-registry/releases) of the `kubeflow/model-registry` repository. To install a specific release of the Model Registry, modify the following commands with the desired `ref=<GIT_TAG>`.

Run the following command to install the `v0.2.3-alpha` release of Model Registry:
Run the following command to install the `v0.2.10` release of Model Registry:

```shell
kubectl apply -k "https://github.com/kubeflow/model-registry/manifests/kustomize/overlays/db?ref=v0.2.3-alpha"
kubectl apply -k "https://github.com/kubeflow/model-registry/manifests/kustomize/overlays/db?ref=v0.2.10"
```

If your Kubernetes cluster uses Istio, you MUST apply the Istio-compatibility manifests (e.g. when using a full Kubeflow Platform). However, these are NOT required for non-Istio clusters.

```shell
kubectl apply -k "https://github.com/kubeflow/model-registry/manifests/kustomize/options/istio?ref=v0.2.3-alpha"
kubectl apply -k "https://github.com/kubeflow/model-registry/manifests/kustomize/options/istio?ref=v0.2.10"
```

If you want Kserve to be able to support `model-registry://` URI formats, you must apply the cluster-scoped `CustomStorageContainer` CR.

```shell
kubectl apply -k "https://github.com/kubeflow/model-registry/manifests/kustomize/options/csi?ref=v0.2.10"
```

## Check Model Registry setup

Expand All @@ -60,7 +65,7 @@ kubectl wait --for=condition=available -n kubeflow deployment/model-registry-dep
kubectl logs -n kubeflow deployment/model-registry-deployment
```

Optionally, you can also manually forward the REST API container port of Model Registry and interact with the [REST API](https://editor.swagger.io/?url=https://raw.githubusercontent.com/kubeflow/model-registry/main/api/openapi/model-registry.yaml),
Optionally, you can also manually forward the REST API container port of Model Registry and interact with the [REST API](https://editor.swagger.io/?url=https://raw.githubusercontent.com/kubeflow/model-registry/v0.2.10/api/openapi/model-registry.yaml),
for example with:
```shell
kubectl port-forward svc/model-registry-service -n kubeflow 8081:8080
Expand Down

0 comments on commit 42e0e45

Please sign in to comment.