Data Types
Module: polygraphy.datatype
- class DataTypeEntry(name, itemsize, type: _DataTypeKind)[source]
Bases:
object
Represents a data type. Can be transformed to and from data type classes of external modules, like NumPy.
Do not construct objects of this type directly. Instead, use the predefined data types provided in the
DataType
class.- name
The human-readable name of the data type
- itemsize
The size in bytes of a single element of this data type
- numpy()
Converts this Polygraphy DataType to a NumPy data type.
- Returns:
The NumPy data type.
- Return type:
np.dtype
- onnx()
Converts this Polygraphy DataType to an ONNX data type.
- Returns:
The ONNX data type.
- Return type:
onnx.TensorProto.DataType
- onnxruntime()
Converts this Polygraphy DataType to an ONNX-Runtime data type.
- Returns:
The ONNX-Runtime data type.
- Return type:
str
- tensorrt()
Converts this Polygraphy DataType to a TensorRT data type.
- Returns:
The TensorRT data type.
- Return type:
tensorrt.DataType
- torch()
Converts this Polygraphy DataType to a PyTorch data type.
- Returns:
The PyTorch data type.
- Return type:
torch.dtype
- class DataType[source]
Bases:
object
Aggregates supported Polygraphy data types. Each data type is accessible via this class as a class member of type
DataTypeEntry
.- Members:
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]
Converts a data type from any known external libraries to a corresponding Polygraphy data type.
- Parameters:
dtype (Any) – A data type from an external library.
source_module (str) – The name of the module from where the provided dtype originates. If this is not provided, Polygraphy will attempt to guess the module in order to convert the data type.
- Returns:
The corresponding Polygraphy data type.
- Return type:
- Raises:
PolygraphyException – If the data type could not be converted.
- static to_dtype(dtype, target_module)[source]
Converts a Polygraphy data type to one from any known external libraries.
- Parameters:
dtype (DataType) – A Polygraphy data type. If something other than a Polygraphy data type is provided, then this function will return it without modifying it.
target_module (str) – The name of the module whose data type class to convert this data type to.
- Returns:
The corresponding data type from the target module.
- Return type:
Any
- Raises:
PolygraphyException – If the data type could not be converted.