Updated on 2024-06-12 GMT+08:00

Deploying as a Batch Service

After an AI application is prepared, you can deploy it as a batch service. The Service Deployment > Batch Services page lists all batch services.

Prerequisites

  • A ModelArts application in the Normal state is available.
  • Data to be batch processed is ready and has been upload to an OBS directory.
  • At least one empty folder has been created in OBS for storing the output.

Context

  • A maximum of 1,000 batch services can be created.
  • Based on the input request (JSON or file) defined by the AI application, different parameters are entered. If the AI application input is a JSON file, a configuration file is required to generate a mapping file. If the AI application input is a file, no mapping file is required.
  • Batch services can only be deployed in a public resource pool, but not a dedicated resource pool.

Procedure

  1. Log in to the ModelArts management console. In the left navigation pane, choose Service Deployment > Batch Services. By default, the Batch Services page is displayed.
  2. In the batch service list, click Deploy in the upper left corner. The Deploy page is displayed.
  3. Set parameters for a batch service.
    1. Set the basic information, including Name and Description. The name is generated by default, for example, service-bc0d. You can specify Name and Description according to actual requirements.
    2. Set other parameters, including AI application configurations. For details, see Table 1.
      Table 1 Parameters

      Parameter

      Description

      AI Application Source

      Select My AI Applications based on your requirements.

      AI Application and Version

      Select an AI application and version that are running properly.

      Input Path

      Select the OBS directory where the uploaded data is stored. Select a folder or a .manifest file. For details about the specifications of the .manifest file, see Manifest File Specifications.

      NOTE:
      • If the input data is an image, ensure that the size of a single image is less than 10 MB.
      • If the input data is in CSV format, ensure that no Chinese character is included.
      • If the input data is in CSV format, ensure that the file size does not exceed 12 MB.

      Output Path

      Select the path for saving the batch prediction result. You can select the empty folder that you create.

      Specifications

      Select available specifications based on the list displayed on the console. The specifications in gray cannot be used at the current region.

      Compute Nodes

      Set the number of instances for the current AI application version. If you set the number of nodes to 1, the standalone computing mode is used. If you set the number of nodes to a value greater than 1, the distributed computing mode is used. Select a computing mode based on the actual requirements.

      Environment Variable

      Set environment variables and inject them to the pod. To ensure data security, do not enter sensitive information in environment variables.

      Timeout

      Timeout of a single model, including both the deployment and startup time. The default value is 20 minutes. The value must range from 3 to 120.

  4. After setting the parameters, deploy the model as a batch service as prompted. Deploying a service generally requires a period of time, which may be several minutes or tens of minutes depending on the amount of your data and resources.

    You can go to the batch service list to view the basic information about the batch service. In the batch service list, after the status of the newly deployed service changes from Deploying to Running, the service is deployed successfully.

Manifest File Specifications

ModelArts batch services support manifest files, which describe data input and output.

Example input manifest file
  • File name: test.manifest
  • File content:
    {"source": "obs://test/data/1.jpg"}
    {"source": "s3://test/data/2.jpg"}
    {"source": "https://infers-data.obs.xxx.com:443/xgboosterdata/data.csv?AccessKeyId=2Q0V0TQ461N26DDL18RB&Expires=1550611914&Signature=wZBttZj5QZrReDhz1uDzwve8GpY%3D&x-obs-security-token=gQpzb3V0aGNoaW5hixvY8V9a1SnsxmGoHYmB1SArYMyqnQT-ZaMSxHvl68kKLAy5feYvLDM..."}
  • Requirements on the file:
    1. The file name extension must be .manifest.
    2. The file content is in JSON format. Each row describes a piece of input data, which must be accurate to a file instead of a folder.
    3. The value of source is the OBS file path in the format of <OBS path>/{{Bucket name}}/{{Object name}}.

Example output manifest file

A manifest file will be generated in the output directory of the batch services.
  • Assume that the output path is //test-bucket/test/. The result is stored in the following path:
    OBS bucket/directory name
    ├── test-bucket
    │   ├── test
    │   │   ├── infer-result-{{task_id}}.manifest
    │   │   ├── infer-result
    │   │   │ ├── 1.jpg_result.txt
    │   │   │ ├── 2.jpg_result.txt
  • Content of the infer-result-0.manifest file:
    {"source": "obs://obs-data-bucket/test/data/1.jpg","result":"SUCCESSFUL","inference-loc": "obs://test-bucket/test/infer-result/1.jpg_result.txt"}
    {"source": "s3://obs-data-bucket/test/data/2.jpg","result":"FAILED","error_message": "Download file failed."}
    {"source ": "https://infers-data.obs.xxx.com:443/xgboosterdata/2.jpg?AccessKeyId=2Q0V0TQ461N26DDL18RB&Expires=1550611914&Signature=wZBttZj5QZrReDhz1uDzwve8GpY%3D&x-obs-security-token=gQpzb3V0aGNoaW5hixvY8V9a1SnsxmGoHYmB1SArYMyqnQT-ZaMSxHvl68kKLAy5feYvLDMNZWxzhBZ6Q-3HcoZMh9gISwQOVBwm4ZytB_m8sg1fL6isU7T3CnoL9jmvDGgT9VBC7dC1EyfSJrUcqfB_N0ykCsfrA1Tt_IQYZFDu_HyqVk-GunUcTVdDfWlCV3TrYcpmznZjliAnYUO89kAwCYGeRZsCsC0ePu4PHMsBvYV9gWmN9AUZIDn1sfRL4voBpwQnp6tnAgHW49y5a6hP2hCAoQ-95SpUriJ434QlymoeKfTHVMKOeZxZea-JxOvevOCGI5CcGehEJaz48sgH81UiHzl21zocNB_hpPfus2jY6KPglEJxMv6Kwmro-ZBXWuSJUDOnSYXI-3ciYjg9-h10b8W3sW1mOTFCWNGoWsd74it7l_5-7UUhoIeyPByO_REwkur2FOJsuMpGlRaPyglZxXm_jfdLFXobYtzZhbul4yWXga6oxTOkfcwykTOYH0NPoPRt5MYGYweOXXxFs3d5w2rd0y7p0QYhyTzIkk5CIz7FlWNapFISL7zdhsl8RfchTqESq94KgkeqatSF_iIvnYMW2r8P8x2k_eb6NJ7U_q5ztMbO9oWEcfr0D2f7n7Bl_nb2HIB_H9tjzKvqwngaimYhBbMRPfibvttW86GiwVP8vrC27FOn39Be9z2hSfJ_8pHej0yMlyNqZ481FQ5vWT_vFV3JHM-7I1ZB0_hIdaHfItm-J69cTfHSEOzt7DGaMIES1o7U3w%3D%3D","result":"SUCCESSFUL","inference-loc": "obs://test-bucket/test/infer-result/2.jpg_result.txt"}
  • File format:
    1. The file name is infer-result-{{task_id}}.manifest, where task_id is the batch task ID, which is unique for a batch service.
    2. If a large number of files need to be processed, multiple manifest files may be generated with the same suffix .manifest and are distinguished by suffix, for example, infer-result-{{task_id}}_1.manifest.
    3. The infer-result-{{task_id}} directory is created in the manifest directory to store the file processing result.
    4. The file content is in JSON format. Each row describes the output result of a piece of input data.
    5. The file contains multiple fields:
      1. source: input data description, which is the same as that of the input manifest file
      2. result: file processing result, which can be SUCCESSFUL or FAILED
      3. inference-loc: output result path. This field is available when result is SUCCESSFUL. The format is obs://{{Bucket name}}/{Object name}.
      4. error_message: error information. This field is available when the result is FAILED.

Example Mapping

The following example shows the relationship between the configuration file, mapping rule, CSV data, and inference request.

The following uses a file for prediction as an example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
[
    {
        "method": "post",
        "url": "/",
        "request": {
            "Content-type": "multipart/form-data",
            "data": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "req_data": {
                                "type": "array",
                                "items": [
                                    {
                                        "type": "object",
                                        "properties": {
                                            "input_1": {
                                                "type": "number"
                                            },
                                            "input_2": {
                                                "type": "number"
                                            },
                                            "input_3": {
                                                "type": "number"
                                            },
                                            "input_4": {
                                                "type": "number"
                                            }
                                        }
                                    }
                                ]
                            }
                        }
                    }
                }
            }
        }
    }
]

The ModelArts management console automatically resolves the mapping relationship from the configuration file as shown below. When calling a ModelArts API, configure the mapping by following the rule.

{
    "type": "object",
    "properties": {
        "data": {
            "type": "object",
            "properties": {
                "req_data": {
                    "type": "array",
                    "items": [
                        {
                            "type": "object",
                            "properties": {
                                "input_1": {
                                    "type": "number",
                                    "index": 0
                                },
                                "input_2": {
                                    "type": "number",
                                    "index": 1
                                },
                                "input_3": {
                                    "type": "number",
                                    "index": 2
                                },
                                "input_4": {
                                    "type": "number",
                                    "index": 3
                                }
                            }
                        }
                    ]
                }
            }
        }
    }
}

Multiple pieces of CSV data for inference are separated by commas (,) The following shows an example:

5.1,3.5,1.4,0.2
4.9,3.0,1.4,0.2
4.7,3.2,1.3,0.2

Depending on the defined mapping relationship, the inference request is shown below, whose format is similar to that for real-time services.

{
	"data": {
		"req_data": [{
			"input_1": 5.1,
			"input_2": 3.5,
			"input_3": 1.4,
			"input_4": 0.2
		}]
	}
}