These three messages are defined in ONNX’s onnx-data.proto (onnx 1.23,
proto2, package onnx). A file of this format is one SequenceProto or one
OptionalProto; a MapProto appears inside them, or as the elements of a sequence. For
the bytes of tags and lengths, see the
Protocol Buffers reference.
SequenceProto
A sequence of values of one kind: tensors, sparse tensors, sequences, maps or optional values.
| Field | Name | Type | Wire type | Meaning |
|---|---|---|---|---|
| 1 | name | string | LEN | The value’s name. |
| 2 | elem_type | int32 | VARINT | What the elements are: a value from the table below. The parser requires it. |
| 3 | tensor_values | repeated TensorProto | LEN, one field per element | The elements, when elem_type is TENSOR. |
| 4 | sparse_tensor_values | repeated SparseTensorProto | LEN, one field per element | The elements, when SPARSE_TENSOR. |
| 5 | sequence_values | repeated SequenceProto | LEN, one field per element | The elements, when SEQUENCE: sequences nested in this one. |
| 6 | map_values | repeated MapProto | LEN, one field per element | The elements, when MAP. |
| 7 | optional_values | repeated OptionalProto | LEN, one field per element | The elements, when OPTIONAL. |
Only the field that matches elem_type may hold elements. The tensors
in a sequence share one element type; whether their shapes may differ depends on the
type the model declares. An empty sequence has a name and an
elem_type and no elements.
Element types
SequenceProto and OptionalProto each have an enum DataType with these
values. It is a different list from a tensor’s
data types.
| Value | Name | Values in field |
|---|---|---|
| 0 | UNDEFINED | none |
| 1 | TENSOR | 3 |
| 2 | SPARSE_TENSOR | 4 |
| 3 | SEQUENCE | 5 |
| 4 | MAP | 6 |
| 5 | OPTIONAL | 7 |
OptionalProto
A value that may be absent: at most one tensor, sparse tensor, sequence, map or optional value. It uses the same numbers and types as SequenceProto, but each value field holds one value, not a list.
| Field | Name | Type | Wire type | Meaning |
|---|---|---|---|---|
| 1 | name | string | LEN | The value’s name. |
| 2 | elem_type | int32 | VARINT | What the value is, from the table above; UNDEFINED (0) when it is absent. |
| 3 | tensor_value | TensorProto | LEN | The value, when TENSOR. |
| 4 | sparse_tensor_value | SparseTensorProto | LEN | The value, when SPARSE_TENSOR. |
| 5 | sequence_value | SequenceProto | LEN | The value, when SEQUENCE. |
| 6 | map_value | MapProto | LEN | The value, when MAP. |
| 7 | optional_value | OptionalProto | LEN | The value, when OPTIONAL. |
One element: the same bytes
A repeated message field and a single one are written the same way on the wire: one LEN field per element. So a SequenceProto with one element and an OptionalProto holding that value are byte for byte the same, and so are an empty sequence and an empty optional value of the same name and element type. Only a sequence of two or more elements cannot be an OptionalProto. The explorer says which readings are possible.
An empty optional value from ONNX’s test data:
| Bytes | Field | Value |
|---|---|---|
0A 0E + 14 bytes | name | optional_input |
10 00 | elem_type | 0, UNDEFINED: the value is absent |
MapProto
A map: keys of one integer type or strings, and the values as a sequence of the same length.
| Field | Name | Type | Wire type | Meaning |
|---|---|---|---|---|
| 1 | name | string | LEN | The value’s name. |
| 2 | key_type | int32 | VARINT | The key type, a tensor data type: one of the integer types INT8 to UINT64, or STRING. |
| 3 | keys | repeated int64 | VARINT, or packed LEN | The keys, for integer key types. |
| 4 | string_keys | repeated bytes | LEN, one field per key | The keys, for STRING. |
| 5 | values | SequenceProto | LEN | The values, in the same order as the keys, one per key. |
No file holding a MapProto was among the files examined for this site.