Elffuss BraidHub

kikocis/ncnn public

master · 36.8 KiBRawPermalink
1//
2// WARNING: This file is automatically generated! Please edit onnx.in.proto.
3//
4
5
6// SPDX-License-Identifier: Apache-2.0
7
8
9syntax = "proto2";
10
11package 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// Definitions of the built-in classical machine learning operators may be found in
28// docs/Operators-ml.md.
29
30// Notes
31//
32// Protobuf compatibility
33//
34// To simplify framework compatibility, ONNX is defined using the subset of protobuf
35// that is compatible with both protobuf v2 and v3. This means that we do not use any
36// protobuf features that are only available in one of the two versions.
37//
38// Here are the most notable contortions we have to carry out to work around
39// these limitations:
40//
41// - No 'map' (added protobuf 3.0). We instead represent mappings as lists
42// of key-value pairs, where order does not matter and duplicates
43// are not allowed.
44
45
46// Versioning
47//
48// ONNX versioning is specified in docs/IR.md and elaborated on in docs/Versioning.md
49//
50// To be compatible with both proto2 and proto3, we will use a version number
51// that is not defined by the default value but an explicit enum number.
52enum Version {
53 // proto3 requires the first enum value to be zero.
54 // We add this just to appease the compiler.
55 _START_VERSION = 0;
56 // The version field is always serialized and we will use it to store the
57 // version that the graph is generated from. This helps us set up version
58 // control.
59 // For the IR, we are using simple numbers starting with 0x00000001,
60 // which was the version we published on Oct 10, 2017.
61 IR_VERSION_2017_10_10 = 0x0000000000000001;
62
63 // IR_VERSION 2 published on Oct 30, 2017
64 // - Added type discriminator to AttributeProto to support proto3 users
65 IR_VERSION_2017_10_30 = 0x0000000000000002;
66
67 // IR VERSION 3 published on Nov 3, 2017
68 // - For operator versioning:
69 // - Added new message OperatorSetIdProto
70 // - Added opset_import in ModelProto
71 // - For vendor extensions, added domain in NodeProto
72 IR_VERSION_2017_11_3 = 0x0000000000000003;
73
74 // IR VERSION 4 published on Jan 22, 2019
75 // - Relax constraint that initializers should be a subset of graph inputs
76 // - Add type BFLOAT16
77 IR_VERSION_2019_1_22 = 0x0000000000000004;
78
79 // IR VERSION 5 published on March 18, 2019
80 // - Add message TensorAnnotation.
81 // - Add quantization annotation in GraphProto to map tensor with its scale and zero point quantization parameters.
82 IR_VERSION_2019_3_18 = 0x0000000000000005;
83
84 // IR VERSION 6 published on Sep 19, 2019
85 // - Add support for sparse tensor constants stored in model.
86 // - Add message SparseTensorProto
87 // - Add sparse initializers
88 IR_VERSION_2019_9_19 = 0x0000000000000006;
89
90 // IR VERSION 7 published on May 8, 2020
91 // - Add support to allow function body graph to rely on multiple external opreator sets.
92 // - Add a list to promote inference graph's initializers to global and
93 // mutable variables. Global variables are visible in all graphs of the
94 // stored models.
95 // - Add message TrainingInfoProto to store initialization
96 // method and training algorithm. The execution of TrainingInfoProto
97 // can modify the values of mutable variables.
98 // - Implicitly add inference graph into each TrainingInfoProto's algorithm.
99 IR_VERSION_2020_5_8 = 0x0000000000000007;
100
101 // IR VERSION 8 published on July 30, 2021
102 // Introduce TypeProto.SparseTensor
103 // Introduce TypeProto.Optional
104 // Added a list of FunctionProtos local to the model
105 // Deprecated since_version and operator status from FunctionProto
106 IR_VERSION_2021_7_30 = 0x0000000000000008;
107
108 // IR VERSION 9 published on May 5, 2023
109 // Added AttributeProto to FunctionProto so that default attribute values can be set.
110 // Added FLOAT8E4M3FN, FLOAT8E4M3FNUZ, FLOAT8E5M2, FLOAT8E5M2FNUZ.
111 IR_VERSION_2023_5_5 = 0x0000000000000009;
112
113 // IR VERSION 10 published on TBD
114 // Added UINT4, INT4.
115 IR_VERSION = 0x000000000000000A;
116}
117
118// Attributes
119//
120// A named attribute containing either singular float, integer, string, graph,
121// and tensor values, or repeated float, integer, string, graph, and tensor values.
122// An AttributeProto MUST contain the name field, and *only one* of the
123// following content fields, effectively enforcing a C/C++ union equivalent.
124message AttributeProto {
125 reserved 12, 16 to 19;
126 reserved "v";
127
128 // Note: this enum is structurally identical to the OpSchema::AttrType
129 // enum defined in schema.h. If you rev one, you likely need to rev the other.
130 enum AttributeType {
131 UNDEFINED = 0;
132 FLOAT = 1;
133 INT = 2;
134 STRING = 3;
135 TENSOR = 4;
136 GRAPH = 5;
137 SPARSE_TENSOR = 11;
138 TYPE_PROTO = 13;
139
140 FLOATS = 6;
141 INTS = 7;
142 STRINGS = 8;
143 TENSORS = 9;
144 GRAPHS = 10;
145 SPARSE_TENSORS = 12;
146 TYPE_PROTOS = 14;
147 }
148
149 // The name field MUST be present for this version of the IR.
150 optional string name = 1; // namespace Attribute
151
152 // if ref_attr_name is not empty, ref_attr_name is the attribute name in parent function.
153 // In this case, this AttributeProto does not contain data, and it's a reference of attribute
154 // in parent scope.
155 // NOTE: This should ONLY be used in function (sub-graph). It's invalid to be used in main graph.
156 optional string ref_attr_name = 21;
157
158 // A human-readable documentation for this attribute. Markdown is allowed.
159 optional string doc_string = 13;
160
161 // The type field MUST be present for this version of the IR.
162 // For 0.0.1 versions of the IR, this field was not defined, and
163 // implementations needed to use has_field heuristics to determine
164 // which value field was in use. For IR_VERSION 0.0.2 or later, this
165 // field MUST be set and match the f|i|s|t|... field in use. This
166 // change was made to accommodate proto3 implementations.
167 optional AttributeType type = 20; // discriminator that indicates which field below is in use
168
169 // Exactly ONE of the following fields must be present for this version of the IR
170 optional float f = 2; // float
171 optional int64 i = 3; // int
172 optional bytes s = 4; // UTF-8 string
173 optional TensorProto t = 5; // tensor value
174 optional GraphProto g = 6; // graph
175 optional SparseTensorProto sparse_tensor = 22; // sparse tensor value
176 // Do not use field below, it's deprecated.
177 // optional ValueProto v = 12; // value - subsumes everything but graph
178 optional TypeProto tp = 14; // type proto
179
180 repeated float floats = 7; // list of floats
181 repeated int64 ints = 8; // list of ints
182 repeated bytes strings = 9; // list of UTF-8 strings
183 repeated TensorProto tensors = 10; // list of tensors
184 repeated GraphProto graphs = 11; // list of graph
185 repeated SparseTensorProto sparse_tensors = 23; // list of sparse tensors
186 repeated TypeProto type_protos = 15;// list of type protos
187}
188
189// Defines information on value, including the name, the type, and
190// the shape of the value.
191message ValueInfoProto {
192 // This field MUST be present in this version of the IR.
193 optional string name = 1; // namespace Value
194 // This field MUST be present in this version of the IR for
195 // inputs and outputs of the top-level graph.
196 optional TypeProto type = 2;
197 // A human-readable documentation for this value. Markdown is allowed.
198 optional string doc_string = 3;
199 // Named metadata values; keys should be distinct.
200 repeated StringStringEntryProto metadata_props = 4;
201}
202
203// Nodes
204//
205// Computation graphs are made up of a DAG of nodes, which represent what is
206// commonly called a "layer" or "pipeline stage" in machine learning frameworks.
207//
208// For example, it can be a node of type "Conv" that takes in an image, a filter
209// tensor and a bias tensor, and produces the convolved output.
210message NodeProto {
211 repeated string input = 1; // namespace Value
212 repeated string output = 2; // namespace Value
213
214 // An optional identifier for this node in a graph.
215 // This field MAY be absent in ths version of the IR.
216 optional string name = 3; // namespace Node
217
218 // The symbolic identifier of the Operator to execute.
219 optional string op_type = 4; // namespace Operator
220 // The domain of the OperatorSet that specifies the operator named by op_type.
221 optional string domain = 7; // namespace Domain
222 // Overload identifier, used only to map this to a model-local function.
223 optional string overload = 8;
224
225 // Additional named attributes.
226 repeated AttributeProto attribute = 5;
227
228 // A human-readable documentation for this node. Markdown is allowed.
229 optional string doc_string = 6;
230
231 // Named metadata values; keys should be distinct.
232 repeated StringStringEntryProto metadata_props = 9;
233}
234
235// Training information
236// TrainingInfoProto stores information for training a model.
237// In particular, this defines two functionalities: an initialization-step
238// and a training-algorithm-step. Initialization resets the model
239// back to its original state as if no training has been performed.
240// Training algorithm improves the model based on input data.
241//
242// The semantics of the initialization-step is that the initializers
243// in ModelProto.graph and in TrainingInfoProto.algorithm are first
244// initialized as specified by the initializers in the graph, and then
245// updated by the "initialization_binding" in every instance in
246// ModelProto.training_info.
247//
248// The field "algorithm" defines a computation graph which represents a
249// training algorithm's step. After the execution of a
250// TrainingInfoProto.algorithm, the initializers specified by "update_binding"
251// may be immediately updated. If the targeted training algorithm contains
252// consecutive update steps (such as block coordinate descent methods),
253// the user needs to create a TrainingInfoProto for each step.
254message TrainingInfoProto {
255 // This field describes a graph to compute the initial tensors
256 // upon starting the training process. Initialization graph has no input
257 // and can have multiple outputs. Usually, trainable tensors in neural
258 // networks are randomly initialized. To achieve that, for each tensor,
259 // the user can put a random number operator such as RandomNormal or
260 // RandomUniform in TrainingInfoProto.initialization.node and assign its
261 // random output to the specific tensor using "initialization_binding".
262 // This graph can also set the initializers in "algorithm" in the same
263 // TrainingInfoProto; a use case is resetting the number of training
264 // iteration to zero.
265 //
266 // By default, this field is an empty graph and its evaluation does not
267 // produce any output. Thus, no initializer would be changed by default.
268 optional GraphProto initialization = 1;
269
270 // This field represents a training algorithm step. Given required inputs,
271 // it computes outputs to update initializers in its own or inference graph's
272 // initializer lists. In general, this field contains loss node, gradient node,
273 // optimizer node, increment of iteration count.
274 //
275 // An execution of the training algorithm step is performed by executing the
276 // graph obtained by combining the inference graph (namely "ModelProto.graph")
277 // and the "algorithm" graph. That is, the actual
278 // input/initializer/output/node/value_info/sparse_initializer list of
279 // the training graph is the concatenation of
280 // "ModelProto.graph.input/initializer/output/node/value_info/sparse_initializer"
281 // and "algorithm.input/initializer/output/node/value_info/sparse_initializer"
282 // in that order. This combined graph must satisfy the normal ONNX conditions.
283 // Now, let's provide a visualization of graph combination for clarity.
284 // Let the inference graph (i.e., "ModelProto.graph") be
285 // tensor_a, tensor_b -> MatMul -> tensor_c -> Sigmoid -> tensor_d
286 // and the "algorithm" graph be
287 // tensor_d -> Add -> tensor_e
288 // The combination process results
289 // tensor_a, tensor_b -> MatMul -> tensor_c -> Sigmoid -> tensor_d -> Add -> tensor_e
290 //
291 // Notice that an input of a node in the "algorithm" graph may reference the
292 // output of a node in the inference graph (but not the other way round). Also, inference
293 // node cannot reference inputs of "algorithm". With these restrictions, inference graph
294 // can always be run independently without training information.
295 //
296 // By default, this field is an empty graph and its evaluation does not
297 // produce any output. Evaluating the default training step never
298 // update any initializers.
299 optional GraphProto algorithm = 2;
300
301 // This field specifies the bindings from the outputs of "initialization" to
302 // some initializers in "ModelProto.graph.initializer" and
303 // the "algorithm.initializer" in the same TrainingInfoProto.
304 // See "update_binding" below for details.
305 //
306 // By default, this field is empty and no initializer would be changed
307 // by the execution of "initialization".
308 repeated StringStringEntryProto initialization_binding = 3;
309
310 // Gradient-based training is usually an iterative procedure. In one gradient
311 // descent iteration, we apply
312 //
313 // x = x - r * g
314 //
315 // where "x" is the optimized tensor, "r" stands for learning rate, and "g" is
316 // gradient of "x" with respect to a chosen loss. To avoid adding assignments
317 // into the training graph, we split the update equation into
318 //
319 // y = x - r * g
320 // x = y
321 //
322 // The user needs to save "y = x - r * g" into TrainingInfoProto.algorithm. To
323 // tell that "y" should be assigned to "x", the field "update_binding" may
324 // contain a key-value pair of strings, "x" (key of StringStringEntryProto)
325 // and "y" (value of StringStringEntryProto).
326 // For a neural network with multiple trainable (mutable) tensors, there can
327 // be multiple key-value pairs in "update_binding".
328 //
329 // The initializers appears as keys in "update_binding" are considered
330 // mutable variables. This implies some behaviors
331 // as described below.
332 //
333 // 1. We have only unique keys in all "update_binding"s so that two
334 // variables may not have the same name. This ensures that one
335 // variable is assigned up to once.
336 // 2. The keys must appear in names of "ModelProto.graph.initializer" or
337 // "TrainingInfoProto.algorithm.initializer".
338 // 3. The values must be output names of "algorithm" or "ModelProto.graph.output".
339 // 4. Mutable variables are initialized to the value specified by the
340 // corresponding initializer, and then potentially updated by
341 // "initializer_binding"s and "update_binding"s in "TrainingInfoProto"s.
342 //
343 // This field usually contains names of trainable tensors
344 // (in ModelProto.graph), optimizer states such as momentums in advanced
345 // stochastic gradient methods (in TrainingInfoProto.graph),
346 // and number of training iterations (in TrainingInfoProto.graph).
347 //
348 // By default, this field is empty and no initializer would be changed
349 // by the execution of "algorithm".
350 repeated StringStringEntryProto update_binding = 4;
351}
352
353// Models
354//
355// ModelProto is a top-level file/container format for bundling a ML model and
356// associating its computation graph with metadata.
357//
358// The semantics of the model are described by the associated GraphProto's.
359message ModelProto {
360 // The version of the IR this model targets. See Version enum above.
361 // This field MUST be present.
362 optional int64 ir_version = 1;
363
364 // The OperatorSets this model relies on.
365 // All ModelProtos MUST have at least one entry that
366 // specifies which version of the ONNX OperatorSet is
367 // being imported.
368 //
369 // All nodes in the ModelProto's graph will bind against the operator
370 // with the same-domain/same-op_type operator with the HIGHEST version
371 // in the referenced operator sets.
372 repeated OperatorSetIdProto opset_import = 8;
373
374 // The name of the framework or tool used to generate this model.
375 // This field SHOULD be present to indicate which implementation/tool/framework
376 // emitted the model.
377 optional string producer_name = 2;
378
379 // The version of the framework or tool used to generate this model.
380 // This field SHOULD be present to indicate which implementation/tool/framework
381 // emitted the model.
382 optional string producer_version = 3;
383
384 // Domain name of the model.
385 // We use reverse domain names as name space indicators. For example:
386 // `com.facebook.fair` or `com.microsoft.cognitiveservices`
387 //
388 // Together with `model_version` and GraphProto.name, this forms the unique identity of
389 // the graph.
390 optional string domain = 4;
391
392 // The version of the graph encoded. See Version enum below.
393 optional int64 model_version = 5;
394
395 // A human-readable documentation for this model. Markdown is allowed.
396 optional string doc_string = 6;
397
398 // The parameterized graph that is evaluated to execute the model.
399 optional GraphProto graph = 7;
400
401 // Named metadata values; keys should be distinct.
402 repeated StringStringEntryProto metadata_props = 14;
403
404 // Training-specific information. Sequentially executing all stored
405 // `TrainingInfoProto.algorithm`s and assigning their outputs following
406 // the corresponding `TrainingInfoProto.update_binding`s is one training
407 // iteration. Similarly, to initialize the model
408 // (as if training hasn't happened), the user should sequentially execute
409 // all stored `TrainingInfoProto.initialization`s and assigns their outputs
410 // using `TrainingInfoProto.initialization_binding`s.
411 //
412 // If this field is empty, the training behavior of the model is undefined.
413 repeated TrainingInfoProto training_info = 20;
414
415 // A list of function protos local to the model.
416 //
417 // The (domain, name, overload) tuple must be unique across the function protos in this list.
418 // In case of any conflicts the behavior (whether the model local functions are given higher priority,
419 // or standard operator sets are given higher priotity or this is treated as error) is defined by
420 // the runtimes.
421 //
422 // The operator sets imported by FunctionProto should be compatible with the ones
423 // imported by ModelProto and other model local FunctionProtos.
424 // Example, if same operator set say 'A' is imported by a FunctionProto and ModelProto
425 // or by 2 FunctionProtos then versions for the operator set may be different but,
426 // the operator schema returned for op_type, domain, version combination
427 // for both the versions should be same for every node in the function body.
428 //
429 // One FunctionProto can reference other FunctionProto in the model, however, recursive reference
430 // is not allowed.
431 repeated FunctionProto functions = 25;
432};
433
434// StringStringEntryProto follows the pattern for cross-proto-version maps.
435// See https://developers.google.com/protocol-buffers/docs/proto3#maps
436message StringStringEntryProto {
437 optional string key = 1;
438 optional string value = 2;
439};
440
441message TensorAnnotation {
442 optional string tensor_name = 1;
443 // <key, value> pairs to annotate tensor specified by <tensor_name> above.
444 // The keys used in the mapping below must be pre-defined in ONNX spec.
445 // For example, for 8-bit linear quantization case, 'SCALE_TENSOR', 'ZERO_POINT_TENSOR' will be pre-defined as
446 // quantization parameter keys.
447 repeated StringStringEntryProto quant_parameter_tensor_names = 2;
448}
449
450
451
452// Graphs
453//
454// A graph defines the computational logic of a model and is comprised of a parameterized
455// list of nodes that form a directed acyclic graph based on their inputs and outputs.
456// This is the equivalent of the "network" or "graph" in many deep learning
457// frameworks.
458message GraphProto {
459 // The nodes in the graph, sorted topologically.
460 repeated NodeProto node = 1;
461
462 // The name of the graph.
463 optional string name = 2; // namespace Graph
464
465 // A list of named tensor values, used to specify constant inputs of the graph.
466 // Each initializer (both TensorProto as well SparseTensorProto) MUST have a name.
467 // The name MUST be unique across both initializer and sparse_initializer,
468 // but the name MAY also appear in the input list.
469 repeated TensorProto initializer = 5;
470
471 // Initializers (see above) stored in sparse format.
472 repeated SparseTensorProto sparse_initializer = 15;
473
474 // A human-readable documentation for this graph. Markdown is allowed.
475 optional string doc_string = 10;
476
477 // The inputs and outputs of the graph.
478 repeated ValueInfoProto input = 11;
479 repeated ValueInfoProto output = 12;
480
481 // Information for the values in the graph. The ValueInfoProto.name's
482 // must be distinct. It is optional for a value to appear in value_info list.
483 repeated ValueInfoProto value_info = 13;
484
485 // This field carries information to indicate the mapping among a tensor and its
486 // quantization parameter tensors. For example:
487 // For tensor 'a', it may have {'SCALE_TENSOR', 'a_scale'} and {'ZERO_POINT_TENSOR', 'a_zero_point'} annotated,
488 // which means, tensor 'a_scale' and tensor 'a_zero_point' are scale and zero point of tensor 'a' in the model.
489 repeated TensorAnnotation quantization_annotation = 14;
490
491 // Named metadata values; keys should be distinct.
492 repeated StringStringEntryProto metadata_props = 16;
493
494 reserved 3, 4, 6 to 9;
495 reserved "ir_version", "producer_version", "producer_tag", "domain";
496}
497
498// Tensors
499//
500// A serialized tensor value.
501message TensorProto {
502 enum DataType {
503 UNDEFINED = 0;
504 // Basic types.
505 FLOAT = 1; // float
506 UINT8 = 2; // uint8_t
507 INT8 = 3; // int8_t
508 UINT16 = 4; // uint16_t
509 INT16 = 5; // int16_t
510 INT32 = 6; // int32_t
511 INT64 = 7; // int64_t
512 STRING = 8; // string
513 BOOL = 9; // bool
514
515 // IEEE754 half-precision floating-point format (16 bits wide).
516 // This format has 1 sign bit, 5 exponent bits, and 10 mantissa bits.
517 FLOAT16 = 10;
518
519 DOUBLE = 11;
520 UINT32 = 12;
521 UINT64 = 13;
522 COMPLEX64 = 14; // complex with float32 real and imaginary components
523 COMPLEX128 = 15; // complex with float64 real and imaginary components
524
525 // Non-IEEE floating-point format based on IEEE754 single-precision
526 // floating-point number truncated to 16 bits.
527 // This format has 1 sign bit, 8 exponent bits, and 7 mantissa bits.
528 BFLOAT16 = 16;
529
530 // Non-IEEE floating-point format based on papers
531 // FP8 Formats for Deep Learning, https://arxiv.org/abs/2209.05433,
532 // 8-bit Numerical Formats For Deep Neural Networks, https://arxiv.org/pdf/2206.02915.pdf.
533 // Operators supported FP8 are Cast, CastLike, QuantizeLinear, DequantizeLinear.
534 // The computation usually happens inside a block quantize / dequantize
535 // fused by the runtime.
536 FLOAT8E4M3FN = 17; // float 8, mostly used for coefficients, supports nan, not inf
537 FLOAT8E4M3FNUZ = 18; // float 8, mostly used for coefficients, supports nan, not inf, no negative zero
538 FLOAT8E5M2 = 19; // follows IEEE 754, supports nan, inf, mostly used for gradients
539 FLOAT8E5M2FNUZ = 20; // follows IEEE 754, supports nan, not inf, mostly used for gradients, no negative zero
540
541 // 4-bit data-types
542 UINT4 = 21; // Unsigned integer in range [0, 15]
543 INT4 = 22; // Signed integer in range [-8, 7], using two's-complement representation
544
545 // Future extensions go here.
546 }
547
548 // The shape of the tensor.
549 repeated int64 dims = 1;
550
551 // The data type of the tensor.
552 // This field MUST have a valid TensorProto.DataType value
553 optional int32 data_type = 2;
554
555 // For very large tensors, we may want to store them in chunks, in which
556 // case the following fields will specify the segment that is stored in
557 // the current TensorProto.
558 message Segment {
559 optional int64 begin = 1;
560 optional int64 end = 2;
561 }
562 optional Segment segment = 3;
563
564 // Tensor content must be organized in row-major order.
565 //
566 // Depending on the data_type field, exactly one of the fields below with
567 // name ending in _data is used to store the elements of the tensor.
568
569 // For float and complex64 values
570 // Complex64 tensors are encoded as a single array of floats,
571 // with the real components appearing in odd numbered positions,
572 // and the corresponding imaginary component appearing in the
573 // subsequent even numbered position. (e.g., [1.0 + 2.0i, 3.0 + 4.0i]
574 // is encoded as [1.0, 2.0 ,3.0 ,4.0]
575 // When this field is present, the data_type field MUST be FLOAT or COMPLEX64.
576 repeated float float_data = 4 [packed = true];
577
578 // For int32, uint8, int8, uint16, int16, uint4, int4, bool, float8 and float16 values
579 // float16 and float8 values must be bit-wise converted to an uint16_t prior
580 // to writing to the buffer.
581 // uint4 and int4 values must be packed to 4bitx2 prior to writing to the buffer, the first element is stored in
582 // the 4 LSB and the second element is stored in the 4 MSB.
583 // When this field is present, the data_type field MUST be
584 // INT32, INT16, INT8, INT4, UINT16, UINT8, UINT4, BOOL, FLOAT16, BFLOAT16, FLOAT8E4M3FN, FLOAT8E4M3FNUZ, FLOAT8E5M2, FLOAT8E5M2FNUZ
585 repeated int32 int32_data = 5 [packed = true];
586
587 // For strings.
588 // Each element of string_data is a UTF-8 encoded Unicode
589 // string. No trailing null, no leading BOM. The protobuf "string"
590 // scalar type is not used to match ML community conventions.
591 // When this field is present, the data_type field MUST be STRING
592 repeated bytes string_data = 6;
593
594 // For int64.
595 // When this field is present, the data_type field MUST be INT64
596 repeated int64 int64_data = 7 [packed = true];
597
598 // Optionally, a name for the tensor.
599 optional string name = 8; // namespace Value
600
601 // A human-readable documentation for this tensor. Markdown is allowed.
602 optional string doc_string = 12;
603
604 // Serializations can either use one of the fields above, or use this
605 // raw bytes field. The only exception is the string case, where one is
606 // required to store the content in the repeated bytes string_data field.
607 //
608 // When this raw_data field is used to store tensor value, elements MUST
609 // be stored in as fixed-width, little-endian order.
610 // Floating-point data types MUST be stored in IEEE 754 format.
611 // Complex64 elements must be written as two consecutive FLOAT values, real component first.
612 // Complex128 elements must be written as two consecutive DOUBLE values, real component first.
613 // Boolean type MUST be written one byte per tensor element (00000001 for true, 00000000 for false).
614 // uint4 and int4 values must be packed to 4bitx2, the first element is stored in the 4 LSB and the second element is stored in the 4 MSB.
615 //
616 // Note: the advantage of specific field rather than the raw_data field is
617 // that in some cases (e.g. int data), protobuf does a better packing via
618 // variable length storage, and may lead to smaller binary footprint.
619 // When this field is present, the data_type field MUST NOT be STRING or UNDEFINED
620 optional bytes raw_data = 9;
621
622 // Data can be stored inside the protobuf file using type-specific fields or raw_data.
623 // Alternatively, raw bytes data can be stored in an external file, using the external_data field.
624 // external_data stores key-value pairs describing data location. Recognized keys are:
625 // - "location" (required) - POSIX filesystem path relative to the directory where the ONNX
626 // protobuf model was stored
627 // - "offset" (optional) - position of byte at which stored data begins. Integer stored as string.
628 // Offset values SHOULD be multiples 4096 (page size) to enable mmap support.
629 // - "length" (optional) - number of bytes containing data. Integer stored as string.
630 // - "checksum" (optional) - SHA1 digest of file specified in under 'location' key.
631 repeated StringStringEntryProto external_data = 13;
632
633 // Location of the data for this tensor. MUST be one of:
634 // - DEFAULT - data stored inside the protobuf message. Data is stored in raw_data (if set) otherwise in type-specified field.
635 // - EXTERNAL - data stored in an external location as described by external_data field.
636 enum DataLocation {
637 DEFAULT = 0;
638 EXTERNAL = 1;
639 }
640
641 // If value not set, data is stored in raw_data (if set) otherwise in type-specified field.
642 optional DataLocation data_location = 14;
643
644 // For double
645 // Complex128 tensors are encoded as a single array of doubles,
646 // with the real components appearing in odd numbered positions,
647 // and the corresponding imaginary component appearing in the
648 // subsequent even numbered position. (e.g., [1.0 + 2.0i, 3.0 + 4.0i]
649 // is encoded as [1.0, 2.0 ,3.0 ,4.0]
650 // When this field is present, the data_type field MUST be DOUBLE or COMPLEX128
651 repeated double double_data = 10 [packed = true];
652
653 // For uint64 and uint32 values
654 // When this field is present, the data_type field MUST be
655 // UINT32 or UINT64
656 repeated uint64 uint64_data = 11 [packed = true];
657
658 // Named metadata values; keys should be distinct.
659 repeated StringStringEntryProto metadata_props = 16;
660}
661
662// A serialized sparse-tensor value
663message SparseTensorProto {
664 // The sequence of non-default values are encoded as a tensor of shape [NNZ].
665 // The default-value is zero for numeric tensors, and empty-string for string tensors.
666 // values must have a non-empty name present which serves as a name for SparseTensorProto
667 // when used in sparse_initializer list.
668 optional TensorProto values = 1;
669
670 // The indices of the non-default values, which may be stored in one of two formats.
671 // (a) Indices can be a tensor of shape [NNZ, rank] with the [i,j]-th value
672 // corresponding to the j-th index of the i-th value (in the values tensor).
673 // (b) Indices can be a tensor of shape [NNZ], in which case the i-th value
674 // must be the linearized-index of the i-th value (in the values tensor).
675 // The linearized-index can be converted into an index tuple (k_1,...,k_rank)
676 // using the shape provided below.
677 // The indices must appear in ascending order without duplication.
678 // In the first format, the ordering is lexicographic-ordering:
679 // e.g., index-value [1,4] must appear before [2,1]
680 optional TensorProto indices = 2;
681
682 // The shape of the underlying dense-tensor: [dim_1, dim_2, ... dim_rank]
683 repeated int64 dims = 3;
684}
685
686// Defines a tensor shape. A dimension can be either an integer value
687// or a symbolic variable. A symbolic variable represents an unknown
688// dimension.
689message TensorShapeProto {
690 message Dimension {
691 oneof value {
692 int64 dim_value = 1;
693 string dim_param = 2; // namespace Shape
694 };
695 // Standard denotation can optionally be used to denote tensor
696 // dimensions with standard semantic descriptions to ensure
697 // that operations are applied to the correct axis of a tensor.
698 // Refer to https://github.com/onnx/onnx/blob/main/docs/DimensionDenotation.md#denotation-definition
699 // for pre-defined dimension denotations.
700 optional string denotation = 3;
701 };
702 repeated Dimension dim = 1;
703}
704
705// Types
706//
707// The standard ONNX data types.
708message TypeProto {
709
710 message Tensor {
711 // This field MUST NOT have the value of UNDEFINED
712 // This field MUST have a valid TensorProto.DataType value
713 // This field MUST be present for this version of the IR.
714 optional int32 elem_type = 1;
715 optional TensorShapeProto shape = 2;
716 }
717
718 // repeated T
719 message Sequence {
720 // The type and optional shape of each element of the sequence.
721 // This field MUST be present for this version of the IR.
722 optional TypeProto elem_type = 1;
723 };
724
725 // map<K,V>
726 message Map {
727 // This field MUST have a valid TensorProto.DataType value
728 // This field MUST be present for this version of the IR.
729 // This field MUST refer to an integral type ([U]INT{8|16|32|64}) or STRING
730 optional int32 key_type = 1;
731 // This field MUST be present for this version of the IR.
732 optional TypeProto value_type = 2;
733 };
734
735 // wrapper for Tensor, Sequence, or Map
736 message Optional {
737 // The type and optional shape of the element wrapped.
738 // This field MUST be present for this version of the IR.
739 // Possible values correspond to OptionalProto.DataType enum
740 optional TypeProto elem_type = 1;
741 };
742
743
744 message SparseTensor {
745 // This field MUST NOT have the value of UNDEFINED
746 // This field MUST have a valid TensorProto.DataType value
747 // This field MUST be present for this version of the IR.
748 optional int32 elem_type = 1;
749 optional TensorShapeProto shape = 2;
750 }
751
752
753 message Opaque {
754 // When missing, the domain is the same as the model's.
755 optional string domain = 1;
756 // The name is optional but significant when provided.
757 optional string name = 2;
758 // parameters that help defining the type
759 // DEPRECATED do not use.
760 // repeated TypeProto parameters = 3;
761 }
762
763
764 oneof value {
765 // The type of a tensor.
766 Tensor tensor_type = 1;
767
768 // NOTE: DNN-only implementations of ONNX MAY elect to not support non-tensor values
769 // as input and output to graphs and nodes. These types are needed to naturally
770 // support classical ML operators. DNN operators SHOULD restrict their input
771 // and output types to tensors.
772
773 // The type of a sequence.
774 Sequence sequence_type = 4;
775
776 // The type of a map.
777 Map map_type = 5;
778
779 // The type of an optional.
780 Optional optional_type = 9;
781
782
783 // Type of the sparse tensor
784 SparseTensor sparse_tensor_type = 8;
785
786
787 Opaque opaque_type = 7;
788
789 }
790
791 // An optional denotation can be used to denote the whole
792 // type with a standard semantic description as to what is
793 // stored inside. Refer to https://github.com/onnx/onnx/blob/main/docs/TypeDenotation.md#type-denotation-definition
794 // for pre-defined type denotations.
795 optional string denotation = 6;
796}
797
798// Operator Sets
799//
800// OperatorSets are uniquely identified by a (domain, opset_version) pair.
801message OperatorSetIdProto {
802 // The domain of the operator set being identified.
803 // The empty string ("") or absence of this field implies the operator
804 // set that is defined as part of the ONNX specification.
805 // This field MUST be present in this version of the IR when referring to any other operator set.
806 optional string domain = 1;
807
808 // The version of the operator set being identified.
809 // This field MUST be present in this version of the IR.
810 optional int64 version = 2;
811}
812
813// Operator/function status.
814enum OperatorStatus {
815 EXPERIMENTAL = 0;
816 STABLE = 1;
817}
818
819message FunctionProto {
820 // The name of the function, similar to op_type in NodeProto.
821 // This is part of the unique-id (domain, name, overload) of FunctionProtos in a model.
822 optional string name = 1;
823
824 // Deprecated since IR Version 8
825 // optional int64 since_version = 2;
826 reserved 2;
827 reserved "since_version";
828
829 // Deprecated since IR Version 8
830 // optional OperatorStatus status = 3;
831 reserved 3;
832 reserved "status";
833
834 // The inputs and outputs of the function.
835 repeated string input = 4;
836 repeated string output = 5;
837
838 // The attribute parameters of the function.
839 // It is for function parameters without default values.
840 repeated string attribute = 6;
841
842 // The attribute protos of the function.
843 // It is for function attributes with default values.
844 // A function attribute shall be represented either as
845 // a string attribute or an AttributeProto, not both.
846 repeated AttributeProto attribute_proto = 11;
847
848 // The nodes in the function.
849 repeated NodeProto node = 7;
850 // A human-readable documentation for this function. Markdown is allowed.
851 optional string doc_string = 8;
852
853 // The OperatorSets this function body (graph) relies on.
854 //
855 // All nodes in the function body (graph) will bind against the operator
856 // with the same-domain/same-op_type operator with the HIGHEST version
857 // in the referenced operator sets. This means at most one version can be relied
858 // for one domain.
859 //
860 // The operator sets imported by FunctionProto should be compatible with the ones
861 // imported by ModelProto. Example, if same operator set say 'A' is imported by FunctionProto
862 // and ModelProto then versions for the operator set may be different but,
863 // the operator schema returned for op_type, domain, version combination
864 // for both the versions should be same.
865
866 repeated OperatorSetIdProto opset_import = 9;
867
868 // The domain which this function belongs to.
869 // This is part of the unique-id (domain, name, overload) of FunctionProtos in a model.
870 optional string domain = 10;
871
872 // The overload identifier of the function.
873 // This is part of the unique-id (domain, name, overload) of FunctionProtos in a model.
874 optional string overload = 13;
875
876 // Information for the values in the function. The ValueInfoProto.name's
877 // must be distinct and refer to names in the function (including inputs,
878 // outputs, and intermediate values). It is optional for a value to appear
879 // in value_info list.
880 repeated ValueInfoProto value_info = 12;
881
882 // Named metadata values; keys should be distinct.
883 repeated StringStringEntryProto metadata_props = 14;
884}
885
886// For using protobuf-lite
887option optimize_for = LITE_RUNTIME;
888