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