カスタム モデルサービング エンドポイントの作成
プレビュー
Mosaic AI Model Serving は パブリック プレビュー 段階にあり、 us-east1
と us-central1
でサポートされています。
この記事では、 モデルサービングを使用してDatabricksカスタムモデル を提供するモデルサービングエンドポイントを作成する方法について説明します 。
モデルサービングには、サービングエンドポイントの作成に関する次のオプションがあります。
- サービングUI
- REST API
- MLflow デプロイ SDK
生成AI モデルを提供するエンドポイントの作成については、「 エンドポイントを提供する基盤モデルの作成」を参照してください。
必要条件
- ワークスペースは 、サポートされているリージョンにある必要があります。
- カスタムライブラリまたはプライベートミラーサーバーのライブラリをモデルで使用する場合は、モデルエンドポイントを作成する前に、 モデルサービングでカスタム Python ライブラリを使用する を参照してください。
- MLflow デプロイ SDK を使用してエンドポイントを作成するには、MLflow デプロイ クライアントをインストールする必要があります。 インストールするには、次のコマンドを実行します。
import mlflow.deployments
client = mlflow.deployments.get_deploy_client("databricks")
アクセス制御
エンドポイント管理のためのモデルサービングエンドポイントのアクセスコントロールオプションを理解するには、「 モデルサービングエンドポイントのアクセス許可を管理する」を参照してください。
また、モデルサービングの認証情報を保存するために環境変数を追加することもできます。 モデルサービングエンドポイントからリソースへのアクセスを設定するを参照してください。
エンドポイントを作成する
- Serving UI
- REST API
- MLflow Deployments SDK
You can create an endpoint for model serving with the Serving UI.
-
Click Serving in the sidebar to display the Serving UI.
-
Click Create serving endpoint.
For models registered in Unity Catalog:
-
In the Name field provide a name for your endpoint.
-
In the Served entities section, click into the Entity field to open the Select served entity form.
- Select the type of model you want to serve. The form dynamically updates based on your selection.
- Select which model and model version you want to serve.
- Select the percentage of traffic to route to your served model.
- Select what size CPU or GPU compute to use. Only the GPU_MEDIUM compute is supported for GPU.
- Under Compute Scale-out, select the size of the compute scale out that corresponds with the number of requests this served model can process at the same time. This number should be roughly equal to QPS x model run time. Available sizes are Small for 0-4 requests, Medium 8-16 requests, and Large for 16-64 requests.
- Specify if the endpoint should scale to zero when not in use.
-
Click Create. The Serving endpoints page appears with Serving endpoint state shown as Not Ready.
You can create endpoints using the REST API. See POST /api/2.0/serving-endpoints for endpoint configuration parameters.
The following example creates an endpoint that serves the first version of the ads1
model that is registered in the Unity Catalog model registry. To specify a model from Unity Catalog, provide the full model name including parent catalog and schema such as, catalog.schema.example-model
.
POST /api/2.0/serving-endpoints
{
"name": "uc-model-endpoint",
"config":
{
"served_entities": [
{
"name": "ads-entity"
"entity_name": "catalog.schema.my-ads-model",
"entity_version": "3",
"workload_size": "Small",
"scale_to_zero_enabled": true
},
{
"entity_name": "catalog.schema.my-ads-model",
"entity_version": "4",
"workload_size": "Small",
"scale_to_zero_enabled": true
}
],
"traffic_config":
{
"routes": [
{
"served_model_name": "my-ads-model-3",
"traffic_percentage": 100
},
{
"served_model_name": "my-ads-model-4",
"traffic_percentage": 20
}
]
}
},
"tags": [
{
"key": "team",
"value": "data science"
}
]
}
The following is an example response. The endpoint’s config_update
state is NOT_UPDATING
and the served model is in a READY
state.
{
"name": "uc-model-endpoint",
"creator": "user@email.com",
"creation_timestamp": 1700089637000,
"last_updated_timestamp": 1700089760000,
"state": {
"ready": "READY",
"config_update": "NOT_UPDATING"
},
"config": {
"served_entities": [
{
"name": "ads-entity",
"entity_name": "catalog.schema.my-ads-model-3",
"entity_version": "3",
"workload_size": "Small",
"scale_to_zero_enabled": true,
"workload_type": "CPU",
"state": {
"deployment": "DEPLOYMENT_READY",
"deployment_state_message": ""
},
"creator": "user@email.com",
"creation_timestamp": 1700089760000
}
],
"traffic_config": {
"routes": [
{
"served_model_name": "catalog.schema.my-ads-model-3",
"traffic_percentage": 100
}
]
},
"config_version": 1
},
"tags": [
{
"key": "team",
"value": "data science"
}
],
"id": "e3bd3e471d6045d6b75f384279e4b6ab",
"permission_level": "CAN_MANAGE",
"route_optimized": false
}
MLflow Deployments provides an API for create, update and deletion tasks. The APIs for these tasks accept the same parameters as the REST API for serving endpoints. See POST /api/2.0/serving-endpoints for endpoint configuration parameters.
The following example creates an endpoint that serves the third version of the my-ads-model
model that is registered in the Unity Catalog model registry. You must provide the full model name including parent catalog and schema such as, catalog.schema.example-model
.
from mlflow.deployments import get_deploy_client
client = get_deploy_client("databricks")
endpoint = client.create_endpoint(
name="unity-catalog-model-endpoint",
config={
"served_entities": [
{
"name": "ads-entity"
"entity_name": "catalog.schema.my-ads-model",
"entity_version": "3",
"workload_size": "Small",
"scale_to_zero_enabled": true
}
],
"traffic_config": {
"routes": [
{
"served_model_name": "my-ads-model-3",
"traffic_percentage": 100
}
]
}
}
)
また、次のこともできます。
GPU ワークロードの種類
GPU デプロイメントは、次のパッケージバージョンと互換性があります。
- PyTorch 1.13.0 - 2.0.1
- TensorFlow 2.5.0 - 2.13.0
- MLflow 2.4.0 以降
GPU を使用してモデルをデプロイするには、エンドポイントの作成時にエンドポイント設定に workload_type
フィールドを含めるか、API を使用してエンドポイント設定の更新として含めます。 Serving UI を使用して GPU ワークロードのエンドポイントを設定するには、 コンピュート Type ドロップダウンから目的の GPU タイプを選択します。
{
"served_entities": [{
"entity_name": "catalog.schema.ads1",
"entity_version": "2",
"workload_type": "GPU_MEDIUM",
"workload_size": "Small",
"scale_to_zero_enabled": false,
}]
}
次の表は、サポートされている使用可能な GPU ワークロードの種類をまとめたものです。
GPU ワークロードの種類 | GPU インスタンス | GPUメモリ |
---|---|---|
| L4 |
カスタムモデルのエンドポイントを変更する
カスタムモデルエンドポイントを有効にした後、必要に応じてコンピュート設定を更新できます。 この構成は、モデルに追加のリソースが必要な場合に特に役立ちます。 ワークロードのサイズとコンピュートの設定は、モデルを提供するためにどのリソースが割り当てられるかにおいて重要な役割を果たします。
新しい設定の準備が整うまで、古い設定は予測トラフィックを提供し続けます。 更新が進行中の間は、別の更新を行うことはできません。 ただし、進行中の更新は Serving UI からキャンセルできます。
- Serving UI
- REST API
- MLflow Deployments SDK
After you enable a model endpoint, select Edit endpoint to modify the compute configuration of your endpoint.
You can do the following:
- Choose from a few workload sizes, and autoscaling is automatically configured within the workload size.
- Specify if your endpoint should scale down to zero when not in use.
- Modify the percent of traffic to route to your served model.
You can cancel an in progress configuration update by selecting Cancel update on the top right of the endpoint’s details page. This functionality is only available in the Serving UI.
The following is an endpoint configuration update example using the REST API. See PUT /api/2.0/serving-endpoints/{name}/config.
PUT /api/2.0/serving-endpoints/{name}/config
{
"name": "unity-catalog-model-endpoint",
"config":
{
"served_entities": [
{
"entity_name": "catalog.schema.my-ads-model",
"entity_version": "5",
"workload_size": "Small",
"scale_to_zero_enabled": true
}
],
"traffic_config":
{
"routes": [
{
"served_model_name": "my-ads-model-5",
"traffic_percentage": 100
}
]
}
}
}
The MLflow Deployments SDK uses the same parameters as the REST API, see PUT /api/2.0/serving-endpoints/{name}/config for request and response schema details.
The following code sample uses a model from the Unity Catalog model registry:
import mlflow
from mlflow.deployments import get_deploy_client
mlflow.set_registry_uri("databricks-uc")
client = get_deploy_client("databricks")
endpoint = client.create_endpoint(
name=f"{endpointname}",
config={
"served_entities": [
{
"entity_name": f"{catalog}.{schema}.{model_name}",
"entity_version": "1",
"workload_size": "Small",
"scale_to_zero_enabled": True
}
],
"traffic_config": {
"routes": [
{
"served_model_name": f"{model_name}-1",
"traffic_percentage": 100
}
]
}
}
)
モデルエンドポイントのスコアリング
モデルをスコアリングするには、モデルサービング エンドポイントに要求を送信します。
- 「カスタムモデルのクエリ サービング エンドポイント」を参照してください。
- 「クエリ基盤モデル」を参照してください。
追加のリソース
- モデルサービングエンドポイントを管理します。
- Mosaic AI Model Servingの外部モデル.
- Python を使用する場合は、 Databricks のリアルタイム サービング Python SDK を使用できます。
ノートブックの例
次のノートブックには、モデルサービングエンドポイントを使用して起動して実行するために使用できる、さまざまな登録済みモデル Databricks が含まれています。 その他の例については、「 チュートリアル: カスタム モデルのデプロイとクエリ」を参照してください。
モデルの例は、「 ノートブックのインポート」の指示に従ってワークスペースにインポートできます。 いずれかの例からモデルを選択して作成したら、 Unity Catalogで登録するモデルサービングの UI ワークフロー手順に従います。