How to schedule EAS service deployments

更新时间:
复制 MD 格式

This topic shows you how to schedule model service deployments.

Background information

You can schedule EAS service deployments using one of the following methods.

Prerequisites

Limits

When you deploy an EAS service by using Method 2:

DataWorks supports only Exclusive Resource Group for Scheduling, not Public Resource Group.

Method 1: Use the Update EAS Service component

Step 1: Create a Designer workflow

  • If your model is trained by using a Designer workflow, you can directly connect the Update EAS Service component downstream of the training component. For more information, see Schedule automatic updates for online model services. In PAI Designer, create a haze prediction workflow. On the canvas, connect the Split, Random Forest, Binary Logistic Regression, Prediction, and Update EAS Service components in sequence. Select the Update EAS Service (Beta) node. In the right-side panel, configure EAS Service Name (for example, test_designer), Region ID (the current region by default), and EAS Service Description json.

  • If your model is stored in an OSS bucket instead of being trained in Designer, create a blank workflow. For more information, see Create a custom workflow. Drag the Read OSS Data and Update EAS Service components to the canvas and connect them. In the Read OSS Data component, set OSS Data Path to the path where the model is stored. On the canvas, connect the Read OSS Data component to the Update EAS Service (Beta) component. Click the Update EAS Service (Beta) node. In the Parameter Settings panel on the right, configure EAS Service Name (for example, test_designer) and EAS Service Description json. Specify only the parameters that you want to modify. The default value is {}.

  • To read your model from a time-stamped custom OSS directory, you can configure a global variable in the workflow. In the Workflow Properties panel on the right, click Global variable and add a variable. Set the variable name to date and the value to 20221220. In the workflow, reference the global variable by using the ${variable_name} format. Use the global variable in the Read OSS Data component to configure the model path. Example: oss://examplebucket.oss-cn-shanghai-internal.aliyuncs.com/${date}/heart.pmml.

    Note

    You can first use the OSS path selector on the page to select a valid model file path, and then replace the time-related parts of the path with the global variable. This simplifies manual configurations, such as specifying the endpoint.

Step 2: Deploy the workflow to DataWorks

Deploy the workflow to DataWorks as a scheduled node. For more information, see Use DataWorks to schedule Designer workflows for offline execution.

If you added a Designer global variable in Step 1, replace the global variable with the required system variable in the scheduling configuration of the node. For more information, see Global variables. On the Properties tab, in the Basic Properties section, set Parameters to date=$bizdate.

Step 3: View service versions

To view the versions of the scheduled model service:

  1. Log on to the PAI console. Select a region on the top of the page. Then, select the desired workspace and click Elastic Algorithm Service (EAS).

  2. To view all historical versions of the service, in the Inference Services list, click the version number in the Current Version column of the target service, such as V2. The Version Information panel appears and displays all historical versions and their creation times. In the Actions column, click Rollback to this version to revert the service to a specific version, or click View Deployment Configuration to view the configuration details of the version.

Method 2: Manually deploy in DataWorks

Step 1: Create an exclusive resource group

  1. Log on to the DataWorks console.

  2. In the left-side navigation pane, click Resource Groups. On the Exclusive Resource Group page that appears, create an exclusive resource group for scheduling. For more information about the parameters, see Use an exclusive resource group for scheduling.

Step 2: Bind a workspace

You must bind an exclusive resource group for scheduling to a workspace before it can be used.

  1. On the Resource Groups page, click the Exclusive Resource Group tab, and then click Associate Workspace in the row of the target resource group.

  2. On the Associate Workspace page, click Bind in the row of the target workspace to associate the exclusive resource group with the workspace.

Step 3: Create a workflow

  1. Log on to the DataWorks console. In the target region, click Data Development and O&M > Data Development in the left-side navigation pane. Select a workspace from the drop-down list and click Go to Data Development.

  2. On the Data Studio page, move the pointer over the 新建 icon and click Create Workflow.

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

  4. Click Create.

  5. Right-click the target workflow and choose Create Node > General > Shell.

  6. In the Create Node dialog box, in the Name field, enter Deployment node and click Confirm.

Step 4: Deploy the initial model

Scheduled deployments update an existing service by adding new versions. Therefore, you must first deploy an initial model to serve as the base online service. If an initial model service already exists, skip to Step 5.

  1. Edit the deployment script.

    1. On the workflow page, double-click the created Shell node (Deployment node).

    2. On the Shell node page, enter the following commands.

      # Write the service deployment specification file.
      cat << EOF > echo.json
      {
        "name": "yourModelName",
        "generate_token": "true",
        "model_path": "yourModelAdress",
        "processor": "yourProcessorType",
        "metadata": {
          "instance": 1, # You can adjust the number of instances based on your needs.
          "cpu": 2, # You can adjust the number of CPUs based on your needs.
          "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 for scheduling was created before August 10, 2022, you must change /home/admin/usertools/tools/eascmd64 *** to /home/admin/usertools/tools/eascmd *** in line 16 of the script.

      echo.json is a JSON file that defines service details, such as the model's storage location and resource usage. Configure the following parameters based on your requirements:

      • name: The service name. It must be unique within a region and serves as the service's unique identifier. You can specify a name based on the business functions of the service.

      • model_path: The path where the trained model is stored. The path can be an HTTP or OSS path.

        If you use an HTTP path, the required files must be in a compressed format, such as TAR, GZ, BZ2, or ZIP. If you use an OSS path, you can specify the path of a compressed file or a directory. When you use an OSS path, you must specify an endpoint by adding the "oss_endpoint":"oss-cn-beijing.aliyuncs.com", line to the service deployment specification file. Modify the region based on your requirements.

        Note

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

      • processor: The processor type.

      • metadata: The metadata of the service. Modify the metadata based on your requirements. For more information about the fields, see Command reference.

      • yourAccessKeyID: The AccessKey ID. For more information about how to obtain an AccessKey pair, see Obtain an AccessKey pair.

      • yourAccessKeySecret: The AccessKey Secret. For more information about how to obtain an AccessKey pair, see Obtain an AccessKey pair

      • The -e parameter in the deployment command specifies the regional endpoint. The following table lists the endpoints for each region.

        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

        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 Shell node page, click the 2 icon at the top.

    2. In the Warning dialog box, click Continue to Run.

    3. In the Runtime Parameters dialog box, set Resource Group for Scheduling to the exclusive resource group that you created.

    4. Click OK.

      After the script runs, it creates an online model service. You can then view the service in the PAI console.

  3. (Optional) View the deployed model service.

    1. Log on to the PAI console. Select a region on the top of the page. Then, select the desired workspace and click Elastic Algorithm Service (EAS).

    2. On the EAS page, view the deployed model service.

      In the following steps, you will add new versions to this service to implement scheduled deployments.

Step 5: Edit the scheduled deployment script

  1. Edit the Shell node script from Step 4 as shown in the following example. If you have completed Step 4, you do not need to modify the first 14 lines of code. If not, you must modify the parameter values in those lines as required.

    # Write the service deployment specification file.
    cat << EOF > echo.json
    {
      "name": "yourModelName",
      "generate_token": "true",
      "model_path": "yourModelAdress",
      "processor": "yourProcessorType",
      "metadata": {
        "instance": 1,
        "cpu": 2,
        "memory": 4000
      }
    }
    EOF # Line 14 of the code.
    # Run the model update deployment. Each scheduled run adds a new version to the original model service as the latest online service.
    /home/admin/usertools/tools/eascmd64 -i <yourAccessKeyID> -k <yourAccessKeySecret> -e pai-eas.cn-shanghai.aliyuncs.com modify <yourModelName> -s echo.json
    # You can add service test logic here.
    # If the service test fails, use 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, you must change /home/admin/usertools/tools/eascmd64 *** to /home/admin/usertools/tools/eascmd *** in lines 16 and 19 of the script.

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

Step 6: Run the scheduled task

  1. Run the scheduled task.

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

    2. In the Schedule section of the Properties pane, select a Scheduling Cycle.

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

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

    5. Click the 保存 icon at the top of the Shell node page to save the configuration.

    6. Click the 提交 icon at the top of the Shell node page to commit the scheduled task.

  2. View the running instances of the scheduled task.

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

    2. In Operation Center, choose Auto Triggered Task O&M > Auto Triggered Node Instance.

    3. On the instance details page, view the Schedule for the automatic model deployment.

    4. In the Actions column, choose More > View Runtime Log to view the runtime logs for each scheduled deployment.

  3. View the scheduled model service.

    1. Log on to the PAI console. Select a region on the top of the page. Then, select the desired workspace and click Elastic Algorithm Service (EAS).

    2. To view all historical versions of the service, in the Inference Services list, click the version number in the Current Version column of the target service, such as V2. The Version Information panel appears and displays all historical versions and their creation times. In the Actions column, click Rollback to this version to revert the service to a specific version, or click View Deployment Configuration to view the configuration details of the version.