onnx.h#
This page documents all ONNX proto message classes defined in onnx.h.
These classes mirror the Google Protocol Buffers schema from the
ONNX specification
but are generated entirely from lightweight C++ macros — no protobuf runtime is
required.
Field accessor pattern#
Every proto field named foo of type T exposes the following members:
Member |
Description |
|---|---|
|
The stored value (public data member). |
|
Returns a mutable reference to the field. |
|
Returns a const reference to the field. |
|
Returns a const pointer to the field, or |
|
Returns |
|
Assigns a new value to the field. |
|
Returns the protobuf field number. |
|
The documentation string for this field, available at compile time. |
Repeated fields (FIELD_REPEATED, FIELD_REPEATED_PACKED) additionally
provide add_foo() and clr_foo(), and store their values in a
onnx::utils::RepeatedField or
onnx::utils::RepeatedProtoField container.
Optional fields (FIELD_OPTIONAL, FIELD_OPTIONAL_ENUM) wrap their value
in onnx::utils::OptionalField or
onnx::utils::OptionalEnumField and add reset_foo() and
add_foo() members.
Every proto class inherits from onnx::Message and includes the
following serialization / deserialization methods (added by
SERIALIZATION_METHOD()):
uint64_t SerializeSize() const;
void ParseFromString(const std::string &raw);
void ParseFromString(const std::string &raw, onnx::ParseOptions &options);
void SerializeToString(std::string &out) const;
void SerializeToString(std::string &out, onnx::SerializeOptions &options) const;
uint64_t SerializeSize(onnx::utils::BinaryWriteStream &stream,
onnx::SerializeOptions &options) const;
void ParseFromStream(onnx::utils::BinaryStream &stream, onnx::ParseOptions &options);
void SerializeToStream(onnx::utils::BinaryWriteStream &stream,
onnx::SerializeOptions &options) const;
std::vector<std::string> PrintToVectorString(onnx::utils::PrintOptions &options) const;
See stream_class.h for onnx::ParseOptions,
onnx::SerializeOptions, and onnx::Message.
API reference#
ONNX proto message classes — the lightweight, protobuf-free ONNX schema.
Every class in this file is generated from the macros defined in stream_class.h (BEGIN_PROTO / END_PROTO / FIELD* / SERIALIZATION_METHOD). Each class inherits from ONNX_LIGHT_NAMESPACE::Message and provides parse/serialize methods as well as typed field accessors following the pattern described in the API documentation.
-
namespace ONNX_LIGHT_NAMESPACE
Enums
Functions
-
inline const char *AttributeProto_AttributeType_Name(AttributeProto::AttributeType t)#
-
class AttributeProto : public onnx::Message#
- #include <onnx.h>
“A named attribute containing either singular float, integer, string, graph, and “ “tensor values, or repeated float, integer, string, graph, and tensor values. An “ “AttributeProto MUST contain the name field, and *only one* of the following “ “content fields, effectively enforcing a C/C++ union equivalent.”
Public Types
-
enum AttributeType#
Values:
-
enumerator UNDEFINED#
-
enumerator FLOAT#
-
enumerator INT#
-
enumerator STRING#
-
enumerator TENSOR#
-
enumerator GRAPH#
-
enumerator SPARSE_TENSOR#
-
enumerator TYPE_PROTO#
-
enumerator FLOATS#
-
enumerator INTS#
-
enumerator STRINGS#
-
enumerator TENSORS#
-
enumerator GRAPHS#
-
enumerator SPARSE_TENSORS#
-
enumerator TYPE_PROTOS#
-
enumerator UNDEFINED#
Public Functions
-
inline AttributeProto()#
Public Members
-
onnx::utils::String name#
“Attribute name. This field MUST be present in this version of the IR.”
-
onnx::utils::String ref_attr_name#
“If ref_attr_name is not empty, ref_attr_name is the attribute name in parent function. In “ “this case, this AttributeProto does not contain data, and it’s a reference of attribute in “ “parent scope. NOTE: This should ONLY be used in function (sub-graph). It’s invalid to be “ “used in main graph.”
-
onnx::utils::String doc_string#
“A human-readable documentation for this tensor. Markdown is allowed.”
-
AttributeType type#
“The type field MUST be present for this version of the IR. For 0.0.1 versions of the IR, this “ “field was not defined, and implementations needed to use has_field heuristics to determine “ “which value field was in use. For IR_VERSION 0.0.2 or later, this field MUST be set and “ “match “ “the f|i|s|t|… field in use. This change was made to accommodate proto3 implementations.”
-
onnx::utils::OptionalField<float> f#
“Optional float attribute.”
-
onnx::utils::OptionalField<int64_t> i#
“Optional int64 attribute.”
-
onnx::utils::String s#
“Optional string attribute.”
-
onnx::utils::OptionalField<TensorProto> t#
“Optional tensor attribute.”
-
onnx::utils::OptionalField<GraphProto> g#
“Optional graph attribute.”
-
onnx::utils::OptionalField<SparseTensorProto> sparse_tensor#
“Optional sparse tensor attribute.”
-
onnx::utils::RepeatedField<float> floats#
“Optional repeated float attribute.”
-
onnx::utils::RepeatedField<int64_t> ints#
“Optional repeated int64 attribute.”
-
onnx::utils::RepeatedProtoField<TensorProto> tensors#
“Optional repeated tensor attribute.”
-
onnx::utils::RepeatedProtoField<SparseTensorProto> sparse_tensors#
“Optional repeated tensor attribute.”
-
onnx::utils::RepeatedProtoField<GraphProto> graphs#
“Optional repeated graph attribute.”
Public Static Functions
-
static inline const char *AttributeType_Name(AttributeType t)#
-
enum AttributeType#
-
class DeviceConfigurationProto : public onnx::Message#
- #include <onnx.h>
“Describes a multi-device configuration for a model.”
-
class FunctionProto : public onnx::Message#
- #include <onnx.h>
“A function defines a sub-operator that can be used in a graph. It is similar to a “ “function in C/C++ or Python, and can be used to define reusable sub-graphs.”
Public Members
-
onnx::utils::String name#
“The name of the function. This field MUST be present in this version of the IR.”
-
onnx::utils::RepeatedProtoField<AttributeProto> attribute_proto#
“typed attributes”
-
onnx::utils::String doc_string#
“A human-readable documentation for this graph. Markdown is allowed.”
-
onnx::utils::RepeatedProtoField<OperatorSetIdProto> opset_import#
“The OperatorSets this function body (graph) relies on. All nodes in the function body (graph) “ “will bind against the operator with the same-domain/same-op_type operator with the HIGHEST “ “version in the referenced operator sets. This means at most one version can be relied for one “ “domain. The operator sets imported by FunctionProto should be compatible with the ones “ “imported “ “by ModelProto. Example, if same operator set say ‘A’ is imported by FunctionProto and “ “ModelProto “ “then versions for the operator set may be different but, the operator schema returned for “ “op_type, domain, version combination for both the versions should be same.”
-
onnx::utils::String domain#
“The domain which this function belongs to. This is part of the unique-id (domain, name, “ “overload) of FunctionProtos in a model.”
-
onnx::utils::String overload#
“The overload identifier of the function. This is part of the unique-id (domain, name, “ “overload) of FunctionProtos in a model.”
-
onnx::utils::RepeatedProtoField<ValueInfoProto> value_info#
“Information for the values in the graph. The ValueInfoProto.name’s must be distinct. “ “It is optional for a value to appear in value_info list.”
-
onnx::utils::RepeatedField<StringStringEntryProto> metadata_props#
“Named metadata values; keys should be distinct.”
-
onnx::utils::String name#
-
class GraphProto : public onnx::Message#
- #include <onnx.h>
“A graph defines the computational logic of a model and is comprised of a parameterized “ “list of nodes that form a directed acyclic graph based on their inputs and outputs. This “ “is the equivalent of the ‘network’ or ‘graph’ in many deep learning frameworks.”
Public Members
-
onnx::utils::String name#
“The name of the graph.”
-
onnx::utils::RepeatedProtoField<TensorProto> initializer#
“A list of named sparse tensor values, used to specify constant inputs of the graph. “ “Each initializer (both TensorProto as well SparseTensorProto) MUST have a name. The “ “name MUST be unique across both initializer and sparse_initializer, but the name MAY “ “also appear in the input list.”
-
onnx::utils::RepeatedProtoField<SparseTensorProto> sparse_initializer#
“A list of named tensor values, used to specify constant inputs of the graph. Each initializer “ “(both TensorProto as well SparseTensorProto) MUST have a name. The name MUST be unique across “ “both initializer and sparse_initializer, but the name MAY also appear in the input list.”
-
onnx::utils::String doc_string#
“A human-readable documentation for this graph. Markdown is allowed.”
-
onnx::utils::RepeatedProtoField<ValueInfoProto> input#
“Inputs of the graph, shapes and types are optional in a subgraph and “ “mandatory in the main graph.”
-
onnx::utils::RepeatedProtoField<ValueInfoProto> output#
“Outputs of the graph, shapes and types are optional in a subgraph and mandatory in the “ “main graph.”
-
onnx::utils::RepeatedProtoField<ValueInfoProto> value_info#
“Information for the values in the graph. The ValueInfoProto.name’s must be distinct. “ “It is optional for a value to appear in value_info list.”
-
onnx::utils::RepeatedField<TensorAnnotation> quantization_annotation#
“This field carries information to indicate the mapping among a tensor and its quantization “ “parameter tensors. For example: For tensor ‘a’, it may have {‘SCALE_TENSOR’, ‘a_scale’} and “ “{‘ZERO_POINT_TENSOR’, ‘a_zero_point’} annotated, which means, tensor ‘a_scale’ and tensor “ “‘a_zero_point’ are scale and zero point of tensor ‘a’ in the model.”
-
onnx::utils::RepeatedField<StringStringEntryProto> metadata_props#
“Named metadata values; keys should be distinct.”
-
onnx::utils::String name#
-
class IntIntListEntryProto : public onnx::Message#
- #include <onnx.h>
“Defines a key value pair, key is an integer, value is a list of integers.”
-
class MapProto : public onnx::Message#
- #include <onnx.h>
“Specifies an associative table, defined by keys and values. MapProto is formed with a “ “repeated field of keys (of type INT8, INT16, INT32, INT64, UINT8, UINT16, UINT32, “ “UINT64, or STRING) and values (of type TENSOR, SPARSE_TENSOR, SEQUENCE, or MAP). Key “ “types and value types have to remain the same throughout the instantiation of the “ “MapProto.”
Public Members
-
onnx::utils::String name#
“An optional identifier for this map.”
-
TensorProto::DataType key_type#
“The data type of the key. “ “This field MUST have a valid TensorProto.DataType value of “ “INT8, INT16, INT32, INT64, UINT8, UINT16, UINT32, UINT64, or STRING”
-
onnx::utils::RepeatedField<int64_t> keys#
“Every element of keys has to be one of the following data types “ “INT8, INT16, INT32, INT64, UINT8, UINT16, UINT32, UINT64, or STRING. “ “The integer cases are represented by the repeated int64 field keys below.”
-
onnx::utils::RepeatedField<utils::String> string_keys#
“If keys are strings, they are represented by the repeated bytes field “ “string_keys below.”
-
SequenceProto values#
“MapProto values are represented in a SequenceProto of the same length as the “ “repeated keys field and have to be one of the following data types “ “TENSOR, SPARSE_TENSOR, MAP, SEQUENCE.”
-
onnx::utils::String name#
-
class ModelProto : public onnx::Message#
- #include <onnx.h>
“ModelProto is a top-level file/container format for bundling a ML model and “ “associating its computation graph with metadata. The semantics of the model “ “are described by the associated GraphProto’s.”
Public Functions
-
void SerializeToString(std::string &out, std::unordered_map<std::string, std::string> &external_files, size_t max_external_file_size, const std::string &external_file_prefix = "weights") const#
Serializes the proto into out and external weight payloads into external_files. External files are split so each file size is at most max_external_file_size.
-
void SerializeToString(std::string &out, std::unordered_map<std::string, std::string> &external_files, size_t max_external_file_size, const std::string &external_file_prefix, const SerializeOptions &opts) const#
Serializes the proto into out and external weight payloads into external_files. External files are split so each file size is at most max_external_file_size.
Public Members
-
onnx::utils::OptionalField<int64_t> ir_version#
“The version of the IR this model targets. See Version enum above. This field MUST be present.”
-
onnx::utils::RepeatedProtoField<OperatorSetIdProto> opset_import#
“The OperatorSets this model relies on. All ModelProtos MUST have at least one entry that “ “specifies which version of the ONNX OperatorSet is being imported. All nodes in the “ “ModelProto’s “ “graph will bind against the operator with the same-domain/same-op_type operator with the “ “HIGHEST “ “version in the referenced operator sets.”
-
onnx::utils::String producer_name#
“The name of the framework or tool used to generate this model. This field SHOULD be present “ “to indicate which implementation/tool/framework emitted the model.”
-
onnx::utils::String producer_version#
“The version of the framework or tool used to generate this model. This field SHOULD be “ “present to indicate which implementation/tool/framework emitted the model.”
-
onnx::utils::String domain#
“Domain name of the model. We use reverse domain names as name space indicators. For “ “example: `company.name`. Together with `model_version` and GraphProto.name, this forms the “ “unique identity of the graph.”
-
onnx::utils::OptionalField<int64_t> model_version#
“The version of the graph encoded. See Version enum below.”
-
onnx::utils::String doc_string#
“A human-readable documentation for this graph. Markdown is allowed.”
-
onnx::utils::OptionalField<GraphProto> graph#
“The parameterized graph that is evaluated to execute the model.”
-
onnx::utils::RepeatedField<StringStringEntryProto> metadata_props#
“Named metadata values; keys should be distinct.”
-
onnx::utils::RepeatedProtoField<FunctionProto> functions#
“A list of function protos local to the model. The (domain, name, overload) tuple must be “ “unique “ “across the function protos in this list. In case of any conflicts the behavior (whether the “ “model “ “local functions are given higher priority, or standard operator sets are given higher “ “priority or “ “this is treated as error) is defined by the runtimes. The operator sets imported by “ “FunctionProto “ “should be compatible with the ones imported by ModelProto and other model local “ “FunctionProtos. “ “Example, if same operator set say ‘A’ is imported by a FunctionProto and ModelProto or by 2 “ “FunctionProtos then versions for the operator set may be different but, the operator schema “ “returned for op_type, domain, version combination for both the versions should be same for “ “every “ “node in the function body. One FunctionProto can reference other FunctionProto in the model, “ “however, recursive reference is not allowed.”
-
onnx::utils::RepeatedField<DeviceConfigurationProto> configuration#
“Describes different target configurations for a multi-device use case. A model MAY “ “describe multiple multi-device configurations for execution.”
-
void SerializeToString(std::string &out, std::unordered_map<std::string, std::string> &external_files, size_t max_external_file_size, const std::string &external_file_prefix = "weights") const#
-
class NodeDeviceConfigurationProto : public onnx::Message#
- #include <onnx.h>
“Defines a multi-device configuration proto for NodeProto.”
Public Members
-
onnx::utils::String configuration_id#
“This field MUST be present for this version of the IR., ID of the configuration. “ “MUST match the name of a DeviceConfigurationProto.”
-
onnx::utils::RepeatedField<ShardingSpecProto> sharding_spec#
“Sharding spec for the node.”
-
onnx::utils::OptionalField<int32_t> pipeline_stage#
“Pipeline stage of this node.”
-
onnx::utils::String configuration_id#
-
class NodeProto : public onnx::Message#
- #include <onnx.h>
“Computation graphs are made up of a DAG of nodes, which represent what is “ “commonly called a ‘layer’ or ‘pipeline stage’ in machine learning frameworks. “ “For example, it can be a node of type ‘Conv’ that takes in an image, a filter “ “tensor and a bias tensor, and produces the convolved output.”
Public Members
-
onnx::utils::String name#
“An optional identifier for this node in a graph. This field MAY be absent in this version “ “of the IR.”
-
onnx::utils::String op_type#
“The symbolic identifier of the Operator to execute.”
-
onnx::utils::RepeatedProtoField<AttributeProto> attribute#
“Attributes associated with this node.”
-
onnx::utils::String domain#
“The domain of the OperatorSet that specifies the operator named by op_type.”
-
onnx::utils::String overload#
“Overload identifier, used only to map this to a model-local function.”
-
onnx::utils::String doc_string#
“A human-readable documentation for this node. Markdown is allowed.”
-
onnx::utils::RepeatedField<StringStringEntryProto> metadata_props#
“Named metadata values; keys should be distinct.”
-
onnx::utils::RepeatedField<NodeDeviceConfigurationProto> device_configurations#
“Configuration of multi-device annotations.”
-
onnx::utils::String name#
-
class OperatorSetIdProto : public onnx::Message#
- #include <onnx.h>
“Defines a unique pair domain, opset version for a set of operators.”
Public Members
-
onnx::utils::String domain#
“The domain of the operator set being identified. The empty string (” “) or absence of this field implies the operator set that is defined as part of the “ “ONNX specification. This field MUST be present in this version of the IR when “ “referring to any other operator set.”
-
int64_t version#
“The version of the operator set being identified. This field MUST be present in “ “this version of the IR.”
-
onnx::utils::String domain#
-
class OptionalProto : public onnx::Message#
- #include <onnx.h>
“A container that may or may not hold a value. The value, if present, may be a “ “Tensor, Sparse Tensor, Sequence, Map, or another Optional. An absent value is “ “semantically different from a present value that contains an empty tensor, “ “sequence, or map. For example, an absent optional tensor means the absence of “ “the tensor itself, whereas a present optional tensor that contains an empty “ “tensor means the tensor is present but it has no elements.”
Public Types
Public Functions
-
inline OptionalProto()#
-
inline bool has_value() const#
-
inline void set_elem_type(int t)#
Public Members
-
onnx::utils::String name#
“An optional identifier for this optional.”
-
DataType elem_type#
“The data type of the element, identifies if the OptionalProto value is Tensor, Sparse “ “Tensor, Sequence, Map, or Optional. The type of the optional value MUST match the “ “elem_type specified. This field MUST have a valid OptionalProto.DataType value.”
-
onnx::utils::OptionalField<TensorProto> tensor_value#
“For TensorProto value. “ “When this field is present, the elem_type field MUST be TENSOR.”
-
onnx::utils::OptionalField<SparseTensorProto> sparse_tensor_value#
“For SparseTensorProto value. “ “When this field is present, the elem_type field MUST be SPARSE_TENSOR.”
-
onnx::utils::OptionalField<SequenceProto> sequence_value#
“For SequenceProto value. When this field is present, the elem_type field MUST be SEQUENCE.”
-
onnx::utils::OptionalField<MapProto> map_value#
“For MapProto value. “ “When this field is present, the elem_type field MUST be MAP.”
-
onnx::utils::OptionalField<OptionalProto> optional_value#
“For OptionalProto value, allowing optional to be of itself (completeness) “ “When this field is present, the elem_type field MUST be OPTIONAL.”
-
inline OptionalProto()#
-
class SequenceProto : public onnx::Message#
- #include <onnx.h>
“Defines a dense, ordered, collection of elements that are of homogeneous types. “ “Sequences can be made out of tensors, maps, or sequences. “ “If a sequence is made out of tensors, the tensors must have the same element “ “type (i.e. int32). In some cases, the tensors in a sequence can have different “ “shapes. Whether the tensors can have different shapes or not depends on the “ “type/shape associated with the corresponding `ValueInfo`. For example, “ “`Sequence<Tensor<float, [M,N]>` means that all tensors have same shape. However, “ “`Sequence<Tensor<float, [omitted,omitted]>` means they can have different “ “shapes (all of rank 2), where `omitted` means the corresponding dimension has “ “no symbolic/constant value. Finally, `Sequence<Tensor<float, omitted>>` means “ “that the different tensors can have different ranks, when the `shape` itself “ “is omitted from the tensor-type. For a more complete description”
Public Types
Public Members
-
onnx::utils::String name#
“An optional identifier for this sequence.”
-
DataType elem_type#
“The type of the elements in the sequence. The type of each element MUST match the elem_type “ “specified. This field MUST be present for this version of the IR.”
-
onnx::utils::RepeatedProtoField<TensorProto> tensor_values#
“For TensorProto values. “ “When this field is present, the elem_type field MUST be TENSOR. “
-
onnx::utils::RepeatedProtoField<SparseTensorProto> sparse_tensor_values#
“For SparseTensorProto values. “ “When this field is present, the elem_type field MUST be SPARSE_TENSOR. “
-
onnx::utils::RepeatedProtoField<SequenceProto> sequence_values#
“For SequenceProto values. “ “When this field is present, the elem_type field MUST be SEQUENCE. “
-
onnx::utils::RepeatedProtoField<MapProto> map_values#
“For MapProto values. “ “When this field is present, the elem_type field MUST be MAP. “
-
onnx::utils::RepeatedProtoField<OptionalProto> optional_values#
“For Optional values. “ “When this field is present, the elem_type field MUST be OPTIONAL. “
-
onnx::utils::String name#
-
class ShardedDimProto : public onnx::Message#
- #include <onnx.h>
“Describes the sharding spec for a single axis of a sharded tensor.”
Public Functions
-
inline ShardedDimProto()#
Public Members
-
int64_t axis#
“This field MUST be present for this version of the IR. The axis this sharding “ “corresponds to. Must be in the range of [-r, r - 1], where r is the rank of the tensor. “ “Negative axis values means counting from the back.”
-
onnx::utils::RepeatedField<SimpleShardedDimProto> simple_sharding#
“Describes how the tensor on the provided axis is sharded. The common-case is described by “ “a single instance of SimpleShardedDimProto. Multiple instances can be used to handle “ “cases where a sharded tensor is reshaped, fusing multiple axes into one.”
-
inline ShardedDimProto()#
-
class ShardingSpecProto : public onnx::Message#
- #include <onnx.h>
“Describes the sharding spec for a specific, input or output tensor of a node.”
Public Members
-
onnx::utils::String tensor_name#
“This field MUST be present for this version of the IR. Identifies the input or output of “ “the node that is being sharded. Required to match a name specified in the node’s input or “ “output list of ValueInfoProtos. It is called `logical tensor` in subsequent descriptions.”
-
onnx::utils::RepeatedField<int64_t> device#
“The following is the list of devices across which the logical tensor is “ “sharded or replicated.”
-
onnx::utils::RepeatedField<IntIntListEntryProto> index_to_device_group_map#
“Each element v in above field devices may represent either a device or a set of devices “ “(when we want the same shard/tensor to be replicated across a subset of devices), as “ “indicated by the following optional map. If the map contains an entry for v, then v “ “represents a device group, and the map indicates the set of devices in that group.”
-
onnx::utils::RepeatedField<ShardedDimProto> sharded_dim#
“The following is the sharded-shape of the tensor, consisting of the “ “sharding-spec for each axis of the tensor.”
-
onnx::utils::String tensor_name#
-
class SimpleShardedDimProto : public onnx::Message#
- #include <onnx.h>
“Indicates that N blocks are divided into M shards. N is allowed to be symbolic “ “where M is required to be a constant.”
Public Members
-
onnx::utils::OptionalField<int64_t> dim_value#
“Dimension value to be sharded if it is a fixed value.”
-
onnx::utils::String dim_param#
“Dimension name to be sharded if it is a dynamic value.”
-
int64_t num_shards#
“This field MUST be present for this version of the IR. Number of shards to “ “split dim into.”
-
onnx::utils::OptionalField<int64_t> dim_value#
-
class SparseTensorProto : public onnx::Message#
- #include <onnx.h>
“A sparse tensor.”
Public Members
-
TensorProto values#
“The sequence of non-default values are encoded as a tensor of shape [NNZ]. The “ “default-value is zero for numeric tensors, and empty-TypeProto::TensorString for string “ “tensors. values must have a non-empty name present which serves as a name for “ “SparseTensorProto when used in sparse_initializer list.”
-
TensorProto indices#
“The indices of the non-default values, which may be stored in one of two formats. (a) “ “Indices can be a tensor of shape [NNZ, rank] with the [i,j]-th value corresponding to “ “the j-th index of the i-th value (in the values tensor). (b) Indices can be a tensor of “ “shape [NNZ], in which case the i-th value must be the linearized-index of the i-th “ “value (in the values tensor). The linearized-index can be converted into an index tuple “ “(k_1,…,k_rank) using the shape provided below. The indices must appear in ascending “ “order without duplication. In the first format, the ordering is lexicographic-ordering: “ “e.g., index-value [1,4] must appear before [2,1].”
-
onnx::utils::RepeatedField<int64_t> dims#
“The shape.”
-
TensorProto values#
-
class StringStringEntryProto : public onnx::Message#
- #include <onnx.h>
“Defines a key value pair, both defines a string.”
-
class TensorAnnotation : public onnx::Message#
- #include <onnx.h>
“Defines a tensor annotation, useful for quantized tensors.”
Public Members
-
onnx::utils::String tensor_name#
“tensor name”
-
onnx::utils::RepeatedField<StringStringEntryProto> quant_parameter_tensor_names#
“<key, value> pairs to annotate tensor specified by <tensor_name> above. The “ “keys used in the mapping below must be pre-defined in ONNX spec. For example, “ “for 8-bit linear quantization case, ‘SCALE_TENSOR’, ‘ZERO_POINT_TENSOR’ will “ “be pre-defined as quantization parameter keys.”
-
onnx::utils::String tensor_name#
-
class TensorProto : public onnx::Message#
- #include <onnx.h>
“Defines a tensor and its content.”
Public Types
-
enum DataType#
Values:
-
enumerator UNDEFINED#
-
enumerator FLOAT#
-
enumerator UINT8#
-
enumerator INT8#
-
enumerator UINT16#
-
enumerator INT16#
-
enumerator INT32#
-
enumerator INT64#
-
enumerator STRING#
-
enumerator BOOL#
-
enumerator FLOAT16#
-
enumerator DOUBLE#
-
enumerator UINT32#
-
enumerator UINT64#
-
enumerator COMPLEX64#
-
enumerator COMPLEX128#
-
enumerator BFLOAT16#
-
enumerator FLOAT8E4M3FN#
-
enumerator FLOAT8E4M3FNUZ#
-
enumerator FLOAT8E5M2#
-
enumerator FLOAT8E5M2FNUZ#
-
enumerator UINT4#
-
enumerator INT4#
-
enumerator FLOAT4E2M1#
-
enumerator FLOAT8E8M0#
-
enumerator UINT2#
-
enumerator INT2#
-
enumerator UNDEFINED#
Public Functions
-
inline TensorProto()#
-
inline void set_data_type(int v)#
-
inline bool is_raw_data() const#
-
void LoadExternalData(const std::string &base_dir = "")#
Loads the raw bytes of this tensor from the external file described by its
external_datafield intoraw_data.Recognized
external_datakeys arelocation(required),offset(optional) andlength(optional, also accepted assize). The tensor must havedata_location == EXTERNAL.The
external_dataanddata_locationfields are preserved so the tensor still describes where the data originally lives.- Parameters:
base_dir – Directory containing the external data file. The final path is
base_dir / location. When empty,locationis used as-is.
Public Members
-
onnx::utils::RepeatedField<uint64_t> dims#
“The shape of the tensor.”
-
DataType data_type#
“The data type of the tensor. This field MUST have a valid TensorProto.DataType value”
-
onnx::utils::OptionalField<Segment> segment#
“For very large tensors, we may want to store them in chunks, in which case the “ “following fields will specify the segment that is stored in the current TensorProto.”
-
onnx::utils::RepeatedField<float> float_data#
“Tensor content must be organized in row-major order. Depending on the data_type field, “ “exactly one of the fields below with name ending in _data is used to store the elements “ “of the tensor. For float and complex64 values Complex64 tensors are encoded as a single “ “array of floats, with the real components appearing in odd numbered positions, and the “ “corresponding imaginary component appearing in the subsequent even numbered position. “ “(e.g., [1.0 + 2.0i, 3.0 + 4.0i] is encoded as [1.0, 2.0 ,3.0 ,4.0] When this field is “ “present, the data_type field MUST be FLOAT or COMPLEX64.”
-
onnx::utils::RepeatedField<int32_t> int32_data#
“For int32, uint8, int8, uint16, int16, uint4, int4, bool, (b)float16, float8, and “ “float4: - (b)float16 and float8 values MUST be converted bit-wise into an unsigned “ “integer representation before being written to the buffer. - Each pair of uint4, int4, “ “and float4 values MUST be packed as two 4-bit elements into a single byte. The first “ “element is stored in the 4 least significant bits (LSB), and the second element is “ “stored in the 4 most significant bits (MSB). Consequently: - For data types with a “ “bit-width of 8 or greater, each `int32_data` stores one element. - For 4-bit data “ “types, each `int32_data` stores two elements. When this field is present, the data_type “ “field MUST be INT32, INT16, INT8, INT4, UINT16, UINT8, UINT4, BOOL, FLOAT16, BFLOAT16, “ “FLOAT8E4M3FN, FLOAT8E4M3FNUZ, FLOAT8E5M2, FLOAT8E5M2FNUZ, FLOAT8E8M0, FLOAT4E2M1, “ “UINT2, INT2”
-
onnx::utils::RepeatedField<utils::String> string_data#
“For strings. Each element of string_data is a UTF-8 encoded Unicode string. No “ “trailing null, no leading BOM. The ‘string’ scalar type is not used to match “ “ML community conventions. When this field is “ “present, the data_type field MUST be STRING”
-
onnx::utils::RepeatedField<int64_t> int64_data#
“For int64. When this field is present, the data_type field MUST be INT64”
-
onnx::utils::String name#
“Optionally, a name for the tensor.”
-
utils::ByteSpan raw_data#
“Serializations can either use one of the fields above, or use this raw bytes field. The “ “only exception is the string case, where one is required to store the content in the “ “repeated bytes string_data field. When this raw_data field is used to store tensor “ “value, elements MUST be stored in as fixed-width, little-endian order. Floating-point “ “data types MUST be stored in IEEE 754 format. Complex64 elements must be written as two “ “consecutive FLOAT values, real component first. Complex128 elements must be written as “ “two consecutive DOUBLE values, real component first. Boolean type MUST be written one “ “byte per tensor element (00000001 for true, 00000000 for false). 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. Note: the advantage of specific field rather than the “ “raw_data field is that in some cases (e.g. int data), protobuf does a better packing “ “via variable length storage, and may lead to smaller binary footprint. When this field “ “is present, the data_type field MUST NOT be STRING or UNDEFINED.”
-
onnx::utils::RepeatedField<double> double_data#
“For double Complex128 tensors are encoded as a single array of doubles, with the real “ “components appearing in odd numbered positions, and the corresponding imaginary component “ “appearing in the subsequent even numbered position. (e.g., [1.0 + 2.0i, 3.0 + 4.0i] is “ “encoded as [1.0, 2.0 ,3.0 ,4.0] When this field is present, the data_type field MUST be “ “DOUBLE or COMPLEX128.”
-
onnx::utils::RepeatedField<uint64_t> uint64_data#
“For uint64 and uint32 values. When this field is present, the data_type “ “field MUST be UINT32 or UINT64.”
-
onnx::utils::String doc_string#
“A human-readable documentation for this tensor. Markdown is allowed.”
-
onnx::utils::RepeatedField<StringStringEntryProto> external_data#
“Data can be stored inside the protobuf file using type-specific fields or raw_data. “ “Alternatively, raw bytes data can be stored in an external file, using the external_data “ “field. external_data stores key-value pairs describing data location. Recognized keys “ “are: “ “- location (required) - POSIX filesystem path relative to the directory where “ “the ONNX protobuf model was stored “ “- offset (optional) - position of byte at which stored data begins. Integer stored as “ “string. “ “Offset values SHOULD be multiples 4096 (page size) to enable mmap support. “ “- length (optional) - number of bytes containing data. Integer stored as string. “ “- checksum (optional) - SHA1 digest of file specified in under ‘location’ key.”
-
onnx::utils::OptionalEnumField<DataLocation> data_location#
“Location of the data for this tensor. MUST be one of: - DEFAULT - data stored inside the “ “protobuf message. Data is stored in raw_data (if set) otherwise in type-specified field. “ “- EXTERNAL - data stored in an external location as described by external_data field. If “ “value not set, data is stored in raw_data (if set) otherwise in type-specified field.”
-
onnx::utils::RepeatedField<StringStringEntryProto> metadata_props#
“Named metadata values; keys should be distinct.”
Public Static Functions
-
class Segment : public onnx::Message#
- #include <onnx.h>
“For very large tensors, we may want to store them in chunks, in which case the following “ “fields will specify the segment that is stored in the current TensorProto.”
-
enum DataType#
-
class TensorShapeProto : public onnx::Message#
- #include <onnx.h>
“Defines a tensor shape. A dimension can be either an integer value or a “ “symbolic variable. A symbolic variable represents an unknown dimension.”
-
class Dimension : public onnx::Message#
- #include <onnx.h>
“Defines a dimension, it can be fixed (an integer dim_value) or dynamic “ “(a string dim_param). Only one of them can be set.”
Public Functions
-
inline void Clear()#
Public Members
-
onnx::utils::OptionalField<int64_t> dim_value#
“Dimension value if it is a fixed value.”
-
onnx::utils::String dim_param#
“Dimension name if it is a dynamic value.”
-
onnx::utils::String denotation#
“Standard denotation can optionally be used to denote tensor dimensions with standard “ “semantic descriptions to ensure that operations are applied to the correct axis of a “ “tensor. Refer to https://github.com/onnx/onnx/blob/main/docs/DimensionDenotation.md” “#axisdenotation-definition for pre-defined dimension denotations.”
-
inline void Clear()#
-
class Dimension : public onnx::Message#
-
class TypeProto : public onnx::Message#
- #include <onnx.h>
“Defines a type, it can be a tensor type (element type and “ “shape), a sequence of the same element type, …”
Public Types
Public Members
-
onnx::utils::String denotation#
“An optional denotation can be used to denote the whole type with a standard “ “semantic description as to what is stored inside. Refer to “ “https://github.com/onnx/onnx/blob/main/docs/” “TypeDenotation.md#type-denotation-definition for pre-defined type denotations.”
-
onnx::utils::OptionalField<SparseTensor> sparse_tensor_type#
“Type of the sparse tensor”
Public Static Attributes
-
static const ValueCase VALUE_NOT_SET = ValueCase::kUndefined#
-
class Map : public onnx::Message#
- #include <onnx.h>
“Defines the type of the key and the type of each value in a dictionary.”
Public Members
-
int32_t key_type#
“This field MUST have a valid TensorProto.DataType value. This field MUST be present for “ “this version of the IR. This field MUST refer to an integral type ([U]INT{8|16|32|64}) “ “or STRING optional int32 key_type = 1;”
-
int32_t key_type#
-
class Optional : public onnx::Message#
- #include <onnx.h>
“Defines the type of an optional value.”
-
class Sequence : public onnx::Message#
- #include <onnx.h>
“Defines the type of each element in a sequence.”
-
class SparseTensor : public onnx::Message#
- #include <onnx.h>
“Defines a sparse tensor type (element type, shape)”
Public Functions
-
inline void set_elem_type(int v)#
Public Members
-
onnx::utils::OptionalEnumField<TensorProto::DataType> elem_type#
“This field MUST NOT have the value of UNDEFINED. This field MUST have a valid “ “TensorProto.DataType value. This field MUST be present for this version of the IR.”
-
onnx::utils::OptionalField<TensorShapeProto> shape#
“The shape.”
-
inline void set_elem_type(int v)#
-
class Tensor : public onnx::Message#
- #include <onnx.h>
“Defines a tensor type (element type, shape).”
Public Functions
-
inline void set_elem_type(int v)#
Public Members
-
onnx::utils::OptionalEnumField<TensorProto::DataType> elem_type#
“This field MUST NOT have the value of UNDEFINED. This field MUST have a valid “ “TensorProto.DataType value. This field MUST be present for this version of the IR.”
-
onnx::utils::OptionalField<TensorShapeProto> shape#
“The shape.”
-
inline void set_elem_type(int v)#
-
onnx::utils::String denotation#
-
class ValueInfoProto : public onnx::Message#
- #include <onnx.h>
“Defines information on value, including the name, the type, and the shape of the value.”
Public Members
-
onnx::utils::String name#
“This field MUST be present in this version of the IR.”
-
onnx::utils::OptionalField<TypeProto> type#
“This field MUST be present in this version of the IR for inputs and outputs of “ “the top-level graph.”
-
onnx::utils::String doc_string#
“A human-readable documentation for this tensor. Markdown is allowed.”
-
onnx::utils::RepeatedField<StringStringEntryProto> metadata_props#
“Named metadata values; keys should be distinct.”
-
onnx::utils::String name#
-
inline const char *AttributeProto_AttributeType_Name(AttributeProto::AttributeType t)#