TensorProtocol¶

class onnx_ir.TensorProtocol(*args, **kwargs)¶

Concrete tensor backed by data.

The protocol does not specify how the data is stored. That data is exposed through the raw attribute for examination, but accessing raw is typically not needed.

To use the tensor as a numpy array, call numpy(). To convert the tensor to a byte string for serialization, call tobytes().

It is recommended to check the size of the tensor first before accessing the underlying data, because accessing the data may be expensive and incur IO overhead.

name¶

The name of the tensor.

Type:

str | None

shape¶

The shape of the tensor.

Type:

ShapeProtocol

dtype¶

The data type of the elements of the tensor. It is an ir.DataType enum.

Type:

_enums.DataType

doc_string¶

Documentation string.

Type:

str | None

raw¶

The raw data behind this tensor. It can be anything.

Type:

Any

size¶

The number of elements in the tensor.

nbytes¶

The number of bytes in the tensor.

metadata_props¶

Metadata that will be serialized to the ONNX file.

Type:

MutableMapping[str, str]

meta¶

Metadata store for graph transform passes.

Type:

MutableMapping[str, Any]

property nbytes: int¶
numpy() np.ndarray[source]¶

Return the tensor as a numpy array.

property size: int¶
tobytes() bytes[source]¶

Return the tensor as a byte string conformed to the ONNX specification, in little endian.

name: str | None¶
shape: ShapeProtocol¶
dtype: _enums.DataType¶
doc_string: str | None¶
raw: Any¶
metadata_props: MutableMapping[str, str]¶
meta: MutableMapping[str, Any]¶