Single-Operator JSON File Configuration
Configuration File Templates
A configuration file can define multiple sets of single-operator JSON configurations, each including the operator type, operator input and output information, and optional attributes. The following provides some configuration code examples. You can modify the examples as required.
Single-Operator JSON File Template
- If format = ND:
[ { "op": "GEMM", "input_desc": [ { "format": "ND", "shape": [16, 16], "type": "float16" }, { "format": "ND", "shape": [16, 16], "type": "float16" }, { "format": "ND", "shape": [16, 16], "type": "float16" }, { "format": "ND", "shape": [], "type": "float16" }, { "format": "ND", "shape": [], "type": "float16" } ], "output_desc": [ { "format": "ND", "shape": [16, 16], "type": "float16" } ], "attr": [ { "name": "transpose_a", "type": "bool", "value": false }, { "name": "transpose_b", "type": "bool", "value": false } ] } ]
- If format = NCHW:
[ { "op": "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] } ] } ]
Multi-Operator JSON File Template
[ { "op": "MatMul", "input_desc": [ { "format": "ND", "shape": [ 16, 16 ], "type": "float16" }, ... ], "output_desc": [ { "format": "ND", "shape": [ 16, 16 ], "type": "float16" } ], "attr": [ { "name": "alpha", "type": "float", "value": 1.0 }, ... ] }, { "op": "MatMul", "input_desc": [ { "format": "ND", "shape": [ 256, 256 ], "type": "float16" }, ... ], "output_desc": [ { "format": "ND", "shape": [ 256, 256 ], "type": "float16" } ], "attr": [ { "name": "alpha", "type": "float", "value": 1.0 }, ... ] } ]
Dynamic-Shape Single-Operator JSON File Template
In this scenario, single-operators come in the following types:
- The shape is not specified during model build. During model execution, the output shape can be inferred based on the input shape.
[ { "op": "Add", "input_desc": [ { "format": "ND", "shape": [-1,16], "shape_range": [[0, 32]], "type": "int64" }, { "format": "ND", "shape": [-1,16], "shape_range": [[0, 32]], "type": "int64" } ], "output_desc": [ { "format": "ND", "shape": [-1,16], "shape_range": [[0, 32]], "type": "int64" } ] } ]
- The shape is not specified during model build. During model execution, the output shape can be inferred based on the input shape and constant.
[ { "op": "TopK", "input_desc": [ { "format": "ND", "shape": [-1], "shape_range": [[1,-1]], "type": "int32" }, { "format": "ND", "shape": [], "type": "int32" } ], "output_desc": [ { "format": "ND", "shape": [-1], "shape_range": [[1,-1]], "type": "int32" }, { "format": "ND", "shape": [-1], "shape_range": [[1,-1]], "type": "int32" }], "attr": [ { "name": "sorted", "type": "bool", "value": true } ] } ]
- The shape is not specified during model build. During model execution, the output shape cannot be inferred based on the input shape, but the output shape range can be obtained.
[ { "op": "Where", "input_desc": [ { "format": "ND", "shape": [-1], "shape_range": [[1,-1]], "type": "int32" } ], "output_desc": [ { "format": "ND", "shape": [-1, 1], "shape_range": [[1,-1]], "type": "int64" } ] } ]
Parameters
The .json file consists of OpDesc arrays. The parameters are described as follows:
Attribute Name |
Type |
Description |
Required or Not |
---|---|---|---|
op |
string |
Operator type |
Yes |
input_desc |
TensorDesc array |
Operator input description |
Yes |
output_desc |
TensorDesc array |
Operator output description |
Yes |
attr |
Attr array |
Operator attributes |
Not |
Attribute Name |
Type |
Description |
---|---|---|
format |
string |
(Required) Tensor format, a format supported by the original operator framework. Currently, the supported formats are as follows:
|
type |
string |
(Required) Tensor data type. The supported types are as follows:
|
shape |
Array of ints |
(Required) Tensor shape, for example, [1, 224, 224, 3] The actual shape size (product of dimension sizes) cannot exceed the maximum int32 value, 214748364. |
name |
string |
(Optional) Tensor name If the operator input is dynamic, this field is required. For example, if the dynamic input definition of the ConcatD operator in the operator prototype is DYNAMIC_INPUT(input_values, ...), set this attribute to "input_values0", "input_values1", ... |
shape_range |
Array of int[2]s |
(Optional) Value range of an unknown dimension when the shape is dynamic. For example, for shape [16, –1, 20, –1], –1 indicates an unknown dimension. Assume that shape_range is [1,128], [1,-1], where, [1,128] indicates the value range from 1 to 128, corresponding to the value range of the first –1 dimension, [1,-1] indicates the value range from 1 to infinity, corresponding to the value range of the second –1 dimension. |
Attribute Name |
Type |
Description |
---|---|---|
name |
string |
(Required) Attribute name |
type |
string |
(Required) Attribute data type:
|
value |
Determined by the value of type |
(Required) Attribute value. Varies according to type.
|