This topic describes how to use Elastic Algorithm Service (EAS) of Machine Learning Platform for AI and DataWorks to implement scheduled model deployment.

Prerequisites

  • An exclusive resource group is purchased in DataWorks. For more information, see DataWorks exclusive resources.
  • Machine Learning Platform for AI is activated. For more information, see Purchase.
  • Scheduled training of an experiment is completed and the model is saved to a specified location. For more information, see Perform offline scheduling.
  • The required permissions on DataWorks and the permissions to deploy models as services in EAS are granted to a RAM user if you use a RAM user. For more information, see Use a RAM user and Grant permissions to RAM users.

Step 1: Create an exclusive resource group

  1. Log on to the DataWorks console.
  2. In the left-side navigation pane, click Resource Groups.
  3. On the Exclusive Resource Groups tab, click Create Resource Group for Scheduling.
  4. In the Create a dedicated resource group panel, set the parameters.
    Parameter Description
    Resource Group Type Select Exclusive Resource Groups.
    Resource Group Name The name of the resource group, which must be unique for the tenant.
    Note A tenant indicates an Alibaba Cloud account. Each tenant may have multiple RAM users.
    Resource Group Description The description of the resource group, which helps differentiate this resource group from other resource groups.
    Order Number The order number of the purchased exclusive resource group. If you have not purchased one, click Purchase.
  5. Click OK.
    Note The exclusive resource group is initialized within 20 minutes. Wait until its status changes to Running.

Step 2: Bind the exclusive resource group to a workspace

You must bind an exclusive resource group to a workspace before you can select the resource group in the workspace.

  1. On the Exclusive Resource Groups tab, find the resource group and click Change Workspace in the Actions column.
  2. In the Workspace section of the Modify home workspace dialog box, find the workspace to which you want to bind the exclusive resource group. Then, click Bind in the Actions column.

Step 3: Create a workflow

  1. Go to the DataStudio page.
    1. Log on to the DataWorks console.
    2. In the left-side navigation pane, click Workspaces.
    3. In the top navigation bar, select the region where your workspace resides, find the workspace, and then click Data Analytics in the Actions column.
  2. Move the pointer over the Create a workflow icon and click Workflow.
    Workflow
  3. In the Create Workflow dialog box, set the Workflow Name and Description parameters.
    Notice The workflow name can be up to 128 characters in length and can contain letters, digits, underscores (_), and periods (.).
  4. Click Create.
  5. On the tab of the workflow, choose General > Shell and drag Shell to the right canvas. Create a node
  6. In the Create Node dialog box, enter Deployment in the Node Name field.
  7. Click Commit.

Step 4: Deploy the model as the initial model service

In scheduled model deployment, the initial model service is updated to a new version as an online service. Therefore, the model must be deployed as the initial model service before the scheduled model deployment. If the initial model service is available, go to Step 5.

  1. Edit 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, # You can change the number of instances based on the actual needs. 
          "cpu": 2 # You can change the number of CPUs based on the actual needs. 
        }
      }
      EOF
      # Run the deployment command. 
      /home/admin/usertools/tools/eascmd -i <yourAccessKeyID> -k <yourAccessKeySecret>  -e pai-eas.cn-shanghai.aliyuncs.com create echo.json
      echo.json is the JSON file that describes the service information, such as the location of the model and the required resources. You can set the following parameters as needed:
      • name: the name of a model service. It is the unique identifier of a model service and must be unique in a region. A model service can be named based on the business meaning.
      • model_path: the path where the trained model is stored. You can specify an HTTP URL or an Object Storage Service (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 the package or the 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 Machine Learning Platform for AI the permissions to access OSS. For more information, see the "OSS authorization" section of the Authorization topic.
      • processor: the type of the processor.
      • metadata: the metadata of the service, which can be modified as needed. For more information, see Run commands to use the EASCMD client.
      • yourAccessKeyID: the AccessKey ID.
      • yourAccessKeySecret: the AccessKey secret.
      • Endpoint: the endpoint of Machine Learning Platform for AI in a specified region. You must set the Endpoint parameter after -e in the preceding deployment command. The following table describes the regions and the endpoint in 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
        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 in the upper part.
    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.
    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 Machine Learning Platform for AI console.
  3. Optional:View the deployed model service.
    1. Log on to the Machine Learning Platform for AI console.
    2. In the left-side navigation pane, choose Model Deployment > EAS-Model Serving.
    3. In the top navigation bar, select a region.
    4. On the Elastic Algorithm Service page, view the deployed model service.
      View the initial model serviceIn subsequent steps, more service versions will be added to the model service to implement scheduled model deployment.

Step 5: Edit the scheduled deployment script

Edit the code of the Shell node in Step 5, as shown in the following sample code. If you have completed Step 5, retain the first 13 lines of code. If you have not performed Step 5, you must change the parameter values in the first 13 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
  }
}
EOF # The 13rd line of code. 
# Update and deploy the model. For each scheduled deployment, a new version of the model service is added as the latest online service. 
/home/admin/usertools/tools/eascmd -i <yourAccessKeyID> -k <yourAccessKeySecret> -e pai-eas.cn-shanghai.aliyuncs.com modify <yourModelName> -s echo.json
# Define the test logic for the service. 
# If an exception occurs on the test service, run the following command to roll back the model service: 
#/home/admin/usertools/tools/eascmd -i <yourAccessKeyID> -k <yourAccessKeySecret> -e pai-eas.cn-shanghai.aliyuncs.com version -f <The name of the model to be rolled back> 1
For more information about the parameters, see Step 4: Deploy the model as the initial model service.

Step 6: Execute 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 Instance Recurrence parameter in the Schedule section.
    3. In the Dependencies section, click Use Root Node next to the Parent Nodes field.
    4. Configure dependencies. For more information, see Instructions to configure scheduling dependencies.
    5. Click the Save icon on the tab of the Shell node to save the configurations.
    6. Click the Commit icon on the tab of the Shell node to commit the scheduled node.
  2. View the instances of the scheduling node.
    1. On the tab of the Shell node, 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. View the operational logs
  3. View the model service deployed at scheduled time.
    1. Log on to the Machine Learning Platform for AI console.
    2. In the left-side navigation pane, choose Model Deployment > EAS-Model Serving.
    3. In the top navigation bar, select a region.
    4. On the Elastic Algorithm Service page, find the service and view all the versions that are automatically updated in the Version column. View the automatically deployed model service