数据类型
模块:polygraphy.datatype
- class DataTypeEntry(name, itemsize, type: _DataTypeKind)[source]
基类:
object
表示一种数据类型。可以与外部模块(如 NumPy)的数据类型类相互转换。
不要直接构造此类型的对象。请改用
DataType
类中提供的预定义数据类型。- name
数据类型的可读名称
- itemsize
此数据类型单个元素的大小(以字节为单位)
- numpy()
将此 Polygraphy 数据类型转换为 NumPy 数据类型。
- 返回:
NumPy 数据类型。
- 返回类型:
np.dtype
- onnx()
将此 Polygraphy 数据类型转换为 ONNX 数据类型。
- 返回:
ONNX 数据类型。
- 返回类型:
onnx.TensorProto.DataType
- onnxruntime()
将此 Polygraphy 数据类型转换为 ONNX-Runtime 数据类型。
- 返回:
ONNX-Runtime 数据类型。
- 返回类型:
str
- tensorrt()
将此 Polygraphy 数据类型转换为 TensorRT 数据类型。
- 返回:
TensorRT 数据类型。
- 返回类型:
tensorrt.DataType
- torch()
将此 Polygraphy 数据类型转换为 PyTorch 数据类型。
- 返回:
PyTorch 数据类型。
- 返回类型:
torch.dtype
- class DataType[source]
基类:
object
聚合支持的 Polygraphy 数据类型。每种数据类型都可以通过此类作为
DataTypeEntry
类型的类成员进行访问。- 成员
FLOAT64
FLOAT32
FLOAT16
FLOAT4
INT16
INT32
INT64
INT8
INT4
UINT16
UINT32
UINT64
UINT8
BOOL
STRING
BFLOAT16
FLOAT8E4M3FN
FLOAT8E4M3FNUZ
FLOAT8E5M2
FLOAT8E5M2FNUZ
- static from_dtype(dtype, source_module=None)[source]
将来自任何已知外部库的数据类型转换为相应的 Polygraphy 数据类型。
- 参数:
dtype (Any) – 来自外部库的数据类型。
source_module (str) – 提供 dtype 的模块名称。如果未提供,Polygraphy 将尝试猜测模块以转换数据类型。
- 返回:
相应的 Polygraphy 数据类型。
- 返回类型:
- 引发:
PolygraphyException – 如果无法转换数据类型。
- static to_dtype(dtype, target_module)[source]
将 Polygraphy 数据类型转换为来自任何已知外部库的数据类型。
- 参数:
dtype (DataType) – Polygraphy 数据类型。如果提供的内容不是 Polygraphy 数据类型,则此函数将返回它,而无需修改。
target_module (str) – 要将此数据类型转换为其数据类型类的模块名称。
- 返回:
来自目标模块的相应数据类型。
- 返回类型:
Any
- 引发:
PolygraphyException – 如果无法转换数据类型。