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_light::utils::RepeatedField or
onnx_light::utils::RepeatedProtoField container.
Optional fields (FIELD_OPTIONAL, FIELD_OPTIONAL_ENUM) wrap their value
in onnx_light::utils::OptionalField or
onnx_light::utils::OptionalEnumField and add reset_foo() and
add_foo() members.
Every proto class inherits from onnx_light::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_light::ParseOptions &options);
void SerializeToString(std::string &out) const;
void SerializeToString(std::string &out, onnx_light::SerializeOptions &options) const;
uint64_t SerializeSize(onnx_light::utils::BinaryWriteStream &stream,
onnx_light::SerializeOptions &options) const;
void ParseFromStream(onnx_light::utils::BinaryStream &stream, onnx_light::ParseOptions &options);
void SerializeToStream(onnx_light::utils::BinaryWriteStream &stream,
onnx_light::SerializeOptions &options) const;
void PrintToStringStream(std::stringstream &ss, onnx_light::utils::PrintOptions &options) const;
See stream_class.h for onnx_light::ParseOptions,
onnx_light::SerializeOptions, and onnx_light::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
Alias that makes onnx-light headers compatible with code that references
ONNX_LIGHT_NAMESPACE(the macro used in the standard onnx package).Set to
ONNX_LIGHT_NAMESPACEso both names resolve to the same namespace.Symbol-visibility attribute for the public onnx-light C++ API.
Defined as empty because onnx-light does not require explicit
__declspec(dllexport)or__attribute__((visibility("default")))annotations — visibility is controlled at the shared-library level. The macro is provided so that vendored ONNX headers that decorate their declarations withONNX_APIcompile without modification.Namespace alias so that ONNX C++ code (and consumers such as onnxruntime) that refers to the literal
onnxnamespace — rather than theONNX_NAMESPACEmacro — resolves to the onnx-light namespace. The standard onnx package lives innamespace onnx; onnx-light usesonnx_light(via ONNX_LIGHT_NAMESPACE), so this alias keeps onnx-light a true drop-in. It is only introduced when the onnx-light namespace differs fromonnx.Enums
Functions
-
inline const char *AttributeProto_AttributeType_Name(AttributeProto::AttributeType t)#
-
class AttributeProto : public onnx_light::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 AttributeProto_AttributeType_UNDEFINED#
-
enumerator AttributeProto_AttributeType_FLOAT#
-
enumerator AttributeProto_AttributeType_INT#
-
enumerator AttributeProto_AttributeType_STRING#
-
enumerator AttributeProto_AttributeType_TENSOR#
-
enumerator AttributeProto_AttributeType_GRAPH#
-
enumerator AttributeProto_AttributeType_SPARSE_TENSOR#
-
enumerator AttributeProto_AttributeType_TYPE_PROTO#
-
enumerator AttributeProto_AttributeType_FLOATS#
-
enumerator AttributeProto_AttributeType_INTS#
-
enumerator AttributeProto_AttributeType_STRINGS#
-
enumerator AttributeProto_AttributeType_TENSORS#
-
enumerator AttributeProto_AttributeType_GRAPHS#
-
enumerator AttributeProto_AttributeType_SPARSE_TENSORS#
-
enumerator AttributeProto_AttributeType_TYPE_PROTOS#
-
enumerator UNDEFINED#
Public Members
-
onnx_light::utils::String name#
“Attribute name. This field MUST be present in this version of the IR.”
-
onnx_light::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_light::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_light::utils::OptionalField<float> f#
“Optional float attribute.”
-
onnx_light::utils::OptionalField<int64_t> i#
“Optional int64 attribute.”
-
onnx_light::utils::String s#
“Optional string attribute.”
-
onnx_light::utils::OptionalField<TensorProto> t#
“Optional tensor attribute.”
-
onnx_light::utils::OptionalField<GraphProto> g#
“Optional graph attribute.”
-
onnx_light::utils::OptionalField<SparseTensorProto> sparse_tensor#
“Optional sparse tensor attribute.”
-
onnx_light::utils::RepeatedField<float> floats#
“Optional repeated float attribute.”
-
onnx_light::utils::RepeatedField<int64_t> ints#
“Optional repeated int64 attribute.”
-
onnx_light::utils::RepeatedField<utils::String> strings#
“Optional repeated string attribute.”
-
onnx_light::utils::RepeatedProtoField<TensorProto> tensors#
“Optional repeated tensor attribute.”
-
onnx_light::utils::RepeatedProtoField<SparseTensorProto> sparse_tensors#
“Optional repeated tensor attribute.”
-
onnx_light::utils::RepeatedProtoField<GraphProto> graphs#
“Optional repeated graph attribute.”
-
onnx_light::utils::OptionalField<TypeProto> tp#
“Type proto”
-
onnx_light::utils::RepeatedProtoField<TypeProto> type_protos#
“Optional repeated type_proto attribute.”
Public Static Functions
-
static inline const char *AttributeType_Name(AttributeType t)#
-
enum AttributeType#
-
class DeviceConfigurationProto : public onnx_light::Message#
- #include <onnx.h>
“Describes a multi-device configuration for a model.”
Public Members
-
onnx_light::utils::String name#
“This field MUST be present for this version of the IR. Name of the configuration.”
-
int32_t num_devices#
“This field MUST be present for this version of the IR. Number of devices inside “ “this configuration.”
-
onnx_light::utils::RepeatedField<utils::String> device#
“Optional names of the devices. MUST be length of num_devices if provided.”
-
onnx_light::utils::String name#
-
class FunctionProto : public onnx_light::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 Functions
-
NodeProto &add_node(const std::string &op_type, const std::vector<std::string> &inputs, const std::vector<std::string> &outputs, const std::string &domain = "", const std::string &name = "")#
Appends a new node built from op_type, inputs, outputs and the optional domain / name to the function body and returns a reference to it. Convenience wrapper around the :ref:
MakeNodefactory.
-
OperatorSetIdProto &add_opset(const std::string &domain, int64_t version)#
Appends an opset import
(domain, version)and returns a reference to the newly added entry.
-
StringStringEntryProto &add_metadata(const std::string &key, const std::string &value)#
Sets metadata property key to value, updating an existing entry with the same key in place, and returns a reference to the stored entry.
Public Members
-
onnx_light::utils::String name#
“The name of the function. This field MUST be present in this version of the IR.”
-
onnx_light::utils::RepeatedProtoField<AttributeProto> attribute_proto#
“typed attributes”
-
onnx_light::utils::RepeatedProtoField<NodeProto> node#
“The nodes in the graph, sorted topologically.”
-
onnx_light::utils::String doc_string#
“A human-readable documentation for this graph. Markdown is allowed.”
-
onnx_light::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_light::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_light::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_light::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_light::utils::RepeatedField<StringStringEntryProto> metadata_props#
“Named metadata values; keys should be distinct.”
-
NodeProto &add_node(const std::string &op_type, const std::vector<std::string> &inputs, const std::vector<std::string> &outputs, const std::string &domain = "", const std::string &name = "")#
-
class GraphProto : public onnx_light::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 Functions
-
NodeProto &add_node(const std::string &op_type, const std::vector<std::string> &inputs, const std::vector<std::string> &outputs, const std::string &domain = "", const std::string &name = "")#
Appends a new node built from op_type, inputs, outputs and the optional domain / name to the graph and returns a reference to it. Convenience wrapper around the :ref:
MakeNodefactory.
-
StringStringEntryProto &add_metadata(const std::string &key, const std::string &value)#
Sets metadata property key to value, updating an existing entry with the same key in place, and returns a reference to the stored entry.
Public Members
-
onnx_light::utils::RepeatedProtoField<NodeProto> node#
“The nodes in the graph, sorted topologically.”
-
onnx_light::utils::String name#
“The name of the graph.”
-
onnx_light::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_light::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_light::utils::String doc_string#
“A human-readable documentation for this graph. Markdown is allowed.”
-
onnx_light::utils::RepeatedProtoField<ValueInfoProto> input#
“Inputs of the graph, shapes and types are optional in a subgraph and “ “mandatory in the main graph.”
-
onnx_light::utils::RepeatedProtoField<ValueInfoProto> output#
“Outputs of the graph, shapes and types are optional in a subgraph and mandatory in the “ “main graph.”
-
onnx_light::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_light::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_light::utils::RepeatedField<StringStringEntryProto> metadata_props#
“Named metadata values; keys should be distinct.”
-
NodeProto &add_node(const std::string &op_type, const std::vector<std::string> &inputs, const std::vector<std::string> &outputs, const std::string &domain = "", const std::string &name = "")#
-
class IntIntListEntryProto : public onnx_light::Message#
- #include <onnx.h>
“Defines a key value pair, key is an integer, value is a list of integers.”
Public Members
-
int64_t key#
“the key”
-
onnx_light::utils::RepeatedField<int64_t> value#
“the value is a list of integers”
-
int64_t key#
-
class MapProto : public onnx_light::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_light::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_light::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_light::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_light::utils::String name#
-
class ModelProto : public onnx_light::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
-
FunctionProto &add_function(const FunctionProto &function)#
Appends function to the model’s
functionsfield and returns a reference to the stored copy.
-
OperatorSetIdProto &add_opset(const std::string &domain, int64_t version)#
Appends an opset import
(domain, version)and returns a reference to the newly added entry.
-
StringStringEntryProto &add_metadata(const std::string &key, const std::string &value)#
Sets metadata property key to value, updating an existing entry with the same key in place, and returns a reference to the stored entry.
-
bool 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. Returns
falsewhenSerializeOptions.max_serialized_size_bytesis exceeded; in that case both out and external_files are cleared.
-
bool 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. Returns
falsewhenSerializeOptions.max_serialized_size_bytesis exceeded; in that case both out and external_files are cleared.
Public Members
-
onnx_light::utils::OptionalField<int64_t> ir_version#
“The version of the IR this model targets. See Version enum above. This field MUST be present.”
-
onnx_light::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_light::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_light::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_light::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_light::utils::OptionalField<int64_t> model_version#
“The version of the graph encoded. See Version enum below.”
-
onnx_light::utils::String doc_string#
“A human-readable documentation for this graph. Markdown is allowed.”
-
onnx_light::utils::OptionalField<GraphProto> graph#
“The parameterized graph that is evaluated to execute the model.”
-
onnx_light::utils::RepeatedField<StringStringEntryProto> metadata_props#
“Named metadata values; keys should be distinct.”
-
onnx_light::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_light::utils::RepeatedField<DeviceConfigurationProto> configuration#
“Describes different target configurations for a multi-device use case. A model MAY “ “describe multiple multi-device configurations for execution.”
-
FunctionProto &add_function(const FunctionProto &function)#
-
class NodeDeviceConfigurationProto : public onnx_light::Message#
- #include <onnx.h>
“Defines a multi-device configuration proto for NodeProto.”
Public Members
-
onnx_light::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_light::utils::RepeatedField<ShardingSpecProto> sharding_spec#
“Sharding spec for the node.”
-
onnx_light::utils::OptionalField<int32_t> pipeline_stage#
“Pipeline stage of this node.”
-
onnx_light::utils::String configuration_id#
-
class NodeProto : public onnx_light::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 Functions
-
AttributeProto &set_attribute(const AttributeProto &attr)#
Replaces an existing attribute with the same name in place, or appends attr to
attributeif no entry with that name exists yet, and returns a reference to the stored attribute.
-
StringStringEntryProto &add_metadata(const std::string &key, const std::string &value)#
Sets metadata property key to value, updating an existing entry with the same key in place, and returns a reference to the stored entry.
Public Members
-
onnx_light::utils::String name#
“An optional identifier for this node in a graph. This field MAY be absent in this version “ “of the IR.”
-
onnx_light::utils::String op_type#
“The symbolic identifier of the Operator to execute.”
-
onnx_light::utils::RepeatedProtoField<AttributeProto> attribute#
“Attributes associated with this node.”
-
onnx_light::utils::String domain#
“The domain of the OperatorSet that specifies the operator named by op_type.”
-
onnx_light::utils::String overload#
“Overload identifier, used only to map this to a model-local function.”
-
onnx_light::utils::String doc_string#
“A human-readable documentation for this node. Markdown is allowed.”
-
onnx_light::utils::RepeatedField<StringStringEntryProto> metadata_props#
“Named metadata values; keys should be distinct.”
-
onnx_light::utils::RepeatedField<NodeDeviceConfigurationProto> device_configurations#
“Configuration of multi-device annotations.”
-
AttributeProto &set_attribute(const AttributeProto &attr)#
-
class OperatorSetIdProto : public onnx_light::Message#
- #include <onnx.h>
“Defines a unique pair domain, opset version for a set of operators.”
Public Members
-
onnx_light::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_light::utils::String domain#
-
class OptionalProto : public onnx_light::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_light::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_light::utils::OptionalField<TensorProto> tensor_value#
“For TensorProto value. “ “When this field is present, the elem_type field MUST be TENSOR.”
-
onnx_light::utils::OptionalField<SparseTensorProto> sparse_tensor_value#
“For SparseTensorProto value. “ “When this field is present, the elem_type field MUST be SPARSE_TENSOR.”
-
onnx_light::utils::OptionalField<SequenceProto> sequence_value#
“For SequenceProto value. When this field is present, the elem_type field MUST be SEQUENCE.”
-
onnx_light::utils::OptionalField<MapProto> map_value#
“For MapProto value. “ “When this field is present, the elem_type field MUST be MAP.”
-
onnx_light::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_light::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_light::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_light::utils::RepeatedProtoField<TensorProto> tensor_values#
“For TensorProto values. “ “When this field is present, the elem_type field MUST be TENSOR. “
-
onnx_light::utils::RepeatedProtoField<SparseTensorProto> sparse_tensor_values#
“For SparseTensorProto values. “ “When this field is present, the elem_type field MUST be SPARSE_TENSOR. “
-
onnx_light::utils::RepeatedProtoField<SequenceProto> sequence_values#
“For SequenceProto values. “ “When this field is present, the elem_type field MUST be SEQUENCE. “
-
onnx_light::utils::RepeatedProtoField<MapProto> map_values#
“For MapProto values. “ “When this field is present, the elem_type field MUST be MAP. “
-
onnx_light::utils::RepeatedProtoField<OptionalProto> optional_values#
“For Optional values. “ “When this field is present, the elem_type field MUST be OPTIONAL. “
-
onnx_light::utils::String name#
-
class ShardedDimProto : public onnx_light::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_light::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_light::Message#
- #include <onnx.h>
“Describes the sharding spec for a specific, input or output tensor of a node.”
Public Members
-
onnx_light::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_light::utils::RepeatedField<int64_t> device#
“The following is the list of devices across which the logical tensor is “ “sharded or replicated.”
-
onnx_light::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_light::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_light::utils::String tensor_name#
-
class SimpleShardedDimProto : public onnx_light::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_light::utils::OptionalField<int64_t> dim_value#
“Dimension value to be sharded if it is a fixed value.”
-
onnx_light::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_light::utils::OptionalField<int64_t> dim_value#
-
class SparseTensorProto : public onnx_light::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_light::utils::RepeatedField<int64_t> dims#
“The shape.”
-
TensorProto values#
-
class StringStringEntryProto : public onnx_light::Message#
- #include <onnx.h>
“Defines a key value pair, both defines a string.”
Public Members
-
onnx_light::utils::String key#
“the key”
-
onnx_light::utils::String value#
“the value”
-
onnx_light::utils::String key#
-
class TensorAnnotation : public onnx_light::Message#
- #include <onnx.h>
“Defines a tensor annotation, useful for quantized tensors.”
Public Members
-
onnx_light::utils::String tensor_name#
“tensor name”
-
onnx_light::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_light::utils::String tensor_name#
-
class TensorProto : public onnx_light::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 TensorProto_DataType_UNDEFINED#
-
enumerator TensorProto_DataType_FLOAT#
-
enumerator TensorProto_DataType_UINT8#
-
enumerator TensorProto_DataType_INT8#
-
enumerator TensorProto_DataType_UINT16#
-
enumerator TensorProto_DataType_INT16#
-
enumerator TensorProto_DataType_INT32#
-
enumerator TensorProto_DataType_INT64#
-
enumerator TensorProto_DataType_STRING#
-
enumerator TensorProto_DataType_BOOL#
-
enumerator TensorProto_DataType_FLOAT16#
-
enumerator TensorProto_DataType_DOUBLE#
-
enumerator TensorProto_DataType_UINT32#
-
enumerator TensorProto_DataType_UINT64#
-
enumerator TensorProto_DataType_COMPLEX64#
-
enumerator TensorProto_DataType_COMPLEX128#
-
enumerator TensorProto_DataType_BFLOAT16#
-
enumerator TensorProto_DataType_FLOAT8E4M3FN#
-
enumerator TensorProto_DataType_FLOAT8E4M3FNUZ#
-
enumerator TensorProto_DataType_FLOAT8E5M2#
-
enumerator TensorProto_DataType_FLOAT8E5M2FNUZ#
-
enumerator TensorProto_DataType_UINT4#
-
enumerator TensorProto_DataType_INT4#
-
enumerator TensorProto_DataType_FLOAT4E2M1#
-
enumerator TensorProto_DataType_FLOAT8E8M0#
-
enumerator TensorProto_DataType_UINT2#
-
enumerator TensorProto_DataType_INT2#
-
enumerator UNDEFINED#
Public Functions
-
inline TensorProto()#
-
inline void Clear()#
-
inline void set_raw_data(const void *data, size_t size)#
Sets raw_data from a byte buffer (protobuf bytes-field compat).
-
inline void set_raw_data(const std::string &data)#
Sets raw_data from a std::string (protobuf bytes-field compat).
-
inline void set_data_type(int v)#
-
inline bool is_raw_data() const#
-
template<typename Deleter>
inline void set_raw_data_with_deleter(const uint8_t *ptr, size_t sz, Deleter &&deleter)# Sets the tensor raw data to a borrowed view of an external buffer and attaches a custom deleter called when all references to that buffer are dropped.
Stores ptr/sz as a borrowed view (identical to calling
ref_raw_data().assign_borrowed(ptr, sz)), but additionally schedules deleter() for invocation when the last copy of the internal owner token is destroyed (i.e., when the TensorProto, and all copies of it sharing the same buffer, go out of scope or are overwritten).The deleter receives no arguments and returns void. Any callable — lambda, function pointer, or functor — is accepted.
- Parameters:
ptr – Pointer to the first byte of tensor raw data.
sz – Number of raw data bytes.
deleter – Callable invoked once when the backing storage is released.
-
template<typename Deleter>
inline void attach_raw_data_deleter(Deleter &&deleter)# Attaches a custom deleter to this tensor’s
raw_datawithout changing the stored bytes.Unlike
set_raw_data_with_deleter, the currentraw_datapointer/size and storage mode (owned or borrowed) are left untouched; only a cleanup callback is registered. deleter() is invoked once when the last copy of the internal owner token is destroyed (i.e., when the TensorProto, and all copies of it sharing the same buffer, go out of scope or the buffer is overwritten/cleared). Any previously attached deleter/owner token is replaced.The deleter receives no arguments and returns void. Any callable — lambda, function pointer, or functor — is accepted.
- Parameters:
deleter – Callable invoked once when the backing storage is released.
-
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_light::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_light::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_light::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_light::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_light::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_light::utils::RepeatedField<int64_t> int64_data#
“For int64. When this field is present, the data_type field MUST be INT64”
-
onnx_light::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_light::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_light::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_light::utils::String doc_string#
“A human-readable documentation for this tensor. Markdown is allowed.”
-
onnx_light::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_light::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_light::utils::RepeatedField<StringStringEntryProto> metadata_props#
“Named metadata values; keys should be distinct.”
Public Static Functions
-
class Segment : public onnx_light::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_light::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.”
Public Members
-
onnx_light::utils::RepeatedField<Dimension> dim#
“Shape as a list of Dimension.”
-
class Dimension : public onnx_light::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 Types
Public Members
-
onnx_light::utils::OptionalField<int64_t> dim_value#
“Dimension value if it is a fixed value.”
-
onnx_light::utils::String dim_param#
“Dimension name if it is a dynamic value.”
-
onnx_light::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.”
-
onnx_light::utils::OptionalField<int64_t> dim_value#
-
onnx_light::utils::RepeatedField<Dimension> dim#
-
class TypeProto : public onnx_light::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_light::utils::OptionalField<Tensor> tensor_type#
“The type of a tensor.”
-
onnx_light::utils::OptionalField<Sequence> sequence_type#
“The type of a sequence.”
-
onnx_light::utils::OptionalField<Map> map_type#
“The type of a map.”
-
onnx_light::utils::OptionalField<Opaque> opaque_type#
“The type of an opaque object.”
-
onnx_light::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_light::utils::OptionalField<SparseTensor> sparse_tensor_type#
“Type of the sparse tensor”
-
onnx_light::utils::OptionalField<Optional> optional_type#
“The type of an optional.”
Public Static Attributes
-
static const ValueCase VALUE_NOT_SET = ValueCase::kUndefined#
-
class Map : public onnx_light::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;”
-
onnx_light::utils::OptionalField<TypeProto> value_type#
“This field MUST be present for this version of the IR.”
-
int32_t key_type#
-
class Opaque : public onnx_light::Message#
- #include <onnx.h>
“Defines an opaque, runtime-specific type identified by a domain and name.”
Public Members
-
onnx_light::utils::String domain#
“The domain of the opaque type.”
-
onnx_light::utils::String name#
“The name of the opaque type.”
-
onnx_light::utils::String domain#
-
class Optional : public onnx_light::Message#
- #include <onnx.h>
“Defines the type of an optional value.”
Public Members
-
onnx_light::utils::OptionalField<TypeProto> elem_type#
“The type and optional shape of the element wrapped. This field MUST be present for this “ “version of the IR. Possible values correspond to OptionalProto.DataType enum”
-
onnx_light::utils::OptionalField<TypeProto> elem_type#
-
class Sequence : public onnx_light::Message#
- #include <onnx.h>
“Defines the type of each element in a sequence.”
Public Members
-
onnx_light::utils::OptionalField<TypeProto> elem_type#
“The type and optional shape of each element of the sequence. This field MUST “ “be present for this version of the IR.”
-
onnx_light::utils::OptionalField<TypeProto> elem_type#
-
class SparseTensor : public onnx_light::Message#
- #include <onnx.h>
“Defines a sparse tensor type (element type, shape)”
Public Functions
-
inline void set_elem_type(int v)#
Public Members
-
onnx_light::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_light::utils::OptionalField<TensorShapeProto> shape#
“The shape.”
-
inline void set_elem_type(int v)#
-
class Tensor : public onnx_light::Message#
- #include <onnx.h>
“Defines a tensor type (element type, shape).”
Public Functions
-
inline void set_elem_type(int v)#
Public Members
-
onnx_light::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_light::utils::OptionalField<TensorShapeProto> shape#
“The shape.”
-
inline void set_elem_type(int v)#
-
onnx_light::utils::OptionalField<Tensor> tensor_type#
-
class ValueInfoProto : public onnx_light::Message#
- #include <onnx.h>
“Defines information on value, including the name, the type, and the shape of the value.”
Public Members
-
onnx_light::utils::String name#
“This field MUST be present in this version of the IR.”
-
onnx_light::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_light::utils::String doc_string#
“A human-readable documentation for this tensor. Markdown is allowed.”
-
onnx_light::utils::RepeatedField<StringStringEntryProto> metadata_props#
“Named metadata values; keys should be distinct.”
-
onnx_light::utils::String name#
-
inline const char *AttributeProto_AttributeType_Name(AttributeProto::AttributeType t)#