hidet
hidet¶
Hidet is an opensource DNN inference framework based on compilation.
Functions:

Create an uninitialized tensor. 

Create a tensor with uniformly distributed values. 

Create a tensor initialized with zero. 

Create a tensor initialized with one. 

Create a tensor initialized with given constant. 

Create a symbolic tensor. 

Convert a list, tuple, or numpy ndarray to a hidet tensor. 

Create a hidet tensor from pytorch tensor. 

Create an uninitialized tensor with the same shape, dtype, and device as the given tensor. 

Create a randomly initialized tensor with the same shape, dtype, and device as the given tensor. 

Create a tensor initialized with zero with the same shape, dtype, and device as the given tensor. 

Create a tensor initialized with one with the same shape, dtype, and device as the given tensor. 

Create a symbol tensor like an existing tensor. 

Create a tensor initialized with fill_value with the same shape, dtype, and device as the given tensor. 

Trace the flow graph given the output tensor(s). 

Create a hidet tensor from an object that implements the __dlpack__ protocol. 

Decorator to convert a Python function to a Hidet function. 
 hidet.empty(shape, dtype='float32', device='cpu', layout=None)[source]¶
Create an uninitialized tensor.
 Parameters
shape (Sequence[int]) – The shape of new tensor.
dtype (str or DataType) – The data type of element of the tensor.
device (Device or str, default 'cpu') – The device of the new tensor is created on.
layout (DataLayout, optional) – The layout of the new tensor. None indicates the default layout (rowmajor layout).
 Returns
ret – The created tensor.
 Return type
 hidet.randn(shape, dtype='float32', mean=0.0, stddev=1.0, device='cpu')[source]¶
Create a tensor with uniformly distributed values.
 Parameters
shape (Sequence[int]) – The shape of new tensor.
dtype (DataType or str, default 'float32') – The data type of element of the tensor.
mean (float, default 0.0) – The mean of the uniform distribution.
stddev (float, default 1.0) – The standard deviation of the uniform distribution.
device (Device or str, default 'cpu') – The device of the new tensor is created on.
 Returns
ret – The created tensor.
 Return type
Examples
>>> randn([2, 3]) Tensor(shape=[2, 3], dtype='float32', device='cuda') [[ 0.10720467 1.6906018 0.06347568] [0.37061226 0.562728 1.857547 ]]
 hidet.full(shape, fill_value, dtype='float32', device='cpu')[source]¶
Create a tensor initialized with given constant.
 Parameters
shape (Sequence[int]) – The shape of new tensor.
fill_value (float or int or hidet.ir.Constant) – The constant to initialize the new tensor.
dtype (DataType or str, default 'float32') – The data type of element of the tensor.
device (Device or str, default 'cpu') – The device of the new tensor is created on.
 Returns
ret – The created tensor.
 Return type
 hidet.symbol(shape, dtype='float32', device='cpu', layout=None)[source]¶
Create a symbolic tensor.
 Parameters
shape (Sequence[int]) – The shape of new tensor.
dtype (str) – The data type of element of the tensor.
device (Device or str, default 'cpu') – The device of the new tensor is created on.
layout (DataLayout, optional) – The layout of the new tensor. None indicates the default layout (rowmajor layout).
 Returns
ret – The created tensor.
 Return type
 hidet.asarray(obj, /, *, dtype=None, device=None)[source]¶
Convert a list, tuple, or numpy ndarray to a hidet tensor.
 Parameters
 Returns
ret – The hidet tensor converted from given object.
 Return type
 hidet.from_torch(torch_tensor)[source]¶
Create a hidet tensor from pytorch tensor.
The created tensor shared the same memory as given pytorch tensor. Thus, any content modification on one tensor would be reflected on the other one.
 Parameters
torch_tensor (torch.Tensor) – The pytorch tensor.
 Returns
ret – The created hidet tensor.
 Return type
 hidet.empty_like(data, shape=None, dtype=None, device=None, layout=None)[source]¶
Create an uninitialized tensor with the same shape, dtype, and device as the given tensor.
 Parameters
data (Tensor) – The tensor to copy shape, dtype, and device from.
shape (Sequence[int], optional) – The shape of new tensor. If None, the shape of data is used.
dtype (DataType or str, optional) – The data type of element of the tensor. If None, the dtype of data is used.
device (Device or str, optional) – The device of the new tensor is created on. If None, the device of data is used.
layout (DataLayout, optional) – The layout of the new tensor. If None, the layout of data is used.
 Returns
ret – The created tensor.
 Return type
 hidet.randn_like(data, mean=0.0, stddev=1.0, shape=None, dtype=None, device=None)[source]¶
Create a randomly initialized tensor with the same shape, dtype, and device as the given tensor.
 Parameters
data (Tensor) – The tensor to copy shape, dtype, and device from.
mean (float, optional) – The mean of the normal distribution.
stddev (float, optional) – The standard deviation of the normal distribution.
shape (Sequence[int], optional) – The shape of new tensor. If None, the shape of data is used.
dtype (DataType or str, optional) – The data type of element of the tensor. If None, the dtype of data is used.
device (Device or str, optional) – The device of the new tensor is created on. If None, the device of data is used.
 Returns
ret – The created tensor with random values sampled from a normal distribution.
 Return type
 hidet.zeros_like(data, shape=None, dtype=None, device=None)[source]¶
Create a tensor initialized with zero with the same shape, dtype, and device as the given tensor.
 Parameters
data (Tensor) – The tensor to copy shape, dtype, and device from.
shape (Sequence[int], optional) – The shape of new tensor. If None, the shape of data is used.
dtype (DataType or str, optional) – The data type of element of the tensor. If None, the dtype of data is used.
device (Device or str, optional) – The device of the new tensor is created on. If None, the device of data is used.
 Returns
ret – The created tensor with all elements as zero.
 Return type
 hidet.ones_like(data, shape=None, dtype=None, device=None)[source]¶
Create a tensor initialized with one with the same shape, dtype, and device as the given tensor.
 Parameters
data (Tensor) – The tensor to copy shape, dtype, and device from.
shape (Sequence[int], optional) – The shape of new tensor. If None, the shape of data is used.
dtype (DataType or str, optional) – The data type of element of the tensor. If None, the dtype of data is used.
device (Device or str, optional) – The device of the new tensor is created on. If None, the device of data is used.
 Returns
ret – The created tensor with all elements as one.
 Return type
 hidet.symbol_like(data, shape=None, dtype=None, device=None, layout=None)[source]¶
Create a symbol tensor like an existing tensor.
 Parameters
data (Tensor) – The tensor to copy shape, dtype, and device from.
shape (Sequence[int], optional) – The shape of new tensor. If None, the shape of data is used.
dtype (DataType or str, optional) – The data type of element of the tensor. If None, the dtype of data is used.
device (Device or str, optional) – The device of the new tensor is created on. If None, the device of data is used.
layout (DataLayout, optional) – The layout of the new tensor. If None, the layout of data is used.
 Returns
ret – The created symbol tensor.
 Return type
 hidet.full_like(data, fill_value, shape=None, dtype=None, device=None)[source]¶
Create a tensor initialized with fill_value with the same shape, dtype, and device as the given tensor.
 Parameters
data (Tensor) – The tensor to copy shape, dtype, and device from.
fill_value (int, float, or bool) – The value to fill the tensor with.
shape (Sequence[int], optional) – The shape of new tensor. If None, the shape of data is used.
dtype (DataType or str, optional) – The data type of element of the tensor. If None, the dtype of data is used.
device (Device or str, optional) – The device of the new tensor is created on. If None, the device of data is used.
 Returns
ret – The created tensor with all elements as fill_value.
 Return type
 hidet.trace_from(tensor, inputs=None)[source]¶
Trace the flow graph given the output tensor(s).
Each
hidet.graph.Tensor
has an attributehidet.graph.Tensor.trace
which indicates how the tensor is generated. If the tensor is generated by an operator with symbolic input(s), the tensor itself is also symbolic. And the tensor will have a reference to the operator that generates it. The reference is stored in this attribute.What this function does is to walk through the trace of the given tensor(s) and construct a flow graph.
When there are multiple symbol inputs, it is mandatory to specify the “inputs” argument explicitly to avoid ambiguity.
 Parameters
tensor (Tensor or List[Tensor]) – The output tensor(s) that we trace from.
inputs (Optional, Tensor or List[Tensor]) – The inputs of the flow graph. When there is only a single symbol tensor in the flow graph, it is optional. When there are multiple inputs, this is required to specify the input order.
 Returns
ret – The flow graph that outputs the given input tensor(s).
 Return type
 hidet.from_dlpack(dltensor)[source]¶
Create a hidet tensor from an object that implements the __dlpack__ protocol.
 Parameters
dltensor (an object that implements the DLPack protocol.) – The object must have the method __dlpack__ that returns a PyCapsule object with name dltensor.
 Returns
ret – The hidet tensor that shares the same storage with the DLPack tensor.
 Return type