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