How to schedule EAS service deployments

Updated at:

EAS supports scheduled model service deployments, which is ideal for scenarios where models are retrained on a regular basis and the latest version must go online automatically.

Background information

EAS provides the following methods for scheduling service deployments.

Prerequisites

Limits

When you deploy an EAS service by using Method 2:

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

Note

DataWorks no longer recommends exclusive resource groups for scheduling. We recommend that you use Serverless resource groups, which cover all core features of exclusive resource groups for scheduling.

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 use the OSS path selector on the page to select a valid model file path, and then replace the time-related parts with the global variable. This simplifies manual configuration such as endpoint specification.

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 Enter 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

If you are using an exclusive resource group for scheduling, see Use exclusive resource groups for scheduling to complete Step 1 and Step 2.

Step 1: Create a resource group

  1. Log on to the DataWorks console.

  2. In the left-side navigation pane, click Resource Groups. Go to the Resource Groups page. Create a resource group on this page. For more information, see Use serverless resource groups.

Step 2: Bind a workspace

  1. Log on to the DataWorks console. In the target region, click Resource Group in the left-side navigation pane to open the resource group list.

  2. In the Operation column of the target resource group, click Associate Workspace. Find the workspace you want to bind, and then click Operation > Bind.

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 add new versions to an existing service. You must first deploy an initial model 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 defines service details such as the model storage location and resource usage. Configure the following parameters based on your requirements:

      • name: the service name. Must be unique within a region and serves as the service identifier.

      • model_path: the storage path of the trained model. Supports HTTP and OSS paths.

        HTTP paths require the files to be compressed (TAR, GZ, BZ2, or ZIP). OSS paths can point to a compressed file or a directory. When using an OSS path, add the "oss_endpoint":"oss-cn-beijing.aliyuncs.com", line to the service deployment specification file. Modify the region as needed.

        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 service metadata. For more information about the fields, see Command reference.

      • yourAccessKeyID: your AccessKey ID. For more information, see Obtain an AccessKey pair.

      • yourAccessKeySecret: your AccessKey secret. For more information, see Obtain an AccessKey pair

      • The -e parameter 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 or Serverless resource group that you created.

    4. Click OK.

      After the script runs, an online model service is created. You can 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 Enter Elastic Algorithm Service (EAS).

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

      In the following steps, you 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 below. If you completed Step 4, the first 14 lines need no changes. Otherwise, update 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 Enter 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.