教程:使用设计器部署机器学习模型Tutorial: Deploy a machine learning model with the designer

可以部署在本教程第一部分开发的预测模型供其他人使用。You can deploy the predictive model developed in part one of the tutorial to give others a chance to use it. 在第一部分中,你已定型了模型。In part one, you trained your model. 现在,让我们基于用户输入生成新的预测。Now, it's time to generate new predictions based on user input. 本教程的此部分介绍如何:In this part of the tutorial, you will:

  • 创建实时推理管道。Create a real-time inference pipeline.
  • 创建推理群集。Create an inferencing cluster.
  • 部署实时终结点。Deploy the real-time endpoint.
  • 测试实时终结点。Test the real-time endpoint.

先决条件Prerequisites

完成教程的第一部分,了解如何在设计器中训练机器学习模型并为其评分。Complete part one of the tutorial to learn how to train and score a machine learning model in the designer.

重要

如果看不到本文档中提到的图形元素(例如工作室或设计器中的按钮),则你可能没有适当级别的工作区权限。If you do not see graphical elements mentioned in this document, such as buttons in studio or designer, you may not have the right level of permissions to the workspace. 请与 Azure 订阅管理员联系,验证是否已向你授予正确级别的访问权限。Please contact your Azure subscription administrator to verify that you have been granted the correct level of access. 有关详细信息,请参阅管理用户和角色For more information, see Manage users and roles.

创建实时推理管道Create a real-time inference pipeline

若要部署管道,必须先将训练管道转换为实时推理管道。To deploy your pipeline, you must first convert the training pipeline into a real-time inference pipeline. 此过程会删除训练模块,并添加 Web 服务输入和输出以处理请求。This process removes training modules and adds web service inputs and outputs to handle requests.

创建实时推理管道Create a real-time inference pipeline

  1. 在管道画布上方,选择“创建推理管道” > “实时推理管道” 。Above the pipeline canvas, select Create inference pipeline > Real-time inference pipeline.

    显示“创建管道”按钮位置的屏幕截图

    管道现在应如下所示:Your pipeline should now look like this:

    显示做好部署准备后管道的预期配置的屏幕截图

    选择“创建推理管道”时,会发生一些事情:When you select Create inference pipeline, several things happen:

    • 训练的模型在模块调色板中存储为“数据集”模块。The trained model is stored as a Dataset module in the module palette. 可以在“我的数据集”下找到它。You can find it under My Datasets.
    • 将删除“训练模型”和“拆分数据”等训练模块。 Training modules like Train Model and Split Data are removed.
    • 保存的训练模型已添加回管道中。The saved trained model is added back into the pipeline.
    • 已添加“Web 服务输入”和“Web 服务输出”模块。Web Service Input and Web Service Output modules are added. 这些模块显示用户数据进入管道的位置,以及返回数据的位置。These modules show where user data enters the pipeline and where data is returned.

    备注

    默认情况下,“Web 服务输入”将需要与用于创建预测管道的训练数据相同的数据架构。By default, the Web Service Input will expect the same data schema as the training data used to create the predictive pipeline. 在此方案中,价格包含在架构内。In this scenario, price is included in the schema. 但是,在预测过程中不会将价格用作因素。However, price isn't used as a factor during prediction.

  2. 选择“提交”,并使用在第一部分中使用的相同计算目标和试验。Select Submit, and use the same compute target and experiment that you used in part one.

    如果这是第一次运行,则管道可能需要长达 20 分钟的时间才能完成运行。If this is the first run, it may take up to 20 minutes for your pipeline to finish running. 默认计算设置中的最小节点大小为 0,这意味着设计器必须在空闲后分配资源。The default compute settings have a minimum node size of 0, which means that the designer must allocate resources after being idle. 由于计算资源已分配,因此,重复的管道运行花费的时间会更少。Repeated pipeline runs will take less time since the compute resources are already allocated. 此外,设计器还对每个模块使用缓存的结果,以便进一步提高效率。Additionally, the designer uses cached results for each module to further improve efficiency.

  3. 选择“部署”。Select Deploy.

创建推理群集Create an inferencing cluster

在显示的对话框中,可以从任何现有的 Azure Kubernetes 服务 (AKS) 群集中进行选择,以便部署模型。In the dialog box that appears, you can select from any existing Azure Kubernetes Service (AKS) clusters to deploy your model to. 如果没有 AKS 群集,可通过以下步骤创建一个。If you don't have an AKS cluster, use the following steps to create one.

  1. 在显示的对话框中选择“计算”,转到“计算”页。 Select Compute in the dialog box that appears to go to the Compute page.

  2. 在导航功能区中,选择“推理群集” > “+ 新建” 。On the navigation ribbon, select Inference Clusters > + New.

    显示如何转到新的推理群集窗格的屏幕截图

  3. 在推理群集窗格中,配置新的 Kubernetes 服务。In the inference cluster pane, configure a new Kubernetes Service.

  4. 输入“aks-compute”作为“计算名称”。Enter aks-compute for the Compute name.

  5. 对于“区域”,选择可用的邻近区域。Select a nearby region that's available for the Region.

  6. 选择“创建”。Select Create.

    备注

    创建新的 AKS 服务大约需要 15 分钟。It takes approximately 15 minutes to create a new AKS service. 可在“推理群集”页上查看预配状态。You can check the provisioning state on the Inference Clusters page.

部署实时终结点Deploy the real-time endpoint

在 AKS 服务完成预配以后,请返回到实时推理管道,以便完成部署。After your AKS service has finished provisioning, return to the real-time inferencing pipeline to complete deployment.

  1. 选择画布上面的“部署”。Select Deploy above the canvas.

  2. 选择“部署新的实时终结点”。Select Deploy new real-time endpoint.

  3. 选择已创建的 AKS 群集。Select the AKS cluster you created.

    显示如何设置新的实时终结点的屏幕截图

    还可以更改实时终结点的“高级”设置。You can also change Advanced setting for your real-time endpoint.

    高级设置Advanced setting 说明Description
    启用 Application Insights 诊断和数据收集Enable Application Insights diagnostics and data collection 是否启用 Azure Application Insights 从部署的终结点收集数据。Whether to enable Azure Application Insights to collect data from the deployed endpoints.
    默认值:falseBy default: false
    评分超时Scoring timeout 对 Web 服务的评分调用强制执行的超时值(以毫秒为单位)。A timeout in milliseconds to enforce for scoring calls to the web service.
    默认情况下:60000By default: 60000
    已启用自动缩放Auto scale enabled 是否为 Web 服务启用自动缩放。Whether to enable autoscaling for the web service.
    默认值:trueBy default: true
    副本数下限Min replicas 自动缩放此 Web 服务时可使用的容器的最小数目。The minimum number of containers to use when autoscaling this web service.
    默认情况下:1By default: 1
    副本数上限Max replicas 自动缩放此 Web 服务时可使用的容器的最大数目。The maximum number of containers to use when autoscaling this web service.
    默认情况下:10By default: 10
    目标利用率Target utilization 自动缩放程序应尝试维持的此 Web 服务的目标利用率(以低于 100 的百分比表示)。The target utilization (in percent out of 100) that the autoscaler should attempt to maintain for this web service.
    默认情况下:70By default: 70
    刷新周期Refresh period 自动缩放程序尝试缩放此 Web 服务的频率(以秒为单位)。How often (in seconds) the autoscaler attempts to scale this web service.
    默认情况下:1By default: 1
    CPU 保留容量CPU reserve capacity 要分配给此 Web 服务的 CPU 核心数。The number of CPU cores to allocate for this web service.
    默认情况下:0.1By default: 0.1
    内存保留容量Memory reserve capacity 为此 Web 服务分配的内存量 (GB)。The amount of memory (in GB) to allocate for this web service.
    默认情况下:0.5By default: 0.5
  4. 选择“部署”。Select Deploy.

    部署完成后,将在画布上方显示成功通知。A success notification above the canvas appears after deployment finishes. 这可能需要几分钟时间。It might take a few minutes.

提示

如果在“实时终结点设置”框中为“计算类型”选择了“Azure 容器实例”,则还可以部署到“Azure 容器实例”(ACI) 。You can also deploy to Azure Container Instance (ACI) if you select Azure Container Instance for Compute type in the real-time endpoint setting box. Azure 容器实例用于测试或开发。Azure Container Instance is used for testing or development. 对于需要小于 48 GB RAM 的基于 CPU 的低缩放工作负载,请使用 ACI。Use ACI for low-scale CPU-based workloads that require less than 48 GB of RAM.

测试实时终结点Test the real-time endpoint

部署完成后,可通过转到“终结点”页来查看实时终结点。After deployment finishes, you can view your real-time endpoint by going to the Endpoints page.

  1. 在“终结点”页上,选择已部署的终结点。On the Endpoints page, select the endpoint you deployed.

    在“详细信息”选项卡中,可以查看更多信息,例如 REST URI、Swagger 定义、状态和标记。In the Details tab, you can see more information such as the REST URI, Swagger definition, status, and tags.

    在“使用”选项卡中,可以找到使用代码示例和安全密钥,以及设置身份验证方法。In the Consume tab, you can find sample consumption code, security keys, and set authentication methods.

    在“部署日志”选项卡中,你可以找到实时终结点的详细部署日志。In the Deployment logs tab, you can find the detailed deployment logs of your real-time endpoint.

  2. 若要测试终结点,请转到“测试”选项卡。可在此输入测试数据并选择“测试”以验证终结点的输出。To test your endpoint, go to the Test tab. From here, you can enter test data and select Test verify the output of your endpoint.

有关使用 Web 服务的详细信息,请参阅使用部署为 Web 服务的模型For more information on consuming your web service, see Consume a model deployed as a webservice

限制Limitations

更新推理管道Update inference pipeline

如果在训练管道中进行了一些修改,则应重新提交训练管道,更新推理管道并再次运行推理管道。If you make some modifications in your training pipeline, you should resubmit the training pipeline, Update the inference pipeline and run the inference pipeline again.

请注意,在推理管道中将只更新经过训练的模型,而不会更新数据转换。Note that only trained models will be updated in the inference pipeline, while data transformation will not be updated.

若要在推理管道中使用更新的转换,需要将转换模块的转换输出注册为数据集。To use the updated transformation in inference pipeline, you need to register the transformation output of the transformation module as dataset.

显示如何注册转换数据集的屏幕截图

然后,手动将推理管道中的 TD 模块替换为已注册的数据集。Then manually replace the TD- module in inference pipeline with the registered dataset.

显示如何替换转换模块的屏幕截图

然后,可以提交具有已更新的模型和转换的推理管道,并部署。Then you can submit the inference pipeline with the updated model and transformation, and deploy.

部署实时终结点Deploy real-time endpoint

由于数据存储访问限制,如果你的推理管道包含“导入数据”或“导出数据”模块,它们将在部署到实时终结点时被自动删除 。Due to datstore access limitation, if your inference pipeline contains Import Data or Export Data module, they will be auto-removed when deploy to real-time endpoint.

清理资源Clean up resources

重要

可以使用你创建的、用作其他 Azure 机器学习教程和操作指南文章的先决条件的资源。You can use the resources that you created as prerequisites for other Azure Machine Learning tutorials and how-to articles.

删除所有内容Delete everything

如果你不打算使用所创建的任何内容,请删除整个资源组,以免产生任何费用。If you don't plan to use anything that you created, delete the entire resource group so you don't incur any charges.

  1. 在 Azure 门户的窗口左侧选择“资源组” 。In the Azure portal, select Resource groups on the left side of the window.

    在 Azure 门户中删除资源组

  2. 在列表中选择你创建的资源组。In the list, select the resource group that you created.

  3. 选择“删除资源组” 。Select Delete resource group.

删除该资源组也会删除在设计器中创建的所有资源。Deleting the resource group also deletes all resources that you created in the designer.

删除各项资产Delete individual assets

在创建试验的设计器中删除各个资产,方法是将其选中,然后选择“删除”按钮。 In the designer where you created your experiment, delete individual assets by selecting them and then selecting the Delete button.

此处创建的计算目标在未使用时,会自动缩减到零个节点。 The compute target that you created here automatically autoscales to zero nodes when it's not being used. 此操作旨在最大程度地减少费用。This action is taken to minimize charges. 若要删除计算目标,请执行以下步骤: If you want to delete the compute target, take these steps:

删除资产

可以通过选择每个数据集并选择“注销” ,从工作区中注销数据集。You can unregister datasets from your workspace by selecting each dataset and selecting Unregister.

取消注册数据集

若要删除数据集,请使用 Azure 门户或 Azure 存储资源管理器访问存储帐户,然后手动删除这些资产。To delete a dataset, go to the storage account by using the Azure portal or Azure Storage Explorer and manually delete those assets.

后续步骤Next steps

本教程介绍了如何在设计器中创建、部署和使用机器学习模型的重要步骤。In this tutorial, you learned the key steps in how to create, deploy, and consume a machine learning model in the designer. 如果要详细了解如何使用设计器,请参阅以下链接:To learn more about how you can use the designer see the following links: