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

应用于:否基本版是企业版            (升级到企业版APPLIES TO: noBasic edition yesEnterprise edition                       (Upgrade to Enterprise)

可以部署在本教程第一部分开发的预测模型供其他人使用。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.

创建实时推理管道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 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.

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

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

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

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

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

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

    显示“实时终结点”选项卡的屏幕截图,其中突出显示了最近创建的终结点

  2. 选择“测试”。Select Test.

  3. 可以手动输入测试数据或使用自动填充的示例数据,然后选择“测试”。You can manually input testing data or use the autofilled sample data, and select Test.

    门户会将测试请求提交到终结点并显示结果。The portal submits a test request to the endpoint and shows the results. 尽管为输入数据生成了价格值,但它不用于生成预测值。Although a price value is generated for the input data, it isn't used to generate the prediction value.

    显示如何测试实时终结点的屏幕截图,其中突出显示了价格的评分标签

清理资源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 to solve other types of problems, see our other sample pipelines.