管理服務端點的模型
本文說明如何使用服務 UI 和 REST API 來管理服務端點的模型。 請參閱 在 REST API 參考中提供端點 。
若要建立服務端點的模型,請使用下列其中一項:
取得模型端點的狀態
在 [服務 UI] 中,您可以從端點詳細數據頁面頂端的 [服務端點狀態指標] 檢查端點的狀態。
您可以使用 REST API 或 MLflow 部署 SDK,以程式設計方式檢查端點的狀態和詳細數據
Rest API
GET /api/2.0/serving-endpoints/{name}
下列範例會取得端點的詳細數據,該端點提供模型登錄中註冊的第 ads1
一個模型版本。 若要從 Unity 目錄指定模型,請提供完整的模型名稱,包括父目錄和架構, catalog.schema.example-model
例如 。
在下列範例回應中 state.ready
,字段為 “READY”,這表示端點已準備好接收流量。 欄位 state.update_state
為 NOT_UPDATING
, pending_config
且不再傳回,因為更新已順利完成。
{
"name": "workspace-model-endpoint",
"creator": "customer@example.com",
"creation_timestamp": 1666829055000,
"last_updated_timestamp": 1666829055000,
"state": {
"ready": "READY",
"update_state": "NOT_UPDATING"
},
"config": {
"served_entities": [
{
"name": "ads1-1",
"entity_name": "ads1",
"entity_version": "1",
"workload_size": "Small",
"scale_to_zero_enabled": false,
"state": {
"deployment": "DEPLOYMENT_READY",
"deployment_state_message": ""
},
"creator": "customer@example.com",
"creation_timestamp": 1666829055000
}
],
"traffic_config": {
"routes": [
{
"served_model_name": "ads1-1",
"traffic_percentage": 100
}
]
},
"config_version": 1
},
"id": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"permission_level": "CAN_MANAGE"
}
Mlflow 部署 sdk
from mlflow.deployments import get_deploy_client
client = get_deploy_client("databricks")
endpoint = client.get_endpoint(endpoint="chat")
assert endpoint == {
"name": "chat",
"creator": "alice@company.com",
"creation_timestamp": 0,
"last_updated_timestamp": 0,
"state": {...},
"config": {...},
"tags": [...],
"id": "88fd3f75a0d24b0380ddc40484d7a31b",
}
刪除服務端點的模型
若要停用模型的服務,您可以刪除其提供的端點。
您可以從服務 UI 中的端點詳細資料頁面刪除端點。
- 按兩下 提要欄位上的 [服務 ]。
- 按兩下您要刪除的端點。
- 點擊頂端的 Kebab 功能表,然後選取 [ 刪除]。
或者,您可以使用 REST API 或 MLflow 部署 SDK,以程式設計方式刪除服務端點
Rest API
DELETE /api/2.0/serving-endpoints/{name}
Mlflow 部署 sdk
from mlflow.deployments import get_deploy_client
client = get_deploy_client("databricks")
client.delete_endpoint(endpoint="chat")
對服務端點的模型進行偵錯
若要對端點的任何問題進行偵錯,您可以擷取:
- 模型伺服器容器組建記錄
- 模型伺服器記錄
您也可以從 [記錄] 索引 標籤中的 [端點] UI 存取這些記錄 。
針對服務模型的組建記錄,您可以使用下列要求:
GET /api/2.0/serving-endpoints/{name}/served-models/{served-model-name}/build-logs
{
“config_version”: 1 // optional
}
針對服務模型的模型伺服器記錄,您可以使用下列要求:
GET /api/2.0/serving-endpoints/{name}/served-models/{served-model-name}/logs
{
“config_version”: 1 // optional
}
管理模型服務端點的許可權
您必須至少有服務端點的 CAN MANAGE 許可權,才能修改許可權。 如需許可權等級的詳細資訊,請參閱 提供端點 ACL。
取得服務端點的許可權清單。
databricks permissions get servingendpoints <endpoint-id>
將服務端點的 CAN QUERY 許可權授與使用者 jsmith@example.com
。
databricks permissions update servingendpoints <endpoint-id> --json '{
"access_control_list": [
{
"user_name": "jsmith@example.com",
"permission_level": "CAN_QUERY"
}
]
}'
您也可以使用 許可權 API 修改服務端點許可權。
取得提供端點架構的模型
服務端點查詢架構是使用 JSON 格式標準 OpenAPI 規格之服務端點的正式描述。 其中包含端點的相關信息,包括端點路徑、查詢端點的詳細數據,例如要求和回應本文格式,以及每個字段的數據類型。 此資訊有助於重現案例,或當您需要端點的相關信息,但不是原始端點建立者或擁有者時。
若要取得服務端點架構的模型,服務模型必須記錄模型簽章,而且端點必須處於 READY
狀態。
下列範例示範如何使用 REST API 以程式設計方式取得服務端點架構的模型。 如需提供端點架構的功能,請參閱 什麼是 Databricks 功能服務?。
API 所傳回的架構格式為遵循 OpenAPI 規格的 JSON 物件格式。
ACCESS_TOKEN="<endpoint-token>"
ENDPOINT_NAME="<endpoint name>"
curl "https://example.databricks.com/api/2.0/serving-endpoints/$ENDPOINT_NAME/openapi" -H "Authorization: Bearer $ACCESS_TOKEN" -H "Content-Type: application/json"
架構回應詳細數據
回應是 JSON 格式的 OpenAPI 規格,通常包括 、 info
servers
和 paths
等openapi
欄位。 因為架構回應是 JSON 物件,所以您可以使用一般程式設計語言剖析它,並使用第三方工具從規格產生用戶端程式代碼。
您也可以使用 Swagger 編輯器等第三方工具將 OpenAPI 規格可視化。
回應的主要欄位包括:
- 欄位
info.title
會顯示服務端點的名稱。 servers
欄位一律包含一個物件,通常是url
端點基底 URL 的欄位。paths
回應中的物件包含端點的所有支持路徑。 物件中的索引鍵是路徑 URL。 每個path
都可以支援多種輸入格式。 這些輸入會列在oneOf
欄位中。
以下是端點架構回應的範例:
{
"openapi": "3.1.0",
"info": {
"title": "example-endpoint",
"version": "2"
},
"servers": [{ "url": "https://example.databricks.com/serving-endpoints/example-endpoint"}],
"paths": {
"/served-models/vanilla_simple_model-2/invocations": {
"post": {
"requestBody": {
"content": {
"application/json": {
"schema": {
"oneOf": [
{
"type": "object",
"properties": {
"dataframe_split": {
"type": "object",
"properties": {
"columns": {
"description": "required fields: int_col",
"type": "array",
"items": {
"type": "string",
"enum": [
"int_col",
"float_col",
"string_col"
]
}
},
"data": {
"type": "array",
"items": {
"type": "array",
"prefixItems": [
{
"type": "integer",
"format": "int64"
},
{
"type": "number",
"format": "double"
},
{
"type": "string"
}
]
}
}
}
},
"params": {
"type": "object",
"properties": {
"sentiment": {
"type": "number",
"format": "double",
"default": "0.5"
}
}
}
},
"examples": [
{
"columns": [
"int_col",
"float_col",
"string_col"
],
"data": [
[
3,
10.4,
"abc"
],
[
2,
20.4,
"xyz"
]
]
}
]
},
{
"type": "object",
"properties": {
"dataframe_records": {
"type": "array",
"items": {
"required": [
"int_col",
"float_col",
"string_col"
],
"type": "object",
"properties": {
"int_col": {
"type": "integer",
"format": "int64"
},
"float_col": {
"type": "number",
"format": "double"
},
"string_col": {
"type": "string"
},
"becx_col": {
"type": "object",
"format": "unknown"
}
}
}
},
"params": {
"type": "object",
"properties": {
"sentiment": {
"type": "number",
"format": "double",
"default": "0.5"
}
}
}
}
}
]
}
}
}
},
"responses": {
"200": {
"description": "Successful operation",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"predictions": {
"type": "array",
"items": {
"type": "number",
"format": "double"
}
}
}
}
}
}
}
}
}
}
}
}