PackedTensor

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

以打包格式存储 4 位数据类型的张量。

0.1.2 版本新增。

参数:
  • 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)

漂亮地打印对象。

参数:

page (bool) – 是否分页输出。

返回类型:

property doc_string: str | None

文档字符串。

property dtype: DataType

张量的数据类型。不可变。

property meta: MetadataStore

用于中间分析的元数据存储。

如果要将元数据序列化为 ONNX 协议,请写入 metadata_props

property metadata_props: dict[str, str]

张量的元数据属性。

元数据属性用于存储有关张量的附加信息。与 meta 不同,此属性被序列化为 ONNX 协议。

property name: str | None

张量的名称。

property nbytes: int

张量中的字节数。

numpy()[来源]

将张量作为 numpy 数组返回。

当数据类型不受 numpy 支持时,使用 ml_dtype 包中的数据类型。可以使用 .view() 方法将值重新解释为位表示。

返回类型:

ndarray

numpy_packed()[来源]

将张量作为打包数组返回。

返回类型:

npt.NDArray[np.uint8]

property raw: TArrayCompatible

张量的后台数据。不可变。

property shape: Shape

张量的形状。不可变。

property size: int

张量中的元素数量。

tobytes()[来源]

以小端编码的字节形式返回该值。

当原始值不是 numpy 数组时,覆盖此方法以实现更高效的序列化。

返回类型:

bytes

tofile(file)[来源]

将张量写入二进制文件。

在 0.1.11 版本中添加。

参数:

file – 一个具有接受字节的 write 方法或具有 fileno() 方法的类文件对象。

返回类型: