| 1 | // |
| 2 | // WARNING: This file is automatically generated! Please edit onnx.in.proto. |
| 3 | // |
| 4 | |
| 5 | |
| 6 | // Copyright (c) ONNX Project Contributors. |
| 7 | // Licensed under the MIT license. |
| 8 | |
| 9 | syntax = "proto2"; |
| 10 | |
| 11 | package onnx; |
| 12 | |
| 13 | // Overview |
| 14 | // |
| 15 | // ONNX is an open specification that is comprised of the following components: |
| 16 | // |
| 17 | // 1) A definition of an extensible computation graph model. |
| 18 | // 2) Definitions of standard data types. |
| 19 | // 3) Definitions of built-in operators. |
| 20 | // |
| 21 | // This document describes the syntax of models and their computation graphs, |
| 22 | // as well as the standard data types. Together, they are referred to as the ONNX |
| 23 | // Intermediate Representation, or 'IR' for short. |
| 24 | // |
| 25 | // The normative semantic specification of the ONNX IR is found in docs/IR.md. |
| 26 | // Definitions of the built-in neural network operators may be found in docs/Operators.md. |
| 27 | |
| 28 | // Notes |
| 29 | // |
| 30 | // Release |
| 31 | // |
| 32 | // We are still in the very early stage of defining ONNX. The current |
| 33 | // version of ONNX is a starting point. While we are actively working |
| 34 | // towards a complete spec, we would like to get the community involved |
| 35 | // by sharing our working version of ONNX. |
| 36 | // |
| 37 | // Protobuf compatibility |
| 38 | // |
| 39 | // To simplify framework compatibility, ONNX is defined using the subset of protobuf |
| 40 | // that is compatible with both protobuf v2 and v3. This means that we do not use any |
| 41 | // protobuf features that are only available in one of the two versions. |
| 42 | // |
| 43 | // Here are the most notable contortions we have to carry out to work around |
| 44 | // these limitations: |
| 45 | // |
| 46 | // - No 'map' (added protobuf 3.0). We instead represent mappings as lists |
| 47 | // of key-value pairs, where order does not matter and duplicates |
| 48 | // are not allowed. |
| 49 | |
| 50 | |
| 51 | // Versioning |
| 52 | // |
| 53 | // ONNX versioning is specified in docs/IR.md and elaborated on in docs/Versioning.md |
| 54 | // |
| 55 | // To be compatible with both proto2 and proto3, we will use a version number |
| 56 | // that is not defined by the default value but an explicit enum number. |
| 57 | enum Version { |
| 58 | // proto3 requires the first enum value to be zero. |
| 59 | // We add this just to appease the compiler. |
| 60 | _START_VERSION = 0; |
| 61 | // The version field is always serialized and we will use it to store the |
| 62 | // version that the graph is generated from. This helps us set up version |
| 63 | // control. |
| 64 | // For the IR, we are using simple numbers starting with with 0x00000001, |
| 65 | // which was the version we published on Oct 10, 2017. |
| 66 | IR_VERSION_2017_10_10 = 0x0000000000000001; |
| 67 | |
| 68 | // IR_VERSION 2 published on Oct 30, 2017 |
| 69 | // - Added type discriminator to AttributeProto to support proto3 users |
| 70 | IR_VERSION_2017_10_30 = 0x0000000000000002; |
| 71 | |
| 72 | // IR VERSION 3 published on Nov 3, 2017 |
| 73 | // - For operator versioning: |
| 74 | // - Added new message OperatorSetIdProto |
| 75 | // - Added opset_import in ModelProto |
| 76 | // - For vendor extensions, added domain in NodeProto |
| 77 | IR_VERSION_2017_11_3 = 0x0000000000000003; |
| 78 | |
| 79 | // IR VERSION 4 published on Jan 22, 2019 |
| 80 | // - Relax constraint that initializers should be a subset of graph inputs |
| 81 | // - Add type BFLOAT16 |
| 82 | IR_VERSION_2019_1_22 = 0x0000000000000004; |
| 83 | |
| 84 | // IR VERSION 5 published on March 18, 2019 |
| 85 | // - Add message TensorAnnotation. |
| 86 | // - Add quantization annotation in GraphProto to map tensor with its scale and zero point quantization parameters. |
| 87 | IR_VERSION = 0x0000000000000005; |
| 88 | } |
| 89 | |
| 90 | // Attributes |
| 91 | // |
| 92 | // A named attribute containing either singular float, integer, string, graph, |
| 93 | // and tensor values, or repeated float, integer, string, graph, and tensor values. |
| 94 | // An AttributeProto MUST contain the name field, and *only one* of the |
| 95 | // following content fields, effectively enforcing a C/C++ union equivalent. |
| 96 | message AttributeProto { |
| 97 | |
| 98 | // Note: this enum is structurally identical to the OpSchema::AttrType |
| 99 | // enum defined in schema.h. If you rev one, you likely need to rev the other. |
| 100 | enum AttributeType { |
| 101 | UNDEFINED = 0; |
| 102 | FLOAT = 1; |
| 103 | INT = 2; |
| 104 | STRING = 3; |
| 105 | TENSOR = 4; |
| 106 | GRAPH = 5; |
| 107 | |
| 108 | FLOATS = 6; |
| 109 | INTS = 7; |
| 110 | STRINGS = 8; |
| 111 | TENSORS = 9; |
| 112 | GRAPHS = 10; |
| 113 | } |
| 114 | |
| 115 | // The name field MUST be present for this version of the IR. |
| 116 | optional string name = 1; // namespace Attribute |
| 117 | |
| 118 | // if ref_attr_name is not empty, ref_attr_name is the attribute name in parent function. |
| 119 | // In this case, this AttributeProto does not contain data, and it's a reference of attribute |
| 120 | // in parent scope. |
| 121 | // NOTE: This should ONLY be used in function (sub-graph). It's invalid to be used in main graph. |
| 122 | optional string ref_attr_name = 21; |
| 123 | |
| 124 | // A human-readable documentation for this attribute. Markdown is allowed. |
| 125 | optional string doc_string = 13; |
| 126 | |
| 127 | // The type field MUST be present for this version of the IR. |
| 128 | // For 0.0.1 versions of the IR, this field was not defined, and |
| 129 | // implementations needed to use has_field hueristics to determine |
| 130 | // which value field was in use. For IR_VERSION 0.0.2 or later, this |
| 131 | // field MUST be set and match the f|i|s|t|... field in use. This |
| 132 | // change was made to accommodate proto3 implementations. |
| 133 | optional AttributeType type = 20; // discriminator that indicates which field below is in use |
| 134 | |
| 135 | // Exactly ONE of the following fields must be present for this version of the IR |
| 136 | optional float f = 2; // float |
| 137 | optional int64 i = 3; // int |
| 138 | optional bytes s = 4; // UTF-8 string |
| 139 | optional TensorProto t = 5; // tensor value |
| 140 | optional GraphProto g = 6; // graph |
| 141 | // Do not use field below, it's deprecated. |
| 142 | // optional ValueProto v = 12; // value - subsumes everything but graph |
| 143 | |
| 144 | repeated float floats = 7; // list of floats |
| 145 | repeated int64 ints = 8; // list of ints |
| 146 | repeated bytes strings = 9; // list of UTF-8 strings |
| 147 | repeated TensorProto tensors = 10; // list of tensors |
| 148 | repeated GraphProto graphs = 11; // list of graph |
| 149 | } |
| 150 | |
| 151 | // Defines information on value, including the name, the type, and |
| 152 | // the shape of the value. |
| 153 | message ValueInfoProto { |
| 154 | // This field MUST be present in this version of the IR. |
| 155 | optional string name = 1; // namespace Value |
| 156 | // This field MUST be present in this version of the IR. |
| 157 | optional TypeProto type = 2; |
| 158 | // A human-readable documentation for this value. Markdown is allowed. |
| 159 | optional string doc_string = 3; |
| 160 | } |
| 161 | |
| 162 | // Nodes |
| 163 | // |
| 164 | // Computation graphs are made up of a DAG of nodes, which represent what is |
| 165 | // commonly called a "layer" or "pipeline stage" in machine learning frameworks. |
| 166 | // |
| 167 | // For example, it can be a node of type "Conv" that takes in an image, a filter |
| 168 | // tensor and a bias tensor, and produces the convolved output. |
| 169 | message NodeProto { |
| 170 | repeated string input = 1; // namespace Value |
| 171 | repeated string output = 2; // namespace Value |
| 172 | |
| 173 | // An optional identifier for this node in a graph. |
| 174 | // This field MAY be absent in ths version of the IR. |
| 175 | optional string name = 3; // namespace Node |
| 176 | |
| 177 | // The symbolic identifier of the Operator to execute. |
| 178 | optional string op_type = 4; // namespace Operator |
| 179 | // The domain of the OperatorSet that specifies the operator named by op_type. |
| 180 | optional string domain = 7; // namespace Domain |
| 181 | |
| 182 | // Additional named attributes. |
| 183 | repeated AttributeProto attribute = 5; |
| 184 | |
| 185 | // A human-readable documentation for this node. Markdown is allowed. |
| 186 | optional string doc_string = 6; |
| 187 | } |
| 188 | |
| 189 | // Models |
| 190 | // |
| 191 | // ModelProto is a top-level file/container format for bundling a ML model and |
| 192 | // associating its computation graph with metadata. |
| 193 | // |
| 194 | // The semantics of the model are described by the associated GraphProto. |
| 195 | message ModelProto { |
| 196 | // The version of the IR this model targets. See Version enum above. |
| 197 | // This field MUST be present. |
| 198 | optional int64 ir_version = 1; |
| 199 | |
| 200 | // The OperatorSets this model relies on. |
| 201 | // All ModelProtos MUST have at least one entry that |
| 202 | // specifies which version of the ONNX OperatorSet is |
| 203 | // being imported. |
| 204 | // |
| 205 | // All nodes in the ModelProto's graph will bind against the operator |
| 206 | // with the same-domain/same-op_type operator with the HIGHEST version |
| 207 | // in the referenced operator sets. |
| 208 | repeated OperatorSetIdProto opset_import = 8; |
| 209 | |
| 210 | // The name of the framework or tool used to generate this model. |
| 211 | // This field SHOULD be present to indicate which implementation/tool/framework |
| 212 | // emitted the model. |
| 213 | optional string producer_name = 2; |
| 214 | |
| 215 | // The version of the framework or tool used to generate this model. |
| 216 | // This field SHOULD be present to indicate which implementation/tool/framework |
| 217 | // emitted the model. |
| 218 | optional string producer_version = 3; |
| 219 | |
| 220 | // Domain name of the model. |
| 221 | // We use reverse domain names as name space indicators. For example: |
| 222 | // `com.facebook.fair` or `com.microsoft.cognitiveservices` |
| 223 | // |
| 224 | // Together with `model_version` and GraphProto.name, this forms the unique identity of |
| 225 | // the graph. |
| 226 | optional string domain = 4; |
| 227 | |
| 228 | // The version of the graph encoded. See Version enum below. |
| 229 | optional int64 model_version = 5; |
| 230 | |
| 231 | // A human-readable documentation for this model. Markdown is allowed. |
| 232 | optional string doc_string = 6; |
| 233 | |
| 234 | // The parameterized graph that is evaluated to execute the model. |
| 235 | optional GraphProto graph = 7; |
| 236 | |
| 237 | // Named metadata values; keys should be distinct. |
| 238 | repeated StringStringEntryProto metadata_props = 14; |
| 239 | }; |
| 240 | |
| 241 | // StringStringEntryProto follows the pattern for cross-proto-version maps. |
| 242 | // See https://developers.google.com/protocol-buffers/docs/proto3#maps |
| 243 | message StringStringEntryProto { |
| 244 | optional string key = 1; |
| 245 | optional string value= 2; |
| 246 | }; |
| 247 | |
| 248 | message TensorAnnotation { |
| 249 | optional string tensor_name = 1; |
| 250 | // <key, value> pairs to annotate tensor specified by <tensor_name> above. |
| 251 | // The keys used in the mapping below must be pre-defined in ONNX spec. |
| 252 | // For example, for 8-bit linear quantization case, 'SCALE_TENSOR', 'ZERO_POINT_TENSOR' will be pre-defined as |
| 253 | // quantization parameter keys. |
| 254 | repeated StringStringEntryProto quant_parameter_tensor_names = 2; |
| 255 | } |
| 256 | |
| 257 | |
| 258 | |
| 259 | // Graphs |
| 260 | // |
| 261 | // A graph defines the computational logic of a model and is comprised of a parameterized |
| 262 | // list of nodes that form a directed acyclic graph based on their inputs and outputs. |
| 263 | // This is the equivalent of the "network" or "graph" in many deep learning |
| 264 | // frameworks. |
| 265 | message GraphProto { |
| 266 | // The nodes in the graph, sorted topologically. |
| 267 | repeated NodeProto node = 1; |
| 268 | |
| 269 | // The name of the graph. |
| 270 | optional string name = 2; // namespace Graph |
| 271 | |
| 272 | // A list of named tensor values, used to specify constant inputs of the graph. |
| 273 | // Each TensorProto entry must have a distinct name (within the list) that |
| 274 | // MAY also appear in the input list. |
| 275 | repeated TensorProto initializer = 5; |
| 276 | |
| 277 | // A human-readable documentation for this graph. Markdown is allowed. |
| 278 | optional string doc_string = 10; |
| 279 | |
| 280 | // The inputs and outputs of the graph. |
| 281 | repeated ValueInfoProto input = 11; |
| 282 | repeated ValueInfoProto output = 12; |
| 283 | |
| 284 | // Information for the values in the graph. The ValueInfoProto.name's |
| 285 | // must be distinct. It is optional for a value to appear in value_info list. |
| 286 | repeated ValueInfoProto value_info = 13; |
| 287 | |
| 288 | // This field carries information to indicate the mapping among a tensor and its |
| 289 | // quantization parameter tensors. For example: |
| 290 | // For tensor 'a', it may have {'SCALE_TENSOR', 'a_scale'} and {'ZERO_POINT_TENSOR', 'a_zero_point'} annotated, |
| 291 | // which means, tensor 'a_scale' and tensor 'a_zero_point' are scale and zero point of tensor 'a' in the model. |
| 292 | repeated TensorAnnotation quantization_annotation = 14; |
| 293 | |
| 294 | // DO NOT USE the following fields, they were deprecated from earlier versions. |
| 295 | // repeated string input = 3; |
| 296 | // repeated string output = 4; |
| 297 | // optional int64 ir_version = 6; |
| 298 | // optional int64 producer_version = 7; |
| 299 | // optional string producer_tag = 8; |
| 300 | // optional string domain = 9; |
| 301 | } |
| 302 | |
| 303 | // Tensors |
| 304 | // |
| 305 | // A serialized tensor value. |
| 306 | message TensorProto { |
| 307 | enum DataType { |
| 308 | UNDEFINED = 0; |
| 309 | // Basic types. |
| 310 | FLOAT = 1; // float |
| 311 | UINT8 = 2; // uint8_t |
| 312 | INT8 = 3; // int8_t |
| 313 | UINT16 = 4; // uint16_t |
| 314 | INT16 = 5; // int16_t |
| 315 | INT32 = 6; // int32_t |
| 316 | INT64 = 7; // int64_t |
| 317 | STRING = 8; // string |
| 318 | BOOL = 9; // bool |
| 319 | |
| 320 | // IEEE754 half-precision floating-point format (16 bits wide). |
| 321 | // This format has 1 sign bit, 5 exponent bits, and 10 mantissa bits. |
| 322 | FLOAT16 = 10; |
| 323 | |
| 324 | DOUBLE = 11; |
| 325 | UINT32 = 12; |
| 326 | UINT64 = 13; |
| 327 | COMPLEX64 = 14; // complex with float32 real and imaginary components |
| 328 | COMPLEX128 = 15; // complex with float64 real and imaginary components |
| 329 | |
| 330 | // Non-IEEE floating-point format based on IEEE754 single-precision |
| 331 | // floating-point number truncated to 16 bits. |
| 332 | // This format has 1 sign bit, 8 exponent bits, and 7 mantissa bits. |
| 333 | BFLOAT16 = 16; |
| 334 | |
| 335 | // Future extensions go here. |
| 336 | } |
| 337 | |
| 338 | // The shape of the tensor. |
| 339 | repeated int64 dims = 1; |
| 340 | |
| 341 | // The data type of the tensor. |
| 342 | // This field MUST have a valid TensorProto.DataType value |
| 343 | optional int32 data_type = 2; |
| 344 | |
| 345 | // For very large tensors, we may want to store them in chunks, in which |
| 346 | // case the following fields will specify the segment that is stored in |
| 347 | // the current TensorProto. |
| 348 | message Segment { |
| 349 | optional int64 begin = 1; |
| 350 | optional int64 end = 2; |
| 351 | } |
| 352 | optional Segment segment = 3; |
| 353 | |
| 354 | // Tensor content must be organized in row-major order. |
| 355 | // |
| 356 | // Depending on the data_type field, exactly one of the fields below with |
| 357 | // name ending in _data is used to store the elements of the tensor. |
| 358 | |
| 359 | // For float and complex64 values |
| 360 | // Complex64 tensors are encoded as a single array of floats, |
| 361 | // with the real components appearing in odd numbered positions, |
| 362 | // and the corresponding imaginary component apparing in the |
| 363 | // subsequent even numbered position. (e.g., [1.0 + 2.0i, 3.0 + 4.0i] |
| 364 | // is encoded as [1.0, 2.0 ,3.0 ,4.0] |
| 365 | // When this field is present, the data_type field MUST be FLOAT or COMPLEX64. |
| 366 | repeated float float_data = 4 [packed = true]; |
| 367 | |
| 368 | // For int32, uint8, int8, uint16, int16, bool, and float16 values |
| 369 | // float16 values must be bit-wise converted to an uint16_t prior |
| 370 | // to writing to the buffer. |
| 371 | // When this field is present, the data_type field MUST be |
| 372 | // INT32, INT16, INT8, UINT16, UINT8, BOOL, or FLOAT16 |
| 373 | repeated int32 int32_data = 5 [packed = true]; |
| 374 | |
| 375 | // For strings. |
| 376 | // Each element of string_data is a UTF-8 encoded Unicode |
| 377 | // string. No trailing null, no leading BOM. The protobuf "string" |
| 378 | // scalar type is not used to match ML community conventions. |
| 379 | // When this field is present, the data_type field MUST be STRING |
| 380 | repeated bytes string_data = 6; |
| 381 | |
| 382 | // For int64. |
| 383 | // When this field is present, the data_type field MUST be INT64 |
| 384 | repeated int64 int64_data = 7 [packed = true]; |
| 385 | |
| 386 | // Optionally, a name for the tensor. |
| 387 | optional string name = 8; // namespace Value |
| 388 | |
| 389 | // A human-readable documentation for this tensor. Markdown is allowed. |
| 390 | optional string doc_string = 12; |
| 391 | |
| 392 | // Serializations can either use one of the fields above, or use this |
| 393 | // raw bytes field. The only exception is the string case, where one is |
| 394 | // required to store the content in the repeated bytes string_data field. |
| 395 | // |
| 396 | // When this raw_data field is used to store tensor value, elements MUST |
| 397 | // be stored in as fixed-width, little-endian order. |
| 398 | // Floating-point data types MUST be stored in IEEE 754 format. |
| 399 | // Complex64 elements must be written as two consecutive FLOAT values, real component first. |
| 400 | // Complex128 elements must be written as two consecutive DOUBLE values, real component first. |
| 401 | // Boolean type MUST be written one byte per tensor element (00000001 for true, 00000000 for false). |
| 402 | // |
| 403 | // Note: the advantage of specific field rather than the raw_data field is |
| 404 | // that in some cases (e.g. int data), protobuf does a better packing via |
| 405 | // variable length storage, and may lead to smaller binary footprint. |
| 406 | // When this field is present, the data_type field MUST NOT be STRING or UNDEFINED |
| 407 | optional bytes raw_data = 9; |
| 408 | |
| 409 | // Data can be stored inside the protobuf file using type-specific fields or raw_data. |
| 410 | // Alternatively, raw bytes data can be stored in an external file, using the external_data field. |
| 411 | // external_data stores key-value pairs describing data location. Recognized keys are: |
| 412 | // - "location" (required) - POSIX filesystem path relative to the directory where the ONNX |
| 413 | // protobuf model was stored |
| 414 | // - "offset" (optional) - position of byte at which stored data begins. Integer stored as string. |
| 415 | // Offset values SHOULD be multiples 4096 (page size) to enable mmap support. |
| 416 | // - "length" (optional) - number of bytes containing data. Integer stored as string. |
| 417 | // - "checksum" (optional) - SHA1 digest of file specified in under 'location' key. |
| 418 | repeated StringStringEntryProto external_data = 13; |
| 419 | |
| 420 | // Location of the data for this tensor. MUST be one of: |
| 421 | // - DEFAULT - data stored inside the protobuf message. Data is stored in raw_data (if set) otherwise in type-specified field. |
| 422 | // - EXTERNAL - data stored in an external location as described by external_data field. |
| 423 | enum DataLocation { |
| 424 | DEFAULT = 0; |
| 425 | EXTERNAL = 1; |
| 426 | } |
| 427 | |
| 428 | // If value not set, data is stored in raw_data (if set) otherwise in type-specified field. |
| 429 | optional DataLocation data_location = 14; |
| 430 | |
| 431 | // For double |
| 432 | // Complex128 tensors are encoded as a single array of doubles, |
| 433 | // with the real components appearing in odd numbered positions, |
| 434 | // and the corresponding imaginary component apparing in the |
| 435 | // subsequent even numbered position. (e.g., [1.0 + 2.0i, 3.0 + 4.0i] |
| 436 | // is encoded as [1.0, 2.0 ,3.0 ,4.0] |
| 437 | // When this field is present, the data_type field MUST be DOUBLE or COMPLEX128 |
| 438 | repeated double double_data = 10 [packed = true]; |
| 439 | |
| 440 | // For uint64 and uint32 values |
| 441 | // When this field is present, the data_type field MUST be |
| 442 | // UINT32 or UINT64 |
| 443 | repeated uint64 uint64_data = 11 [packed = true]; |
| 444 | } |
| 445 | |
| 446 | // Defines a tensor shape. A dimension can be either an integer value |
| 447 | // or a symbolic variable. A symbolic variable represents an unknown |
| 448 | // dimension. |
| 449 | message TensorShapeProto { |
| 450 | message Dimension { |
| 451 | oneof value { |
| 452 | int64 dim_value = 1; |
| 453 | string dim_param = 2; // namespace Shape |
| 454 | }; |
| 455 | // Standard denotation can optionally be used to denote tensor |
| 456 | // dimensions with standard semantic descriptions to ensure |
| 457 | // that operations are applied to the correct axis of a tensor. |
| 458 | // Refer to https://github.com/onnx/onnx/blob/master/docs/DimensionDenotation.md#denotation-definition |
| 459 | // for pre-defined dimension denotations. |
| 460 | optional string denotation = 3; |
| 461 | }; |
| 462 | repeated Dimension dim = 1; |
| 463 | } |
| 464 | |
| 465 | // Types |
| 466 | // |
| 467 | // The standard ONNX data types. |
| 468 | message TypeProto { |
| 469 | |
| 470 | message Tensor { |
| 471 | // This field MUST NOT have the value of UNDEFINED |
| 472 | // This field MUST have a valid TensorProto.DataType value |
| 473 | // This field MUST be present for this version of the IR. |
| 474 | optional int32 elem_type = 1; |
| 475 | optional TensorShapeProto shape = 2; |
| 476 | } |
| 477 | |
| 478 | |
| 479 | oneof value { |
| 480 | // The type of a tensor. |
| 481 | Tensor tensor_type = 1; |
| 482 | |
| 483 | } |
| 484 | |
| 485 | // An optional denotation can be used to denote the whole |
| 486 | // type with a standard semantic description as to what is |
| 487 | // stored inside. Refer to https://github.com/onnx/onnx/blob/master/docs/TypeDenotation.md#type-denotation-definition |
| 488 | // for pre-defined type denotations. |
| 489 | optional string denotation = 6; |
| 490 | } |
| 491 | |
| 492 | // Operator Sets |
| 493 | // |
| 494 | // OperatorSets are uniquely identified by a (domain, opset_version) pair. |
| 495 | message OperatorSetIdProto { |
| 496 | // The domain of the operator set being identified. |
| 497 | // The empty string ("") or absence of this field implies the operator |
| 498 | // set that is defined as part of the ONNX specification. |
| 499 | // This field MUST be present in this version of the IR when referring to any other operator set. |
| 500 | optional string domain = 1; |
| 501 | |
| 502 | // The version of the operator set being identified. |
| 503 | // This field MUST be present in this version of the IR. |
| 504 | optional int64 version = 2; |
| 505 | } |