1/** 2 * Copyright 2019 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17syntax = "proto2"; 18 19package mindspore.irpb; 20 21 22// Versioning 23enum Version { 24 // unknown version 25 UNKNOWWN_VERSION = 0; 26 27 // Initial version (IR VERSION 1), published on Sep 23, 2019 28 IR_VERSION = 0x0000000000000001; 29} 30 31// Data type definition 32enum DataType { 33 DT_UNDEFINED = 0; 34 // Basic types. 35 DT_BOOL = 1; // bool 36 37 DT_INT8 = 2; // int8_t 38 DT_INT16 = 3; // int16_t 39 DT_INT32 = 4; // int32_t 40 DT_INT64 = 5; // int64_t 41 42 DT_UINT8 = 6; // uint8_t 43 DT_UINT16 = 7; // uint16_t 44 DT_UINT32 = 8; // uint32_t 45 DT_UINT64 = 9; // uint64_t 46 47 DT_FLOAT16 = 10; // float 16 48 DT_FLOAT32 = 11; // float 32 49 DT_FLOAT64 = 12; // float 64 50 51 DT_STRING = 13; // string 52 DT_TENSOR = 14; // tensor 53 DT_GRAPH = 15; // graph 54 55 // list type 56 DT_BOOLS = 16; // list of bool 57 58 DT_INTS8 = 17; // list of int8_t 59 DT_INTS16 = 18; // list of int16_t 60 DT_INTS32 = 19; // list of int32_t 61 DT_INTS64 = 20; // list of int64_t 62 63 DT_UINTS8 = 21; // list of uint8_t 64 DT_UINTS16 = 22; // list of uint16_t 65 DT_UINTS32 = 23; // list of uint32_t 66 DT_UINTS64 = 24; // list of uint64_t 67 68 DT_FLOATS16 = 25; // list of float16 69 DT_FLOATS32 = 26; // list of float32 70 DT_FLOATS64 = 27; // list of float64 71 72 DT_STRINGS = 28; // list of string 73 DT_TENSORS = 29; // list of tensor 74 DT_GRAPHS = 30; // list of graph 75 76 DT_TUPLE = 31; // tuple 77 DT_LIST = 32; // list 78 DT_DICT = 33; // dictionary 79 80 // other types 81 DT_NONE = 34; // None 82 DT_SYM_INST = 35; // Symbolic Key Instance 83 84 // type related type 85 DT_BASE_INT = 36; // type generic int 86 DT_BASE_UINT = 37; // type generate unsigned int 87 DT_BASE_FLOAT = 38; // type generate float 88 DT_TYPE = 39; // type type 89 DT_ANYTHING = 40; // type anything 90 DT_REFKEY = 41; // type refkey 91 DT_REF = 42; // type ref 92 DT_COMPLEX64 = 43; // type generate complex64 93 DT_COMPLEX128 = 44; // type generate complex128 94} 95 96// Value definition for attribute value or parameter default value 97message ValueProto { 98 // data type of value 99 optional DataType dtype = 1; // discriminator that indicates which field below is in use 100 101 // Exactly ONE of the following fields must be present for this version of the IR 102 optional bool bool_val = 2; // bool 103 optional int64 int_val = 3; // int 104 optional uint64 uint_val = 4; // uint 105 optional float float_val = 5; // float 106 optional double double_val = 6; // double 107 optional string str_val = 7; // string 108 optional TensorProto tensor_val = 8; // tensor value 109 optional GraphProto graph = 9; // graph 110 111 repeated bool bool_vals = 10; // list of bool 112 repeated int64 int_vals = 11; // list of int 113 repeated uint64 uint_vals = 12; // list of uint 114 repeated float float_vals = 13; // list of float 115 repeated double double_vals = 14; // list of double 116 repeated string str_vals = 15; // list of string 117 repeated TensorProto tensor_vals = 16; // list of tensor value 118 repeated GraphProto graphs = 17; // list of graph 119 120 // tuple or list 121 repeated ValueProto values = 18; // tuple, list of value 122 123 // dictionary 124 repeated NamedValueProto dict_val = 19; // dictionary info 125 126 // filed for type type 127 optional TypeProto type_val = 20; // type type info 128} 129 130message AttributeProto { 131 optional string name = 1; // attribute name 132 optional ValueProto value = 2; // attribute value 133} 134 135message NamedValueProto { 136 optional string key = 1; // attribute name 137 optional ValueProto value = 2; // attribute value 138} 139 140// Defines a tensor shape. 141message TensorShapeProto { 142 // One dimension of the tensor. 143 message Dimension { 144 // Size of the tensor in that dimension. 145 // This value must be >= -1, but values of -1 are reserved for "unknown" 146 // shapes (values of -1 mean "unknown" dimension). 147 optional int64 size = 1; 148 149 // Optional name of the tensor dimension. 150 optional string name = 2; 151 }; 152 153 repeated Dimension dim = 1; 154} 155 156// Types for graph input(parameter) and output 157message TypeProto { 158 159 message Tensor { 160 // This field MUST have a valid DataType value except DT_TENSOR 161 optional DataType elem_type = 1; 162 optional TensorShapeProto shape = 2; // for scalar, this field is not set 163 } 164 165 // tuple type 166 message Sequence { 167 // The type and optional shape of elements of the tuple. 168 repeated TypeProto elem_types = 1; 169 }; 170 171 // data type 172 optional DataType data_type = 1; 173 174 oneof value { 175 // The type of a tensor. 176 Tensor tensor_type = 2; 177 178 // The type of a tuple. 179 Sequence sequence_type = 3; 180 } 181} 182 183// Defines information on graph parameters, including the name, the type, and 184// the default value of parameter if exists. 185message ParameterProto { 186 optional string name = 1; // parameter name 187 optional TypeProto type = 2; // parameter type 188 optional ValueProto default_val = 3; // default value of parameter if exists 189} 190 191// Defines graph output information 192message OutputProto { 193 optional string name = 1; // output node name 194 optional TypeProto type = 2; // output node type 195} 196 197// Define node input information 198message InputProto { 199 enum EdgeType { 200 DATA_EDGE = 0; // data edge 201 CONTROL_EDGE = 1; // control edge 202 } 203 204 optional string name = 1; 205 optional EdgeType type = 2; 206} 207 208// Nodes 209// 210// Computation graphs are made up of a DAG of nodes, which represent what is 211// commonly called a "layer" or "pipeline stage" in machine learning frameworks. 212// 213// For example, it can be a node of type "Conv" that takes in an image, a filter 214// tensor and a bias tensor, and produces the convolved output. 215message NodeProto { 216 repeated InputProto input = 1; // namespace Value 217 optional string name = 2; // namespace Value 218 219 // The symbolic identifier of the Operator to execute. 220 optional string op_type = 3; // namespace Operator 221 // The domain of the OperatorSet that specifies the operator named by op_type. 222 optional string scope = 4; // namespace Domain 223 224 // Additional named attributes. 225 repeated AttributeProto attribute = 5; 226 227 // Optional type info of this node 228 optional TypeProto output_type = 6; 229 230 // other fields for debug 231 optional uint64 output_i = 7; 232 233 // The full_name_with_scope of CNode 234 optional string full_name = 8; 235} 236 237// Models 238// 239// ModelProto is a top-level file/container format for bundling a ML model and 240// associating its computation graph with metadata. 241// 242// The semantics of the model are described by the associated GraphProto. 243message ModelProto { 244 // ir version 245 optional int64 ir_version = 1; 246 247 // Domain name of the model. 248 // We use reverse domain names as name space indicators. For example: 249 // `com.facebook.fair` or `com.microsoft.cognitiveservices` 250 // 251 // Together with `model_version` and GraphProto.name, this forms the unique identity of 252 // the graph. 253 optional string domain = 2; 254 255 // The version of the graph encoded. See Version enum below. 256 optional int64 model_version = 3; 257 258 // The parameterized graph that is evaluated to execute the model. 259 optional GraphProto graph = 4; 260 261 // metadata info of operators 262 optional OperatorSetProto metadata_operators = 5; 263}; 264 265message OperatorProto { 266 optional string name = 1; // used as key, must be distinct 267 optional bytes config = 2; // operator config info 268 optional bytes obj_info = 3; // operator related object info, e.g. content of operator binary or name 269}; 270 271message OperatorSetProto { 272 repeated OperatorProto operators = 1; 273 optional string summary = 2; // summary info of operators, e.g. file position of operators file 274} 275 276// Graphs 277// 278// A graph defines the computational logic of a model and is comprised of a parameterized 279// list of nodes that form a directed acyclic graph based on their inputs and outputs. 280// This is the equivalent of the "network" or "graph" in many deep learning 281// frameworks. 282message GraphProto { 283 // The nodes in the graph, sorted topologically. 284 repeated NodeProto node = 1; 285 286 // The name of the graph. 287 optional string name = 2; // namespace Graph 288 289 // The parameters(inputs) and outputs of the graph. 290 repeated ParameterProto parameters = 3; 291 repeated OutputProto outputs = 4; 292 293 // Constants used in this graph 294 repeated NamedValueProto const_vals = 5; 295} 296 297// Tensors 298// 299// A serialized tensor value. 300message TensorProto { 301 // The shape of the tensor. 302 repeated int64 dims = 1; 303 304 // The data type of the tensor. 305 // This field MUST have a valid DataType value except DT_TENSOR 306 optional DataType data_type = 2; 307 308 // Tensor content must be organized in row-major order. 309 // 310 // Depending on the data_type field, exactly one of the fields below with 311 // name ending in _data is used to store the elements of the tensor. 312 313 // For float values 314 repeated float float_data = 3 [packed = true]; 315 316 // For int32, uint8, int8, uint16, int16, and bool values 317 // When this field is present, the data_type field MUST be 318 // INT32, INT16, INT8, UINT16, UINT8, or BOOL 319 repeated int32 int32_data = 4 [packed = true]; 320 321 // For int64. 322 // When this field is present, the data_type field MUST be INT64 323 repeated int64 int64_data = 5 [packed = true]; 324 325 // For double 326 // When this field is present, the data_type field MUST be DOUBLE 327 repeated double double_data = 6 [packed = true]; 328 329 // For uint64 and uint32 values 330 // When this field is present, the data_type field MUST be 331 // UINT32 or UINT64 332 repeated uint64 uint64_data = 7 [packed = true]; 333 334 // Store raw tensor content. When this raw_data field is used to store tensor value, 335 // elements MUST be stored in as fixed-width, little-endian order. 336 optional bytes raw_data = 8; 337} 338