Single-Operator Description File Template
Different input or format scenarios may require different configurations for a single-operator description file. This section provides configuration examples for these scenarios.
The operators in this section are defined in Ascend IR, and the description file is in JSON format. For details about the parameters in the JSON description file, see Description File Parameters. For details about the definition of a single-operator, see Operator Acceleration Library API Reference.
- If format = ND:
In this example, the offline model converted from the single-operator is add.om.
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
[ { "op": "Add", "name": "add", "input_desc": [ { "format": "ND", "shape": [3,3], "type": "int32" }, { "format": "ND", "shape": [3,3], "type": "int32" } ], "output_desc": [ { "format": "ND", "shape": [3,3], "type": "int32" } ] } ]
- If format = NCHW:In this example, the offline model converted from the single-operator is conv2d.om.
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 42
[ { "op": "Conv2D", "name": "conv2d", "input_desc": [ { "format": "NCHW", "shape": [1, 3, 16, 16], "type": "float16" }, { "format": "NCHW", "shape": [3, 3, 3, 3], "type": "float16" } ], "output_desc": [ { "format": "NCHW", "shape": [1, 3, 16, 16], "type": "float16" } ], "attr": [ { "name": "strides", "type": "list_int", "value": [1, 1, 1, 1] }, { "name": "pads", "type": "list_int", "value": [1, 1, 1, 1] }, { "name": "dilations", "type": "list_int", "value": [1, 1, 1, 1] } ] } ]
- The tensor's format is changed after it is implemented.
During ATC model conversion, origin_format and origin_shape are converted into format and shape required by the offline model.
In this example, the offline model converted from the single-operator is add.om.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
[ { "op": "Add", "name": "add", "input_desc": [ { "format": "NC1HWC0", "origin_format": "NCHW", "shape": [8, 1, 16, 4, 16], "origin_shape": [8, 16, 16, 4], "type": "float16" }, { "format": "NC1HWC0", "origin_format": "NCHW", "shape": [8, 1, 16, 4, 16], "origin_shape": [8, 16, 16, 4], "type": "float16" } ], "output_desc": [ { "format": "NC1HWC0", "origin_format": "NCHW", "shape": [8, 1, 16, 4, 16], "origin_shape": [8, 16, 16, 4], "type": "float16" } ] } ]
- The input is specified as a constant.
In this scenario, the input can be set to a constant. is_const and const_value are newly added, indicating whether the input is a constant and the constant value, respectively. Currently, const_value supports only a one-dimensional list. The number of lists to configure is determined by the value of shape. For example, in the following example, the value of shape is 2, indicating that there are two lists in const_value. The data type of const_value is determined by type. If type is set to float16, single-operator build automatically converts const_value to the float16 format.
In this example, the offline model converted from the single-operator is resizeBilinearV2.om.
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55
[ { "op": "ResizeBilinearV2", "name": "resizeBilinearV2", "input_desc": [ { "format": "NHWC", "name": "x", "shape": [ 4, 16, 16, 16 ], "type": "float16" }, { "format": "NHWC", "is_const": true, "const_value": [49, 49], "name": "size", "shape": [ 2 ], "type": "int32", "test": [7, 7.0] } ], "output_desc": [ { "format": "NHWC", "name": "y", "shape": [ 4, 48, 48, 16 ], "type": "float" } ], "attr": [ { "name": "align_corners", "type": "bool", "value": false }, { "name": "half_pixel_centers", "type": "bool", "value": false } ] } ]
- Optional input:
For any unspecified optional input, set format to RESERVED and set type to UNDEFINED; for any specified optional input, set format and type to the actual values.
In this example, the offline model converted from the single-operator is matMulV2.om.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 42 43 44 45 46 47
[ { "op": "MatMulV2", "name": "matMulV2", "input_desc": [ { "format": "ND", "shape": [16, 16], "type": "float" }, { "format": "ND", "shape": [16, 16], "type": "float" }, { "format": "RESERVED", "shape": [], "type": "UNDEFINED" }, { "format": "RESERVED", "shape": [], "type": "UNDEFINED" } ], "attr": [ { "name": "transpose_x1", "type": "bool", "value": false }, { "name": "transpose_x2", "type": "bool", "value": false } ], "output_desc": [ { "format": "ND", "shape": [16, 16], "type": "float" } ] } ]
- Unfixed number of inputs (dynamic inputs):
In this scenario, the number of inputs of a single-operator is unfixed. The AddN operator is used as an example.
In this example, the offline model converted from the single-operator is addN.om.
- If the constructed single-operator JSON file uses the dynamic_input parameter instead of the name parameter of the tensor:
The value of dynamic_input must be the same as the name field defined in the operator information library.
The number of inputs for AddN is specified by the N attribute in its single-operator description file. You can add or remove inputs, as long as the input number matches the value of N. (The description file is specific to individual operators, and therefore AddN's description file takes effect only for the AddN operator.)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
[ { "op": "AddN", "name": "addN", "input_desc": [ { "dynamic_input": "x", "format": "NCHW", "shape": [1,3,166,166], "type": "float32" }, { "dynamic_input": "x", "format": "NCHW", "shape": [1,3,166,166], "type": "int32" }, { "dynamic_input": "x", "format": "NCHW", "shape": [1,3,166,166], "type": "float32" } ], "output_desc": [ { "format": "NCHW", "shape": [1,3,166,166], "type": "float32" } ], "attr": [ { "name": "N", "type": "int", "value": 3 } ] } ]
- If your single-operator JSON file uses the name parameter of the tensor instead of the dynamic_input parameter:
The value of name must be the same as the input name in the operator prototype definition and the names will be automatically indexed as x0, x1, x2, ... based on the number of inputs.
The number of tensor names for AddN is specified by the N attribute in its single-operator description file. You can add or remove tensor names, as long as the tensor name number matches the value of N. For example, if N is set to 3, the name fields should be x0, x1, and x2, respectively. (The description file is specific to individual operators, and therefore AddN's description file takes effect only for the AddN operator.)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
[ { "op": "AddN", "name": "addN", "input_desc": [ { "name":"x0", "format": "NCHW", "shape": [1,3,166,166], "type": "float32" }, { "name":"x1", "format": "NCHW", "shape": [1,3,166,166], "type": "int32" }, { "name":"x2" "format": "NCHW", "shape": [1,3,166,166], "type": "float32", } ], "output_desc": [ { "format": "NCHW", "shape": [1,3,166,166], "type": "float32" } ], "attr": [ { "name": "N", "type": "int", "value": 3 } ] } ]
- If the constructed single-operator JSON file uses the dynamic_input parameter instead of the name parameter of the tensor: