All Products
Search
Document Center

Platform For AI:Configure scheduled model deployment

Last Updated:Dec 26, 2023

This topic describes how to deploy a model as a model service at a scheduled time.

Background information

You can use one of the following methods to deploy an Elastic Algorithm Service (EAS) model at a scheduled time.

Prerequisites

Limits

Method 2

Only exclusive resource groups for scheduling in DataWorks can be used for scheduled model deployment. Shared resource groups are not supported.

Method 1: Use the Update EAS Service component provided by Designer

Step 1: Create a Designer workflow

  • If your model is trained by using a Designer workflow, you can directly connect the output port of the model training component to the Update EAS Service component. For more information, see Periodically update online model services. image.png

  • If your model is not trained by using Designer but the model is stored in an OSS bucket, you can create an empty workflow for the model. For more information, see Create a custom workflow. After you create the workflow, refer to the following figure, drag and drop the Read OSS Data and Update EAS Service components, and connect the components. Then, set the OSS Data Path parameter of the Read OSS Data component to the OSS path of the model. image

  • If your model is retrieved from a specified OSS path at a specified time, you can add global variables to the workflow. e0593dcccb40d8cf3ec4d602893e682a.pngThen, reference the global variables in the Read OSS Data component to specify the model path. Example: oss://examplebucket.oss-cn-shanghai-internal.aliyuncs.com/${date}/heart.pmml.

    Note

    You can use the OSS path selector on the page to select a valid model path, and then replace the elements that are related to the time variables in the path with global variables. This simplifies the input configurations such as the endpoint setting.

Step 2: Deploy the workflow in DataWorks

Refer to Use DataWorks tasks to schedule pipelines in Machine Learning Designer and deploy the preceding workflow as a scheduled node in DataWorks by using one-click deployment.

If you want to reference the Designer global variables that you added in Step 1, refer to Example 2: Replace scheduling parameters and replace the global variables in the scheduling configuration of the node with the required system variables. image

Step 3: View the historical versions of the periodically updated model service

To view the historical versions of the periodically updated model service, perform the following steps:

  1. Log on to the PAI console.

  2. In the left-side navigation pane, click Workspaces. On the Workspaces page, click the name of the workspace to which the model service you want to view belongs.

  3. Perform the steps in the following figure to view all historical versions of the periodically updated model service. ad4cd8feb8bb34f963f1f7fdc1c18cd8

Method 2: Manually deploy the model in DataWorks

Step 1: Create an exclusive resource group for scheduling

  1. Log on to the DataWorks console.

  2. In the left-side navigation pane, click Resource Groups. On the Exclusive Resource Groups tab of the Resource Groups page, click Create Resource Group for Scheduling to go to the DataWorks Exclusive Resources page. On this page, configure the following parameters.

    Parameter

    Description

    Region

    The region in which you want to use the exclusive resource group for scheduling.

    Note

    An exclusive resource group for scheduling cannot be shared across regions. For example, an exclusive resource group for scheduling in the China (Shanghai) region can be used only by workspaces in the China (Shanghai) region.

    Type

    The type of the exclusive resource group. Select Exclusive Resources for Scheduling for this parameter.

    Resource Group Name

    The name of the exclusive resource group for scheduling. The name must be unique within a tenant. Otherwise, an error is reported when you confirm the purchase operation.

    Note

    A tenant refers to an Alibaba Cloud account. Each tenant can have multiple RAM users.

    Resource Group Description

    The description of the exclusive resource group for scheduling.

    Duration

    Exclusive resource groups for scheduling are charged based on the subscription billing method. To ensure service continuity, we recommend that you select Auto-renewal. You can also go to the Renewal Management page to enable or disable auto renewal after the resource group is created. For more information, see General reference: Disable auto-renewal for subscription resources.

    You can configure other parameters based on your business requirements.

  3. Click Buy Now and complete the payment based on the instructions.

    Then, DataWorks starts to initialize the exclusive resource group for scheduling. When the resource group enters the Running state, the resource group is created in the DataWorks console.

    Note

    DataWorks requires approximately 20 minutes to initialize the exclusive resource group for scheduling. Wait until the status of the resource group changes to Running.

Step 2: Associate the exclusive resource group with a workspace

You must associate an exclusive resource group for scheduling with a workspace before you can select the resource group in the workspace.

  1. In the left-side navigation pane, click Resource Groups. On the Exclusive Resource Groups tab of the Resource Groups page, find the created resource group and click Change Workspace in the Actions column.

  2. In the Modify home workspace dialog box, find the workspace with which you want to associate the resource group and click Bind in the Actions column.

Step 3: Create a workflow

  1. Log on to the DataWorks console. In the left-side navigation pane, choose Data Modeling and Development > DataStudio. On the page that appears, select the desired workspace from the drop-down list and click Go to DataStudio.

  2. On the DataStudio page, move the pointer over the Create icon and select Create Workflow.

  3. In the Create Workflow dialog box, configure Workflow Name and Description.

  4. Click Create.

  5. On the configuration tab of the workflow, drag and drop the Shell node below General to the right-side canvas.新增节点

  6. In the Create Node dialog box, enter Deployment in the Name field.

  7. Click OK.

Step 4: Deploy the model as an initial model service

In scheduled model deployment, online model services are updated from initial model services. Therefore, the model must be deployed as an initial model service before you perform the scheduled model deployment. If the initial model service already exists, go to Step 5.

  1. Modify the deployment script.

    1. On the tab of the workflow, double-click the created Shell node. In this example, double-click the Deployment node.

    2. On the tab of the Shell node, enter the following commands:

      # Compile the service deployment description file. 
      cat << EOF > echo.json
      {
        "name": "yourModelName",
        "generate_token": "true",
        "model_path": "yourModelAdress",
        "processor": "yourProcessorType",
        "metadata": {
          "instance": 1, # Change the number of instances as needed. 
          "cpu": 2 # Change the number of vCPUs as needed. 
          "memory": 4000
        }
      }
      EOF
      # Run the deployment command. 
      /home/admin/usertools/tools/eascmd64 -i <yourAccessKeyID> -k <yourAccessKeySecret>  -e pai-eas.cn-shanghai.aliyuncs.com create echo.json
      Important

      If your exclusive resource group was created before August 10, 2022, replace /home/admin/usertools/tools/eascmd64 *** with /home/admin/usertools/tools/eascmd *** in Line 16 of the preceding command.

      The echo.json is the JSON file that describes the service information, such as the path of the model and the required resources. You can set the following parameters based on your business requirements:

      • name: the name of a model service. The name uniquely identifies a model service. Service names must be unique within a region. We recommend that you name model services based on the actual business for which the model services are used.

      • model_path: the path where the trained model is stored. You can specify an HTTP URL or an OSS path.

        If you set this parameter to an HTTP URL, the files must be in TAR, GZ, BZ2, or ZIP format. If you set this parameter to an OSS path, you can specify the path of a compressed package or a directory. To use an OSS path, you must specify the endpoint of OSS by adding the line of code "oss_endpoint":"oss-cn-beijing.aliyuncs.com" to the preceding service deployment description file. You can change the region in the code as needed.

        Note

        If you use OSS to store models, you must grant PAI the permissions to access OSS. For more information, see Grant PAI the permissions to access OSS.

      • processor: the type of the processor.

      • metadata: the metadata of the service, which can be modified as needed. For more information about the fields, see Run commands to use the EASCMD client.

      • yourAccessKeyID: the AccessKey ID. For information about how to obtain an AccessKey pair, see How do I obtain an AccessKey pair?.

      • yourAccessKeySecret: the AccessKey secret. For information about how to obtain an AccessKey pair, see How do I obtain an AccessKey pair?

      • Endpoint: the endpoint of PAI in a specified region. You must set the Endpoint parameter that follows -e in the preceding deployment command. The following table lists the regions and their endpoints.

        Region

        Endpoint

        China (Shanghai)

        pai-eas.cn-shanghai.aliyuncs.com

        China (Beijing)

        pai-eas.cn-beijing.aliyuncs.com

        China (Hangzhou)

        pai-eas.cn-hangzhou.aliyuncs.com

        China (Shenzhen)

        pai-eas.cn-shenzhen.aliyuncs.com

        China (Hong Kong)

        pai-eas.cn-hongkong.aliyuncs.com

        Singapore

        pai-eas.ap-southeast-1.aliyuncs.com

        India (Mumbai)

        pai-eas.ap-south-1.aliyuncs.com

        Indonesia (Jakarta)

        pai-eas.ap-southeast-5.aliyuncs.com

        Germany (Frankfurt)

        pai-eas.eu-central-1.aliyuncs.com

  2. Run the script.

    1. On the tab of the Shell node, click the 2 icon.

    2. In the Warning message, click Continue to Run.

    3. In the Runtime Parameters dialog box, set the Resource Group parameter to the created exclusive resource group for scheduling.

    4. Click OK.

      After the code is executed, an online model service is generated. You can perform the following steps to view the model service in the PAI console.

  3. Optional. View deployed model services.

    1. Log on to the PAI console.

    2. In the left-side navigation pane, click Workspaces. On the Workspaces page, click the name of the workspace to which the model service that you want to view belongs.

    3. Perform the steps in the following figure to view the deployed model service. image

      In subsequent steps, more service versions will be added to the model service to implement scheduled model deployment.

Step 5: Modify the scheduled deployment script

  1. Modify the code of the Shell node in Step 4, which is shown in the following sample code. If you have finished Step 4, retain the first 14 lines of code. If you have not performed Step 4, you must change the parameter values in the first 14 lines of code as needed.

    # Compile the service deployment description file. 
    cat << EOF > echo.json
    {
      "name": "yourModelName",
      "generate_token": "true",
      "model_path": "yourModelAdress",
      "processor": "yourProcessorType",
      "metadata": {
        "instance": 1,
        "cpu": 2,
        "memory": 4000
      }
    }
    EOF # Code in Line 14. 
    # Update and deploy the model. For each scheduled deployment, a new version of the model service is added as the latest online service version. 
    /home/admin/usertools/tools/eascmd64 -i <yourAccessKeyID> -k <yourAccessKeySecret> -e pai-eas.cn-shanghai.aliyuncs.com modify <yourModelName> -s echo.json
    # Define the logic for testing the service. 
    # If the service encounters an error during the test, run the following command to roll back the model service: 
    #/home/admin/usertools/tools/eascmd64 -i <yourAccessKeyID> -k <yourAccessKeySecret> -e pai-eas.cn-shanghai.aliyuncs.com version -f <The name of the model to be rolled back> 1
    Important

    If your exclusive resource group for scheduling was created before August 10, 2022, replace /home/admin/usertools/tools/eascmd64 *** with /home/admin/usertools/tools/eascmd *** in Line 16 and Line 19.

    For more information about the parameters, see Step 4: Deploy the model as an initial model service.

Step 6: Perform scheduled deployment

  1. Configure scheduling properties and commit the Shell node.

    1. On the Shell node tab, click the Properties tab in the right-side pane.

    2. In the Properties panel, set the Recurrence parameter in the Schedule section.

    3. In the Dependencies section, click Add Root Node next to the Parent Nodes field.

    4. Configure scheduling dependencies. For more information, see Configure same-cycle scheduling dependencies.

    5. Click the 保存 icon on the tab of the Shell node to save the configurations.

    6. Click the 提交 icon on the tab of the Shell node to commit the Shell node.

  2. View the instances of the Shell node.

    1. On the Shell node tab, click Operation Center in the upper-right corner.

    2. On the Operation Center page, choose Cycle Task Maintenance > Cycle Instance.

    3. On the instance list page, view the scheduled time for automatic model deployment in the Schedule column.

    4. Click More in the Actions column and select View Runtime Log to view operational logs of each scheduled deployment.

  3. View the model service deployed at a specific scheduled time.

    1. Log on to the PAI console.

    2. In the left-side navigation pane, click Workspaces. On the Workspaces page, click the name of the workspace to which the model service that you want to view belongs.

    3. Perform the steps in the following figure to view all historical versions of the periodically updated model service. ad4cd8feb8bb34f963f1f7fdc1c18cd8