AI开发平台MODELARTS-将模型部署为批量推理服务:映射关系示例

时间:2024-08-16 20:39:03

映射关系示例

如下示例展示了配置文件、映射规则、csv数据以及最终推理请求的关系。

假设,您的模型所用配置文件,其apis参数如下所示:

 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"
                                            }
                                        }
                                    }
                                ]
                            }
                        }
                    }
                }
            }
        }
    }
]

此时,其对应的映射关系如下所示。ModelArts管理控制台将从配置文件中自动解析映射关系,如果您调用ModelArts API时,需要自行根据规则编写映射关系。

{
    "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
                                }
                            }
                        }
                    ]
                }
            }
        }
    }
}

用户需要进行推理的数据,即 CS V数据,格式如下所示。数据必须以英文逗号隔开。

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

根据定义好的映射关系,最终推理请求样例如下所示,与在线服务使用的格式类似:

{
	"data": {
		"req_data": [{
			"input_1": 5.1,
			"input_2": 3.5,
			"input_3": 1.4,
			"input_4": 0.2
		}]
	}
}
support.huaweicloud.com/usermanual-standard-modelarts/inference-modelarts-0039.html