PackedTensor¶

class onnx_ir.PackedTensor(value, dtype, *, shape, name=None, doc_string=None, metadata_props=None)¶

A tensor that stores 4bit datatypes in packed format.

Parameters:
  • value (TArrayCompatible)

  • dtype (_enums.DataType)

  • shape (Shape | Sequence[int])

  • name (str | None)

  • doc_string (str | None)

  • metadata_props (dict[str, str] | None)

display(*, page=False)¶

Pretty print the object.

Parameters:

page (bool) – Whether to page the output.

Return type:

None

property doc_string: str | None¶

The documentation string.

property dtype: DataType¶

The data type of the tensor. Immutable.

property meta: MetadataStore¶

The metadata store for intermediate analysis.

Write to the metadata_props if you would like the metadata to be serialized to the ONNX proto.

property metadata_props: dict[str, str]¶
property name: str | None¶

The name of the tensor.

property nbytes: int¶

The number of bytes in the tensor.

numpy()[source]¶

Return the tensor as a numpy array.

When the data type is not supported by numpy, the dtypes from the ml_dtype package are used. The values can be reinterpreted as bit representations using the .view() method.

Return type:

ndarray

numpy_packed()[source]¶

Return the tensor as a packed array.

Return type:

npt.NDArray[np.uint8]

property raw: TArrayCompatible¶

Backing data of the tensor. Immutable.

property shape: Shape¶

The shape of the tensor. Immutable.

property size: int¶

The number of elements in the tensor.

tobytes()[source]¶

Returns the value as bytes encoded in little endian.

Override this method for more efficient serialization when the raw value is not a numpy array.

Return type:

bytes