TensorProto#
- class onnx_light.onnx.TensorProto(*args, **kwargs)#
Defines a tensor and its content.
- CopyFrom(self, arg: onnx_light.onnx_py._onnxpy.TensorProto, /) None#
Copies one instance into this one.
- class DataLocation(*values)#
- class DataType(*values)#
- ParseFromFile(self, name: str, options: object | None = None, external_data_file: str = '') None#
Parses a binary file to fill this instance.
- ParseFromString(self, data: bytes, options: object | None = None) None#
- ParseFromString(self, data: str, options: object | None = None) None
Overloaded function.
ParseFromString(self, data: bytes, options: object | None = None) -> None
Parses a sequence of bytes to fill this instance.
ParseFromString(self, data: str, options: object | None = None) -> None
Parses a string to fill this instance.
- SerializeSize(self, options: object | None = None) onnx_light.onnx_py._onnxpy.SerializeSizeResult#
Returns the size once serialized without serializing.
- SerializeToFile(self, name: str, options: object | None = None, external_data_file: str = '') None#
Serializes this instance into a file. If
external_data_sizeis not empty, big weights are stored in this (depending onoptions.raw_data_threshold). When writing to two files, temporary external-data metadata is cleared so the in-memory model stays unchanged.
- SerializeToString(self, options: object | None = None) bytes#
Serializes this instance into a sequence of bytes.
- property data_location#
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.
- Type:
Location of the data for this tensor. MUST be one of
- property data_type#
The data type of the tensor. This field MUST have a valid TensorProto.DataType value
- property dims#
The shape of the tensor.
- property doc_string#
A human-readable documentation for this tensor. Markdown is allowed.
- property 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.
- property external_data#
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.
- Type:
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
- property 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.
- property int32_data#
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
- Type:
For int32, uint8, int8, uint16, int16, uint4, int4, bool, (b)float16, float8, and float4
- Type:
(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
- property int64_data#
For int64. When this field is present, the data_type field MUST be INT64
- load_external_data(self, base_dir: str = '') None#
Loads the raw bytes of this tensor from the external file described by its
external_datafield intoraw_data. Theexternal_dataanddata_locationfields are preserved.
- property metadata_props#
Named metadata values; keys should be distinct.
- property name#
Optionally, a name for the tensor.
- property raw_data#
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.
- Type:
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
- property 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
- property uint64_data#
For uint64 and uint32 values. When this field is present, the data_type field MUST be UINT32 or UINT64.