Deploying a Model 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. You can enter a service name in the search box in the upper right corner and click to query the service.
Prerequisites¶
Data has been prepared. Specifically, you have created an AI application in the Normal state in ModelArts.
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.
Background¶
A maximum of 1,000 batch services can be created.
Based on the input request (JSON or other file) defined by the AI application, different parameter 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 other file, no mapping file is required.
Batch services can only be deployed in a public resource pool, but not a dedicated resource pool.
Procedure¶
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.
In the batch service list, click Deploy in the upper left corner. The Deploy page is displayed.
Set parameters for a batch service.
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.
Set other parameters, including AI application configurations. For details, see Table 1.
¶ Parameter
Description
AI Application Source
Select My AI Applications based on your requirements.
AI Application and Version
Select the AI application and version that are in the Normal state.
Input Path
Select the OBS directory where the data is to be uploaded. 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 format is CSV, you can convert the file encoding format using code, or open the CSV file using Notepad and set the encoding format in the window displayed after you click Save As.
Request Path
URI used for calling the AI application interface in a batch service, and also the request path of the AI application service. Its value is obtained from the url field of apis in the AI application configuration file.
Mapping Relationship
If the AI application input is in JSON format, the system automatically generates the mapping based on the configuration file corresponding to the AI application. If the AI application input is other file, mapping is not required.
Automatically generated mapping file. Enter the field index corresponding to each parameter in the CSV file. The index starts from 0.
Mapping rule: The mapping rule comes from the input parameter (request) in the model configuration file config.json. When type is set to string/number/integer/boolean, you are required to set the index parameter. For details about the mapping rule, see Example Mapping.
The index must be a positive integer starting from 0. If the value of index does not comply with the rule, this parameter is ignored in the request. After the mapping rule is configured, the corresponding CSV data must be separated by commas (,).
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 site.
Compute Nodes
Set the number of instances for the current AI application version. If you set Instances to 1, the standalone computing mode is used. If you set Instances 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, such as plaintext passwords, in environment variables.
After setting the parameters, deploy the model as a batch service as prompted. Generally, service deployment jobs run for a period of time, which may be several minutes or tens of minutes depending on the amount of your selected 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¶
Batch services of the inference platform support the manifest file. The manifest file describes the input and output of data.
Example input manifest file
File name: test.manifest
File content:
{"source": "<obs path>/test/data/1.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..."}
File requirements:
The file name extension must be .manifest.
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.
The source field value 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-{{index}}.manifest │ │ ├── infer-result │ │ │ ├── 1.jpg_result.txt │ │ │ ├── 2.jpg_result.txt
Content of the infer-result-0.manifest file:
{"source": "<obs path>/obs-data-bucket/test/data/1.jpg","inference-loc": "<obs path>/test-bucket/test/infer-result/1.jpg_result.txt"} {"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...", "inference-loc": "obs://test-bucket/test/infer-result/2.jpg_result.txt"}
File format:
The file name is infer-result-{{index}}.manifest, where index is the instance ID. Each running instance of a batch service generates a manifest file.
The infer-result directory is created in the manifest directory to store the file processing result.
The file content is in JSON format. Each row describes the output result of a piece of input data.
The content contains multiple fields:
source: input data description, which is the same as that of the input manifest file
inference-loc: output result path in the format of <obs path>/{{Bucket name}}/{{Object name}}
Example Mapping¶
The following example shows the relationship between the configuration file, mapping rule, CSV data, and inference request.
Assume that the apis parameter in the configuration file used by your model is as follows:
[
{
"protocol": "http",
"method": "post",
"url": "/",
"request": {
"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"
}
}
}
]
}
}
}
}
}
}
]
At this point, the corresponding mapping relationship is shown below. The ModelArts management console automatically resolves the mapping relationship from the configuration file. When calling a ModelArts API, write the mapping relationship by yourself according to 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
}
}
}
]
}
}
}
}
}
The data for inference, that is, the CSV data, is in the following format. The data must be separated by commas (,).
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. The format is similar to the format used by the real-time service.
{
"data": {
"req_data": [{
"input_1": 5.1,
"input_2": 3.5,
"input_3": 1.4,
"input_4": 0.2
}]
}
}