Criar um endpoint de modelo de serviço personalizado
Este artigo descreve como criar um endpoint servindo modelo que serve modelos personalizados usando Databricks servindo modelo.
O servindo modelo oferece as seguintes opções para servir a criação do endpoint:
- A interface de usuário de serviço
- API REST
- SDK de implantações do MLflow
Para criar um endpoint que atenda aos modelos generativos do AI, consulte Criar um endpoint que atenda ao modelo.
Requisitos
- Seu workspace deve estar em uma região compatível.
- Se o senhor usar uma biblioteca personalizada ou uma biblioteca de um servidor espelho privado com seu modelo, consulte Usar uma biblioteca personalizada Python com o modelo de serviço antes de criar o modelo endpoint.
- Para criar um endpoint usando o MLflow Deployments SDK, o senhor deve instalar o cliente MLflow Deployment. Para instalá-lo, execute:
import mlflow.deployments
client = mlflow.deployments.get_deploy_client("databricks")
Controle de acesso
Para entender as opções de controle de acesso para o endpoint servindo modelo para o endpoint gerenciamento,consulte gerenciar permissões em seu endpoint endpoint servindo modelo.
Você também pode:
- Adicionar um perfil de instância a um endpoint de serviço de modelo
- Configure o acesso aos recursos de endpoints de serviço de modelo
Criar um endpoint
- 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 the Workspace model registry or models 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 compute to use. You can use CPU or GPU computes for your workloads. See GPU workload types for more information on available GPU computes.
- 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.
- Under Advanced configuration, you can:
- Add an instance profile to connect to AWS resources from your endpoint.
- Add environment variables to connect to resources from your endpoint or log your feature lookup DataFrame to the endpoint's inference table. Logging the feature lookup DataFrame requires MLflow 2.14.0 or above.
-
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
}
]
}
}
)
Você também pode:
- Configure seu endpoint para atender a vários modelos.
- Configure seu endpoint para otimização de rota.
- Ative as tabelas de inferência para capturar automaticamente as solicitações de entrada e as respostas de saída para seu endpoint de modelo de serviço.
- Se as tabelas de inferência estiverem ativadas no seu endpoint, o senhor poderá log a pesquisa de recurso DataFrame para a tabela de inferência.
Tipos de carga de trabalho de GPU
A implementação da GPU é compatível com as seguintes versões do pacote:
- PyTorch 1.13.0 - 2.0.1
- TensorFlow 2.5.0 - 2.13.0
- MLflow 2.4.0 e acima
Para implantar seus modelos usando GPUs, inclua o campo workload_type
em sua configuração endpoint durante a criação doendpoint ou como uma atualização da configuração endpoint usando o API. Para configurar seu endpoint para cargas de trabalho de GPU com a UI de serviço, selecione o tipo de GPU desejado no tipo de computação dropdown.
{
"served_entities": [{
"entity_name": "catalog.schema.ads1",
"entity_version": "2",
"workload_type": "GPU_MEDIUM",
"workload_size": "Small",
"scale_to_zero_enabled": false,
}]
}
A tabela a seguir resume os tipos de carga de trabalho de GPU disponíveis suportados.
Tipo de carga de trabalho da GPU | Instância de GPU | Memória GPU |
---|---|---|
| 1xT4 | 16GB |
| 1 x A10g | 24 GB |
| 4xA10G | 96 GB |
| 8xA10g | 192 GB |
Modificar um endpoint de modelo personalizado
Depois de ativar um modelo personalizado endpoint, o senhor pode atualizar a configuração do compute conforme desejar. Essa configuração é particularmente útil se o senhor precisar de recurso adicional para o seu modelo. O tamanho da carga de trabalho e a compute configuração key do site desempenham um papel importante em quais recursos são alocados para atender ao seu modelo.
Até que a nova configuração esteja pronta, a configuração antiga continua fornecendo tráfego de previsão. Enquanto houver uma atualização em andamento, outra atualização não poderá ser feita. No entanto, você pode cancelar uma atualização em andamento na 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
}
]
}
}
)
Pontuação de um modelo endpoint
Para pontuar seu modelo, envie solicitações para o servindo modelo endpoint.
- Consulte Ponto de extremidade de serviço de consulta para modelos personalizados.
- Consulte Modelos básicos de consulta.
Recurso adicional
- gerenciar servindo o modelo endpoint.
- Modelos externos no Mosaic AI Model Serving.
- Se preferir usar Python, o senhor pode usar o Python SDK de serviço em tempo real da Databricks.
Notebook exemplos
O Notebook a seguir inclui diferentes Databricks modelos registrados que o senhor pode usar para começar a trabalhar com o endpoint modelo servindo. Para obter exemplos adicionais, consulte o tutorial: implantar e consultar um modelo personalizado.
Os exemplos de modelos podem ser importados para o site workspace seguindo as instruções em Import a Notebook. Depois de escolher e criar um modelo a partir de um dos exemplos, registre-o em Unity Catalog e siga as etapas do fluxo de trabalho da interface do usuário para servir o modelo.