assertlen(inp.shape)<=2,"Input should be 1d or 2d"
ifdescending:
order="DESCENDING"
order="descending"
else:
order="ASCENDING"
order="ascending"
op=builtin.Argsort(order=order)
iflen(inp.shape)==1:
...
...
@@ -699,11 +699,11 @@ def topk(
inp=-inp
ifkth_only:
mode="KTH_ONLY"
mode="kth_only"
elifno_sort:
mode="VALUE_IDX_NOSORT"
mode="value_idx_nosort"
else:
mode="VALUE_IDX_SORTED"
mode="value_idx_sorted"
op=builtin.TopK(mode=mode)
ifnotisinstance(k,Tensor):
...
...
@@ -765,8 +765,8 @@ def matmul(
inp2:Tensor,
transpose_a=False,
transpose_b=False,
compute_mode="DEFAULT",
format="DEFAULT",
compute_mode="default",
format="default",
)->Tensor:
"""
Performs a matrix multiplication of the matrices ``inp1`` and ``inp2``.
...
...
@@ -776,7 +776,9 @@ def matmul(
- Both 1-D tensor, simply forward to ``dot``.
- Both 2-D tensor, normal matrix multiplication.
- If one input tensor is 1-D, matrix vector multiplication.
- If at least one tensor are 3-dimensional or >3-dimensional, the other tensor should have dim >= 2, the batched matrix-matrix is returned, and the tensor with smaller dimension will be broadcasted. For example:
- If at least one tensor are 3-dimensional or >3-dimensional, the other tensor should have dim >= 2,
the batched matrix-matrix is returned, and the tensor with smaller dimension will be broadcasted.
Convolution bias with activation operation, only for inference.
...
...
@@ -35,27 +35,30 @@ def conv_bias_activation(
:param weight: convolution kernel.
:param bias: bias added to the result of convolution
:param stride: stride of the 2D convolution operation. Default: 1
:param padding: size of the paddings added to the input on both sides of its spatial dimensions. Only zero-padding is supported. Default: 0
:param padding: size of the paddings added to the input on both sides
of its spatial dimensions. Only zero-padding is supported. Default: 0
:param dilation: dilation of the 2D convolution operation. Default: 1
:param groups: number of groups into which the input and output channels are divided, so as to perform a "grouped convolution". When ``groups`` is not 1,
:param groups: number of groups into which the input and output channels are divided,
so as to perform a "grouped convolution". When ``groups`` is not 1,
``in_channels`` and ``out_channels`` must be divisible by ``groups``,
and the shape of weight should be `(groups, out_channel // groups,
in_channels // groups, height, width)`.
:type conv_mode: string or :class:`Convolution.Mode`.
:param conv_mode: supports 'CROSS_CORRELATION' or 'CONVOLUTION'. Default:
'CROSS_CORRELATION'
:param conv_mode: supports 'cross_correlation' or 'convolution'. Default:
'cross_correlation'
:param dtype: support for ``np.dtype``, Default: np.int8
:type compute_mode: string or
:class:`Convolution.ComputeMode`.
:param compute_mode: when set to "DEFAULT", no special requirements will be
placed on the precision of intermediate results. When set to "FLOAT32",
"Float32" would be used for accumulator and intermediate result, but only effective when input and output are of Float16 dtype.
:param compute_mode: when set to "default", no special requirements will be
placed on the precision of intermediate results. When set to "float32",
"float32" would be used for accumulator and intermediate result,
but only effective when input and output are of float16 dtype.
"""
ph,pw=_pair(padding)
sh,sw=_pair_nonzero(stride)
dh,dw=_pair_nonzero(dilation)
sparse_type="DENSE"ifgroups==1else"GROUP"
sparse_type="dense"ifgroups==1else"group"
op=builtin.ConvBias(
stride_h=sh,
stride_w=sw,
...
...
@@ -84,9 +87,9 @@ def batch_conv_bias_activation(
padding:Union[int,Tuple[int,int]]=0,
dilation:Union[int,Tuple[int,int]]=1,
groups:int=1,
nonlinear_mode="IDENTITY",
conv_mode="CROSS_CORRELATION",
compute_mode="DEFAULT",
nonlinear_mode="identity",
conv_mode="cross_correlation",
compute_mode="default",
)->Tensor:
"""
Batch convolution bias with activation operation, only for inference.
:param bias: bias added to the result of convolution
:param stride: stride of the 2D convolution operation. Default: 1
:param padding: size of the paddings added to the input on both sides of its spatial dimensions. Only zero-padding is supported. Default: 0
:param padding: size of the paddings added to the input on both sides
of its spatial dimensions. Only zero-padding is supported. Default: 0
:param dilation: dilation of the 2D convolution operation. Default: 1
:param groups: number of groups into which the input and output channels are divided, so as to perform a "grouped convolution". When ``groups`` is not 1,
:param groups: number of groups into which the input and output channels are divided,
so as to perform a "grouped convolution". When ``groups`` is not 1,
``in_channels`` and ``out_channels`` must be divisible by ``groups``,
and the shape of weight should be `(groups, out_channel // groups,
in_channels // groups, height, width)`.
:type conv_mode: string or :class:`Convolution.Mode`.
:param conv_mode: supports 'CROSS_CORRELATION' or 'CONVOLUTION'. Default:
'CROSS_CORRELATION'
:param conv_mode: supports 'cross_correlation' or 'convolution'. Default:
'cross_correlation'
:param dtype: support for ``np.dtype``, Default: np.int8
:type compute_mode: string or
:class:`Convolution.ComputeMode`.
:param compute_mode: when set to "DEFAULT", no special requirements will be
placed on the precision of intermediate results. When set to "FLOAT32",
"Float32" would be used for accumulator and intermediate result, but only effective when input and output are of Float16 dtype.
:param compute_mode: when set to "default", no special requirements will be
placed on the precision of intermediate results. When set to "float32",
"float32" would be used for accumulator and intermediate result,
but only effective when input and output are of float16 dtype.
:param compute_mode: When set to "default", no special requirements will be
placed on the precision of intermediate results. When set to "float32",
"float32" would be used for accumulator and intermediate result, but only
effective when input and output are of float16 dtype.
Examples:
...
...
@@ -336,8 +336,8 @@ class Conv2d(_ConvNd):
dilation:Union[int,Tuple[int,int]]=1,
groups:int=1,
bias:bool=True,
conv_mode:str="CROSS_CORRELATION",
compute_mode:str="DEFAULT",
conv_mode:str="cross_correlation",
compute_mode:str="default",
**kwargs
):
kernel_size=_pair_nonzero(kernel_size)
...
...
@@ -436,15 +436,16 @@ class Conv3d(_ConvNd):
:param padding: size of the paddings added to the input on both sides of its
spatial dimensions. Only zero-padding is supported. Default: 0
:param dilation: dilation of the 3D convolution operation. Default: 1
:param groups: number of groups into which the input and output channels are divided, so as to perform a "grouped convolution". When ``groups`` is not 1,
:param groups: number of groups into which the input and output channels are divided,
so as to perform a "grouped convolution". When ``groups`` is not 1,
``in_channels`` and ``out_channels`` must be divisible by ``groups``,
and there would be an extra dimension at the beginning of the weight's
shape. Specifically, the shape of weight would be `(groups,