CLI (v2) 部署模板 YAML 架构

适用于:Azure CLI ml 扩展 v2(当前)

源 JSON 架构可在 https://azuremlschemas.azureedge.net/latest/deploymentTemplate.schema.json 中找到。

注释

本文档中详细介绍的 YAML 语法基于最新版本的 ML CLI v2 扩展的 JSON 架构。 此语法必定仅适用于最新版本的 ML CLI v2 扩展。 可以在 https://azuremlschemasprod.azureedge.net/ 上查找早期扩展版本的架构。

YAML 语法

Key 类型 Description 允许的值 默认值
$schema 字符串 YAML 架构。 如果使用 Azure 机器学习 VS Code 扩展来创作 YAML 文件,则可通过在文件顶部包含 $schema 来调用架构和资源完成操作。
name 字符串 必填。 部署模板的名称。
version 字符串或整数 部署模板的版本。
description 字符串 部署模板的说明。
display_name 字符串 部署模板的显示名称。 UI 图面(如 Foundry 门户)用于在用户选择部署模板时向使用者显示友好标签。
tags 对象 部署模板的标记字典。
type 字符串 部署模板的类型。
deployment_template_type 字符串 必填。 部署模板类型。 “Managed”是唯一当前允许的值。
environment 字符串 必填。 用于部署模板的环境。 此值必须是对注册表中现有版本控制环境的引用。 使用 azureml://registries/<registry-name>/environments/<environment-name>/versions/<version> 语法。

注意: 部署模板不支持工作区范围环境(使用 azureml:<name>:<version> 语法)和内联环境定义。
environment_variables 对象 要为部署设置的环境变量键值对的字典。 可以从评分脚本访问这些环境变量。
instance_count 整数 必填。 用于部署的实例数。 根据期望的工作负载指定值。
default_instance_type 字符串 必填。 使用此模板进行部署时要使用的默认实例类型。
allowed_instance_types 字符串列表 使用者在部署使用此模板的模型时允许设置的实例类型。 将实例类型指定为字符串列表。
model_mount_path 字符串 在容器中装载模型的路径。
scoring_path 字符串 必填。 评分终结点的路径。
scoring_port 整数 必填。 评分终结点的端口。
liveness_probe 对象 运行情况探测设置,用于定期监控容器的运行状况。 请参阅 ProbeSettings 以了解可配置属性集。
readiness_probe 对象 用于验证容器是否已准备好为流量提供服务的就绪情况探测设置。 请参阅 ProbeSettings 以了解可配置属性集。
request_settings 对象 请求部署设置。 请参阅 RequestSettings 以了解可配置属性集。

ProbeSettings

Key 类型 Description 默认值
failure_threshold 整数 当探测失败时,系统会在放弃之前尝试 failure_threshold 时间。 在运行情况探测的情况下放弃意味着容器会重启。 对于就绪情况探测,容器标记为“未读”。 最小值为 1 30
initial_delay 整数 容器启动后且在探测启动前的秒数。 最小值为 1 10
method 字符串 用于探测的 HTTP 方法。
path 字符串 探测的路径。
period 整数 执行探测的频率(以秒为单位)。 10
port 整数 要探测的端口。
scheme 字符串 用于探测的方案(例如 HTTP 或 HTTPS)。
success_threshold 整数 失败后,探测被视为成功的最小连续成功次数。 最小值为 1 1
timeout 整数 探测超时后的秒数。最小值为 1 2

请求设置

Key 类型 Description 默认值
request_timeout_ms 整数 请求超时(以毫秒为单位)。 5000
max_concurrent_requests_per_instance 整数 部署允许的每个实例的最大并发请求数。 1

注解

部署模板提供用于部署模型的可重用配置。 它们定义可在创建部署时应用的环境、基础结构设置和探测配置。

例子

下面显示了示例。

YAML:基本

$schema: https://azuremlschemas.azureedge.net/latest/deploymentTemplate.schema.json
name: my-deployment-template
version: 1
description: Basic deployment template example
deployment_template_type: Managed
environment: azureml://registries/my-registry/environments/my-environment/versions/1
instance_count: 1
default_instance_type: Standard_DS3_v2
scoring_path: /score
scoring_port: 5001

YAML:具有环境变量和探测

$schema: https://azuremlschemas.azureedge.net/latest/deploymentTemplate.schema.json
name: my-deployment-template
version: 1
description: Deployment template with environment variables and health probes
display_name: My deployment template
deployment_template_type: Managed
environment: azureml://registries/azureml/environments/minimal-ubuntu20.04-py38-cpu-inference/versions/latest
environment_variables:
  MODEL_PATH: /var/azureml-app/model
  SCORING_TIMEOUT: "60"
instance_count: 3
default_instance_type: Standard_DS3_v2
scoring_path: /score
scoring_port: 8080
liveness_probe:
  initial_delay: 30
  period: 10
  timeout: 2
  success_threshold: 1
  failure_threshold: 3
readiness_probe:
  initial_delay: 10
  period: 5
  timeout: 2
  success_threshold: 1
  failure_threshold: 3
request_settings:
  request_timeout_ms: 10000
  max_concurrent_requests_per_instance: 2

YAML:使用允许的实例类型

$schema: https://azuremlschemas.azureedge.net/latest/deploymentTemplate.schema.json
name: my-deployment-template-restricted
version: 1
description: Deployment template with instance type restrictions
deployment_template_type: Managed
environment: azureml://registries/my-registry/environments/my-environment/versions/1
instance_count: 1
default_instance_type: Standard_DS3_v2
allowed_instance_types:
  - Standard_DS3_v2
  - Standard_DS4_v2
scoring_path: /score
scoring_port: 5001

YAML:具有允许的实例类型(列表)

$schema: https://azuremlschemas.azureedge.net/latest/deploymentTemplate.schema.json
name: my-deployment-template-multi
version: 1
description: Deployment template that allows multiple instance types
deployment_template_type: Managed
environment: azureml://registries/my-registry/environments/my-environment/versions/1
instance_count: 1
default_instance_type: Standard_DS3_v2
allowed_instance_types:
  - Standard_DS3_v2
  - Standard_DS4_v2
  - Standard_DS5_v2
scoring_path: /score
scoring_port: 5001

YAML:具有模型装载路径

$schema: https://azuremlschemas.azureedge.net/latest/deploymentTemplate.schema.json
name: my-deployment-template-custom-mount
version: 1
description: Deployment template with custom model mount path
deployment_template_type: Managed
environment: azureml://registries/my-registry/environments/my-environment/versions/1
instance_count: 1
default_instance_type: Standard_DS3_v2
scoring_path: /score
scoring_port: 5001
model_mount_path: /var/azureml-app/models

后续步骤