AksWebservice 类

表示一个部署为 Azure Kubernetes 服务上 Web 服务终结点的机器学习模型。

从模型、脚本和关联的文件创建已部署的服务。 生成的 Web 服务是一个负载均衡、具有 REST API 的 HTTP 终结点。 可将数据发送到此 API,并接收模型返回的预测。

AksWebservice 将一个服务部署到一个终结点。 若要将多个服务部署到一个终结点,请使用 AksEndpoint 类。

有关详细信息,请参阅将模型部署到 Azure Kubernetes 服务群集

初始化 Web 服务实例。

Webservice 构造函数检索与提供的工作区关联的 Webservice 对象的云表示形式。 它将返回与检索到的 Webservice 对象的特定类型对应的子类的实例。

继承
AksWebservice

构造函数

AksWebservice(workspace, name)

参数

workspace
Workspace
必需

包含要检索的 Webservice 对象的工作区对象。

name
str
必需

要检索的 Webservice 对象的名称。

注解

建议的部署模式是使用 deploy_configuration 方法创建部署配置对象,然后将该对象与 Model 类的 deploy 方法一起使用,如下所示。


   # Set the web service configuration (using default here)
   aks_config = AksWebservice.deploy_configuration()

   # # Enable token auth and disable (key) auth on the webservice
   # aks_config = AksWebservice.deploy_configuration(token_auth_enabled=True, auth_enabled=False)

完整示例可从 https://github.com/Azure/MachineLearningNotebooks/blob/master/how-to-use-azureml/deployment/production-deploy-to-aks/production-deploy-to-aks.ipynb 获取

有多种方法可以将模型部署为 webservice,包括:

  • 已在工作区中注册的模型的 Modeldeploy 方法。

  • Webservicedeploy_from_image 方法。

  • 已在工作区中注册的模型的 Webservicedeploy_from_model 方法。 此方法将创建映像。

  • Webservicedeploy 方法,它将注册模型并创建映像。

有关使用 webservice 的信息,请参阅

“变量”部分列出了云 AksWebservice 对象的本地表示形式的属性。 应将这些变量视为只读。 更改其值不会反映在对应的云对象中。

变量

enable_app_insights
bool

是否为 Webservice 启用了 AppInsights 日志记录。

autoscaler
AutoScaler

Webservice 的自动缩放程序对象。

compute_name
str

将 Webservice 部署到的 ComputeTarget 的名称。

container_resource_requirements
ContainerResourceRequirements

Webservice 的容器资源要求。

liveness_probe_requirements
LivenessProbeRequirements

Webservice 的运行情况探测要求。

data_collection
DataCollection

Webservice 的 DataCollection 对象。

max_concurrent_requests_per_container
int

Webservice 的每个容器的最大并发请求数。

max_request_wait_time
int

Webservice 的最大请求等待时间,以毫秒为单位。

num_replicas
int

Webservice 的副本数。 每个副本对应于一个 AKS Pod。

scoring_timeout_ms
int

Webservice 的评分超时,以毫秒为单位。

azureml.core.webservice.AksWebservice.scoring_uri
str

Webservice 的评分终结点

is_default
bool

Webservice 是否为父 AksEndpoint 的默认版本。

traffic_percentile
int

要路由到父 AksEndpoint 中 Webservice 的流量百分比。

version_type
VersionType

父 AksEndpoint 中 Webservice 的版本类型。

token_auth_enabled
bool

是否为 Webservice 启用了令牌身份验证。

environment
Environment

用于创建 Webservice 的环境对象。

azureml.core.webservice.AksWebservice.models
list[Model]

部署到 Webservice 的模型的列表。

deployment_status
str

Webservice 的部署状态。

namespace
str

Webservice 的 AKS 命名空间。

azureml.core.webservice.AksWebservice.swagger_uri
str

Webservice 的 swagger 终结点。

方法

add_properties

将键值对添加到此 Webservice 的属性字典。

add_tags

将键值对添加到此 Webservice 的标记字典。

引发 WebserviceException

deploy_configuration

创建配置对象以部署到 AKS 计算目标。

get_access_token

检索此 Webservice 的身份验证令牌。

get_token

已弃用。 请改用 get_access_token 方法。

检索此 Webservice 的身份验证令牌。

remove_tags

从此 Webservice 的标记字典中删除指定的键。

run

使用提供的输入调用此 Web 服务。

serialize

将此 Webservice 转换为 JSON 序列化字典。

update

使用提供的属性更新 Webservice。

在此 Webservice 中,保留为 None 的值将保持不变。

add_properties

将键值对添加到此 Webservice 的属性字典。

add_properties(properties)

参数

properties
dict[str, str]
必需

要添加的属性字典。

add_tags

将键值对添加到此 Webservice 的标记字典。

引发 WebserviceException

add_tags(tags)

参数

tags
dict[str, str]
必需

要添加的标记字典。

例外

deploy_configuration

创建配置对象以部署到 AKS 计算目标。

static deploy_configuration(autoscale_enabled=None, autoscale_min_replicas=None, autoscale_max_replicas=None, autoscale_refresh_seconds=None, autoscale_target_utilization=None, collect_model_data=None, auth_enabled=None, cpu_cores=None, memory_gb=None, enable_app_insights=None, scoring_timeout_ms=None, replica_max_concurrent_requests=None, max_request_wait_time=None, num_replicas=None, primary_key=None, secondary_key=None, tags=None, properties=None, description=None, gpu_cores=None, period_seconds=None, initial_delay_seconds=None, timeout_seconds=None, success_threshold=None, failure_threshold=None, namespace=None, token_auth_enabled=None, compute_target_name=None, cpu_cores_limit=None, memory_gb_limit=None, blobfuse_enabled=None)

参数

autoscale_enabled
bool
默认值: None

是否为此 Webservice 启用自动缩放。 如果 num_replicas 为 None,则默认值为 True。

autoscale_min_replicas
int
默认值: None

自动缩放此 Webservice 时要使用的容器的最小数目。 默认值为 1。

autoscale_max_replicas
int
默认值: None

自动缩放此 Webservice 时要使用的容器的最大数目。 默认值为 10。

autoscale_refresh_seconds
int
默认值: None

自动缩放程序应尝试缩放此 Webservice 的频率。 默认值为 1。

autoscale_target_utilization
int
默认值: None

自动缩放程序应尝试维持此 Webservice 的目标利用率(以低于 100 的百分比表示)。 默认值为 70。

collect_model_data
bool
默认值: None

是否为此 Webservice 启用模型数据收集。 默认为 False。

auth_enabled
bool
默认值: None

是否为此 Webservice 启用密钥身份验证。 默认为 True。

cpu_cores
float
默认值: None

要分配给此 Webservice 的 CPU 核心数。 可以是小数。 默认值为 0.1。 对应于 Azure Kubernetes 服务中的 Pod 核心请求,而不是限制。

memory_gb
float
默认值: None

为此 Webservice 分配的内存量 (GB)。 可以是小数。 默认值为 0.5。 对应于 Azure Kubernetes 服务中的 Pod 内存请求,而不是限制。

enable_app_insights
bool
默认值: None

是否为此 Webservice 启用 Application Insights 日志记录。 默认为 False。

scoring_timeout_ms
int
默认值: None

对此 Webservice 的评分调用强制执行的超时时间。 默认值为 60000。

replica_max_concurrent_requests
int
默认值: None

允许用于此 Webservice 的每个副本的最大并发请求数。 默认值为 1。 除非获得 Microsoft 技术支持人员或 Azure 机器学习团队成员的指导,否则不要更改此设置的默认值 1。

max_request_wait_time
int
默认值: None

在返回 503 错误之前,请求将在队列中停留的最长时间(以毫秒为单位)。 默认为 500。

num_replicas
int
默认值: None

要分配给此 Webservice 的容器数量。 无默认值,如果未设置此参数,则默认启用自动缩放程序。

primary_key
str
默认值: None

要用于此 Webservice 的主要身份验证密钥。

secondary_key
str
默认值: None

要用于此 Webservice 的辅助身份验证密钥。

tags
dict[str, str]
默认值: None

为此 Webservice 指定的键值标记字典。

properties
dict[str, str]
默认值: None

提供此 Webservice 的键值属性的字典。 这些属性在部署后无法更改,但是可以添加新的键值对。

description
str
默认值: None

提供此 Webservice 的说明。

gpu_cores
int
默认值: None

要分配给此 Web 服务的 GPU 核心数。 默认值为 0。

period_seconds
int
默认值: None

执行运行情况探测的频率(秒)。 默认值为 10 秒。 最小值为 1。

initial_delay_seconds
int
默认值: None

启动容器后,启动运行情况探测前的秒数。 默认值为 310。

timeout_seconds
int
默认值: None

运行情况探测超时前等待的秒数。默认值为 2 秒。 最小值为 1。

success_threshold
int
默认值: None

失败后,运行情况探测被视为成功的最小连续成功次数。 默认值为 1。 最小值为 1。

failure_threshold
int
默认值: None

当 Pod 启动而运行情况探测失败时,Kubernetes 将尝试 failureThreshold 次才会放弃。 默认值为 3。 最小值为 1。

namespace
str
默认值: None

要在其中部署此 Web 服务的 Kubernetes 命名空间:最多 63 个小写字母数字(“a”-“z”、“0”-“9”)和连字符(“-”)。 第一个和最后一个字符不能为连字符。

token_auth_enabled
bool
默认值: None

是否为此 Webservice 启用令牌身份验证。 如果启用此功能,则用户可以通过使用使用其 Azure Active Directory 凭据提取访问令牌来访问此 Webservice。 默认为 False。

compute_target_name
str
默认值: None

要部署到的计算目标的名称

cpu_cores_limit
float
默认值: None

允许此 Webservice 使用的最大 CPU 核心数。 可以是小数。

memory_gb_limit
float
默认值: None

允许此 Webservice 使用的最大内存量 (GB)。 可以是小数。

blobfuse_enabled
bool
默认值: None

是否为此 Webservice 启用 blobfuse 模型下载。 默认为 True

返回

部署 AksWebservice 时要使用的配置对象。

返回类型

例外

get_access_token

检索此 Webservice 的身份验证令牌。

get_access_token()

返回

用于描述此 Webservice 的身份验证令牌的对象。

返回类型

例外

get_token

已弃用。 请改用 get_access_token 方法。

检索此 Webservice 的身份验证令牌。

get_token()

返回

此 Webservice 的身份验证令牌以及何时刷新此令牌。

返回类型

例外

remove_tags

从此 Webservice 的标记字典中删除指定的键。

remove_tags(tags)

参数

tags
list[str]
必需

要删除的键列表

run

使用提供的输入调用此 Web 服务。

run(input_data)

参数

input_data
<xref:varies>
必需

用于调用 Webservice 的输入

返回

调用 Web 服务后的结果

返回类型

例外

serialize

将此 Webservice 转换为 JSON 序列化字典。

serialize()

返回

此 Webservice 的 JSON 表示形式。

返回类型

update

使用提供的属性更新 Webservice。

在此 Webservice 中,保留为 None 的值将保持不变。

update(image=None, autoscale_enabled=None, autoscale_min_replicas=None, autoscale_max_replicas=None, autoscale_refresh_seconds=None, autoscale_target_utilization=None, collect_model_data=None, auth_enabled=None, cpu_cores=None, memory_gb=None, enable_app_insights=None, scoring_timeout_ms=None, replica_max_concurrent_requests=None, max_request_wait_time=None, num_replicas=None, tags=None, properties=None, description=None, models=None, inference_config=None, gpu_cores=None, period_seconds=None, initial_delay_seconds=None, timeout_seconds=None, success_threshold=None, failure_threshold=None, namespace=None, token_auth_enabled=None, cpu_cores_limit=None, memory_gb_limit=None, **kwargs)

参数

image
Image
默认值: None

要部署到 Webservice 的新映像

autoscale_enabled
bool
默认值: None

启用或禁用此 Webservice 的自动缩放

autoscale_min_replicas
int
默认值: None

自动缩放此 Webservice 时要使用的容器的最小数目

autoscale_max_replicas
int
默认值: None

自动缩放此 Webservice 时要使用的容器的最大数目

autoscale_refresh_seconds
int
默认值: None

自动缩放程序应尝试缩放此 Webservice 的频率

autoscale_target_utilization
int
默认值: None

自动缩放程序应尝试为此 Webservice 维持的目标利用率(以低于 100 的百分比表示)

collect_model_data
bool
默认值: None

为此 Webservice 启用或禁用模型数据收集

auth_enabled
bool
默认值: None

是否为此 Webservice 启用身份验证

cpu_cores
float
默认值: None

要分配给此 Webservice 的 CPU 核心数。 可以是小数

memory_gb
float
默认值: None

为此 Webservice 分配的内存量 (GB)。 可以是小数

enable_app_insights
bool
默认值: None

是否为此 Webservice 启用 Application Insights 日志记录

scoring_timeout_ms
int
默认值: None

对此 Webservice 的评分调用强制执行的超时时间

replica_max_concurrent_requests
int
默认值: None

允许用于此 Webservice 的每个副本的最大并发请求数。

max_request_wait_time
int
默认值: None

在返回 503 错误之前,请求将在队列中停留的最长时间(以毫秒为单位)

num_replicas
int
默认值: None

要分配给此 Webservice 的容器数量

tags
dict[str, str]
默认值: None

为此 Webservice 指定的键值标记字典。 将替换现有标记。

properties
dict[str, str]
默认值: None

要添加到现有属性字典的键值属性字典

description
str
默认值: None

为此 Webservice 指定的说明

models
list[Model]
默认值: None

要与已更新的服务一起打包的模型对象的列表

inference_config
InferenceConfig
默认值: None

用于提供所需模型部署属性的 InferenceConfig 对象。

gpu_cores
int
默认值: None

要分配给此 Web 服务的 GPU 核心数

period_seconds
int
默认值: None

执行运行情况探测的频率(秒)。 默认值为 10 秒。 最小值为 1。

initial_delay_seconds
int
默认值: None

启动容器后,启动运行情况探测前的秒数。

timeout_seconds
int
默认值: None

运行情况探测超时前等待的秒数。默认值为 1 秒。 最小值为 1。

success_threshold
int
默认值: None

运行情况探测失败后,将其视为成功所需的最小连续成功次数。 默认值为 1。 最小值为 1。

failure_threshold
int
默认值: None

当 Pod 启动而运行情况探测失败时,Kubernetes 将尝试 failureThreshold 次才会放弃。 默认值为 3。 最小值为 1。

namespace
str
默认值: None

要在其中部署此 Web 服务的 Kubernetes 命名空间:最多 63 个小写字母数字(“a”-“z”、“0”-“9”)和连字符(“-”)。 第一个和最后一个字符不能为连字符。

token_auth_enabled
bool
默认值: None

是否为此 Webservice 启用令牌身份验证。 如果启用此功能,则用户可以通过使用其 Azure Active Directory 凭据提取访问令牌来访问此 Webservice。 默认为 False

cpu_cores_limit
float
默认值: None

允许此 Webservice 使用的最大 CPU 核心数。 可以是小数。

memory_gb_limit
float
默认值: None

允许此 Webservice 使用的最大内存量 (GB)。 可以是小数。

kwargs
<xref:varies>
必需

包括参数,以支持将 AKS Web 服务迁移到 Kubernetes 联机终结点和部署。 is_migration=True|False, compute_target=.

例外