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 字符串 部署模板的说明。
tags 对象 部署模板的标记字典。
type 字符串 部署模板的类型。
deployment_template_type 字符串 部署模板类型。
environment 字符串或对象 用于部署模板的环境。 此值可以是对注册表中现有版本控制环境的引用,也可以是内联环境规范。

若要引用注册表中的现有环境,请使用 azureml://registries/<registry-name>/environments/<environment-name> 语法。

若要以内联方式定义环境,请遵循环境架构

对于生产方案,最佳做法应该是单独创建环境并在此处引用环境。
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
environment: azureml:my-environment:1
instance_count: 1
default_instance_type: Standard_DS3_v2

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
environment: azureml://registries/azureml/environments/minimal-ubuntu20.04-py38-cpu-inference: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
environment: azureml:my-environment:1
instance_count: 1
default_instance_type: Standard_DS3_v2
allowed_instance_types: Standard_DS3_v2

YAML:内联环境

$schema: https://azuremlschemas.azureedge.net/latest/deploymentTemplate.schema.json
name: my-deployment-template-inline-env
version: 1
description: Deployment template with inline environment definition
environment:
  name: inline-environment
  image: mcr.microsoft.com/azureml/minimal-ubuntu20.04-py38-cpu-inference:latest
  inference_config:
    liveness_route:
      path: /health
      port: 5001
    readiness_route:
      path: /ready
      port: 5001
    scoring_route:
      path: /score
      port: 5001
instance_count: 1
default_instance_type: Standard_DS3_v2

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
environment: azureml:my-environment:1
instance_count: 1
default_instance_type: Standard_DS3_v2
model_mount_path: /var/azureml-app/models

后续步骤