不同深度学习前端api定义对照表

You might also like

Download as xlsx, pdf, or txt
Download as xlsx, pdf, or txt
You are on page 1of 84

pattern 算子

kOpaque annotation.stop_fusion

# kOpaque tells TVM


annotation.cast_hint

kOpaque annotation.bitpack_start

kOpaque annotation.bitpack_end

kOpaque annotation.checkpoint

kOpaque annotation.compiler_begin
kOpaque annotation.compiler_end

kOpaque memory.alloc_storage

kOpaque memory.alloc_tensor

kOpaque memory.kill

kOpaque debug

kOpaque shape_of
kOpaque sliding_window

kOpaque argwhere

kOpaque scatter

kOpaque scatter_add

kOpaque scatter_nd

kOpaque arange
kOpaque sparse_fill_empty_rows

kOpaque stft

kOpaque sparse_to_dense

kOpaque cumsum

kOpaque cumprod

kOpaque unique
kOpaque device_copy

kOpaque on_device

kOpaque call_lowered

kOpaque dyn.sparse_to_dense

kOpaque nn.dropout
kCommReduce argmax

kCommReduce argmin

kCommReduce sum

kCommReduce all

kCommReduce any

kCommReduce max
kCommReduce min

kCommReduce prod

kCommReduce mean

kCommReduce variance

kBroadcast expand_dims
kBroadcast repeat

kBroadcast tile

kBroadcast where

kBroadcast broadcast_to

kBroadcast broadcast_to_like

kBroadcast dyn.broadcast_to(tvm/src/relay/op/dyn/tensor/transform.cc)
kBroadcast add

kBroadcast subtract

kBroadcast right_shift

kBroadcast left_shift

kBroadcast maximum

kBroadcast minimum
kBroadcast divide

kBroadcast trunc_divide

kBroadcast floor_divide

kBroadcast power

kBroadcast floor_mod

kBroadcast mod
kBroadcast trunc_mod

kBroadcast logical_and

kBroadcast logical_or

kBroadcast logical_xor

kBroadcast bitwise_and

kBroadcast bitwise_or
kBroadcast bitwise_xor

kBroadcast equal

kBroadcast not_equal

kBroadcast less

kBroadcast less_equal

kBroadcast greater
kBroadcast greater_equal

kInjective image.resize1d

kInjective image.resize2d

kInjective image.resize3d

kInjective image.crop_and_resize
kInjective nn.umsampling

kInjective nn.upsampling3d

kInjective dyn.reshape

kInjective dyn.tile

kInjective dyn.strided_slice

kInjective dyn.expand_dims
kInjective dyn.squeeze

kInjective concatenate

kInjective stack

kInjective transpose

kInjective reshape

kInjective reshape_like
kInjective take

kInjective sparse_reshape

kInjective meshgrid

kInjective reverse

kInjective reverse_sequence

kInjective squeeze
kInjective strided_slice

kInjective strided_set

kInjective split

kInjective slice_like

kInjective contrib_reverse_reshape

kInjective gather
kInjective gather_nd

kInjective sequence_mask

kInjective unravel_index

kInjective matrix_set_diag

kInjective adv_index

kInjective invert_permutation
kInjective dyn.nn.upsampling

kInjective dyn.nn.upsampling3d

kInjective image.affine_grid

kInjective image.grid_sample

kInjective einsum

kInjective nn.pad
kInjective nn.mirror_pad

kInjective dyn.nn.pad

kInjective dyn.image.resize2d

kInjective ndarray_size

kInjective nn.space_to_batch_nd

kInjective nn.batch_to_space_nd
elementwise clip

elementwise fixed_point_multiply

elementwise dyn.full

elementwise cast

elementwise cast_like
elementwise reinterpret

elementwise full

elementwise full_like

elementwise log

elementwise log2

elementwise log10
elementwise tan

elementwise cos

elementwise cosh

elementwise sin

elementwise sinh

elementwise acos
elementwise acosh

elementwise asin

elementwise asinh

elementwise atan

elementwise atanh

elementwise exp
elementwise fast_exp

elementwise erf

elementwise fast_erf

elementwise sqrt

elementwise rsqrt

elementwise ones_like
elementwise zeros_like

elementwise sigmoid

elementwise copy

elementwise floor

elementwise ceil

elementwise trunc
elementwise round

elementwise sign

elementwise abs

elementwise tanh

elementwise fast_tanh

elementwise negtive
elementwise logical_not

elementwise bitwise_not

elementwise isnan

elementwise isfinite

elementwise isinf
pytorch定义
torch.argmax(input, dim, keepdim=False) → LongTensor

torch.sum(input, *, dtype=None) → Tensor

torch.all(input, dim, keepdim=False, *, out=None) → Tensor

torch.max(input, dim, keepdim=False, *, out=None)


torch.prod(input, dim, keepdim=False, *, dtype=None) → Tensor

Tensor.expand(*sizes) → Tensor
Tensor.repeat(*sizes) → Tensor sizes (torch.Size or int...) – The number of times to rep

torch.tile(input, dims) → Tensor input (Tensor) – the tensor


whose elements to repeat.

dims (tuple) – the number of repetitions per dimension.

torch.where(condition, x, y) → Tensor
Return a tensor of elements selected from either x or y, depending on condition.

torch.broadcast_to(input, shape) → Tensor input (Tensor) – the input tensor.

shape (list, tuple, or torch.Size) – the new shape.

elay/op/dyn/tensor/transform.cc)
torch.maximum(input, other, *, out=None) → Tensor
torch.fmod(input, other, *, out=None) → Tensor torch.fmod(a, b) == a - a.div(b,
rounding_mode="trunc") * b input (Tensor) – the dividend

other (Tensor or Scalar) – the divisor


torch.reshape(input, shape) → Tensor


torch.take(input, index) → Tensor
Returns a new tensor with the elements of input at the given indices. The input tensor is
treated as if it were viewed as a 1-D tensor. The result takes the same shape as the indices.

torch.meshgrid(*tensors) currently has the same behavior as calling


numpy.meshgrid(*arrays, indexing=’ij’).

In the future torch.meshgrid will transition to indexing=’xy’ as the default.

https://github.com/pytorch/pytorch/issues/50276 tracks this issue with the goal of migrating


to NumPy’s behavior.

torch.squeeze(input, dim=None, *, out=None) → TensorIf the tensor has a batch dimension of


tensor (Tensor) – tensor to split.

split_size_or_sections (int) or (list(int)) – size of a single chunk or list of sizes for each
chunk

dim (int) – dimension along which to split the tensor.


tvm定义
argmax(data[, axis, keepdims, exclude, ...])

sum(data[, axis, keepdims, exclude])

tvm.relay.all(data, axis=None, keepdims=False, exclude=False)

max(data[, axis, keepdims, exclude])


prod(data[, axis, keepdims, exclude])

tvm.relay.variance(data, axis=None, keepdims=False, exclude=False, unbiased=False)

tvm.relay.expand_dims(data, axis, num_newaxis=1)


Insert num_newaxis axes at the position given by axis.

Parameters
data (relay.Expr) – The input data to the operator.

axis (Union[int, Expr]) – The axis at which the input array is expanded. Should lie in range [-
data.ndim - 1, data.ndim]. If axis < 0, it is the first axis inserted; If axis >= 0, it is the last axis
inserted in Python’s negative indexing.

num_newaxis (int) – Number of axes to be inserted. Should be >= 0.

Returns
result – The reshaped result.

Return type
relay.Expr
tvm.relay.repeat(data, repeats, axis)
Repeats elements of an array. By default, repeat flattens the input array into 1-D and then repeats
the elements.

repeatsint
The number of repetitions for each element.

axis: int
The axis along which to repeat values. The negative numbers are interpreted counting from the
backward. By default, use the flattened input array, and return a flat output array.

Returns
ret – The computed result.
tvm.relay.tile(data, reps)
Repeats the whole array multiple times.
Return type
relay.Expr
Parameters
data (relay.Expr) – The input data to the operator.

reps (tuple of int or relay.Expr) – The number of times repeating the tensor data.

tvm.relay.where(condition, x, y)
Selecting elements from either x or y depending on the value of the condition.
tvm.relay.maximum(lhs, rhs)
tvm.relay.mod(lhs, rhs)
Mod with numpy-style broadcasting.

Parameters
lhs (relay.Expr) – The left hand side input data

rhs (relay.Expr) – The right hand side input data



tvm.topi.nn.concatenate(a_tuple, axis=0)¶
Join a sequence of arrays along an existing axis.

Parameters
a_tuple (tuple of tvm.te.Tensor) – The arrays to concatenate
axis (int, optional) – The axis along which the arrays will be joined. Default is 0.

Returns
ret

Return type
tvm.te.Tensor

tvm.relay.reshape(data, newshape, allowzero=False)


Reshape the input array.
tvm.relay.meshgrid(data, indexing='ij')
Create coordinate matrices from coordinate vectors.Parameters
data (Union(List[relay.Expr], Tuple[relay.Expr])) – A list of tensors, which must be either scalars or
1-D vectors.

indexing (str) – Indexing mode, either “ij” for matrix indexing or “xy” for Cartesian indexing.

Returns
tvm.relay.reverse(data, axis)
ret – The computed result.
Reverses the order of elements along given axis while preserving array shape.
Return type
Parameters
relay.Tuple([relay.Expr, relay.Expr])
data (relay.Expr) – The input data to the operator.

axis (int) – The axis along which to reverse elements.

Returns
ret – The computed result.

Return type
relay.Expr

其他基本相同
Parameters
data (relay.Expr) – The source array.

indices_or_sections (int or tuple of int) – Indices or sections to split into. Accepts an int or a tuple

axis (int, optional) – The axis over which to split.

Returns
ret – The computed result.

Return type
relay.Tuple([relay.Expr, relay.Expr])
tensorflow定义
tf.math.argmax(
input,
axis=None,
output_type=tf.dtypes.int64,
name=None
)

Reduces input along the dimensions given in axis. Unless keep_dims is true, the rank of the tensor
is reduced by 1 for each entry in axis. If keep_dims is true, the reduced dimensions are retained
with length 1.

Args:

scope: A Scope object


input: The tensor to reduce.
axis: The dimensions to reduce. Must be in the range [-rank(input), rank(input)).
Optional attributes (see Attrs):

keep_dims: If true, retain reduced dimensions with length 1.


Returns:

Output: The reduced tensor.


Aliases:
tf.experimental.numpy.all(
a, axis=None, keepdims=None
ReduceSum
)

tft.max(
x: common_types.TensorType,
reduce_instance_dims: bool = True,
name: Optional[str] = None
) -> tf.Tensor
scope: A Scope object
input: The tensor to reduce.
axis: The dimensions to reduce. Must be in the range [-rank(input), rank(input)).
Optional attributes (see Attrs):

keep_dims: If true, retain reduced dimensions with length 1.


Returns:

Output: The reduced tensor.

tfp.stats.variance(
x, sample_axis=0, keepdims=False, name=None
)

Given a tensor input, this operation inserts a dimension of length 1 at the dimension index axis of
input's shape. The dimension index follows Python indexing rules: It's zero-based, a negative
index it is counted backward from the end.

This operation is useful to:

Add an outer "batch" dimension to a single element.


Align axes for broadcasting.
To add an inner vector length axis to a tensor of scalars.
tf.repeat(
input, repeats, axis=None, name=None
)

tf.tile(
input, multiples, name=None
) multiples A Tensor. Must be one of the following types:
int32, int64. 1-D. Length must be the same as the number of dimensions in input

Return the indices of non-zero elements - When only condition is provided the result is an int64
tensor where each row is the index of a non-zero element of condition. The result's shape is
[tf.math.count_nonzero(condition), tf.rank(condition)].
Multiplex x and y - When both x and y are provided the result has the shape of x, y, and condition
broadcast together. The result is taken from x where condition is non-zero or y where condition is
zero.
tf.reshape(
tensor, shape, name=None
)
tf.experimental.numpy.take(
a, indices, axis=None, out=None, mode='clip'
)
value The Tensor to split.
num_or_size_splits Either an int indicating the number of splits along axis or a 1-D integer
Tensor or Python list containing the sizes of each output tensor along axis. If an int, then it must
evenly divide value.shape[axis]; otherwise the sum of sizes along the split axis must match that of
the value.
axis An int or scalar int32 Tensor. The dimension along which to split. Must be in the range [-
rank(value), rank(value)). Defaults to 0.
num Optional, an int, used to specify the number of outputs when it cannot be inferred from the
shape of size_splits.
name A name for the operation (optional).
keras定义
keras.backend.argmax(x, axis=-1)

def sum(x, axis=None, keepdims=False):


if isinstance(axis, list):
axis = tuple(axis)
return np.sum(x, axis=axis, keepdims=keepdims)

keras.backend.max(x, axis=None, keepdims=False)


张量中的最大值。
keras.backend.prod(x, axis=None, keepdims=False)
在某一指定轴,计算张量中的值的乘积。

/
repeat_elements
keras.backend.repeat_elements(x, rep, axis)
repeat
keras.backend.repeat(x, n)
重复一个 2D 张量。

如果 x 的尺寸为 (samples, dim) 并且 n 为 2, 则输出的尺寸为


(samples, 2, dim)。

tile
keras.backend.tile(x, n)
创建一个用 n 平铺 的 x 张量。

/
keras.layers.maximum(inputs)inputs: 一个列表的输入张量(列表
大小至少为 2)。
**kwargs: 层的关键字参数。
keras.layers.concatenate(inputs, axis=-1)
Concatenate 层的函数式接口。

参数

inputs: 一个列表的输入张量(列表大小至少为 2)。


axis: 串联的轴。
**kwargs: 层的关键字参数。

keras.backend.reshape(x, shape)
将张量重塑为指定的尺寸。

参数

x: 张量或变量。
shape: 目标尺寸元组。
描述

Annotate an expression to prevent it being fused with following expressions.

Annotate an expression to be cast into specific data type.

Mark the start of bitpacking.

Mark the end of bitpacking.

Mark a checkpoint for checkpointing memory optimization.

Beginning of a region that is handled by a given compiler.


end of a region that is handled by a given compiler.

Explicitly allocate storage to be used by tensors.

Explicitly allocate storage to be used by tensors.

Mark a variable for release to the allocator.

Enter the interpreter's debugger.

Returns a tensor representing the shape of a tensor.


Slide window over a tensor.

Find the indices of elements of a tensor that are

Update data at positions defined by indices with values in updates

Update data by adding values in updates at positions defined by indices

Scatter elements or slices from data and store to a tensor

Returns evenly spaced values within a given interval.


Fill empty rows of a sparse tensor with a default value.

The STFT computes the Fourier transform of short overlapping windows of the input.

A dense tensor from a sparse representation.

Return the cumulative sum of the elements along a given axis.

Return the cumulative product of the elements along a given axis.

his operation returns the unique elements and the new index of each item in a given 1-D array
Copy data from one tensor to another. The source and destination
might be_x000D_
on different devices.

Annotate an expression with device type

Invoke an operation compiled by TVM.

A dense tensor from a sparse representation.

Applies the dropout operation to the input array.


Creates an operation that finds the indices of the minimum

Computes the sum of array elements over given axes.

Computes the logical AND of boolean array elements over given axes.

Computes the logical AND of boolean array elements over given axes.
Computes the products of array elements over given axes.

Computes the variance of array elements over given axes.

Insert `num_newaxis` axes at the position given by `axis`


Repeat elements of an array `repeats` times along axis `axis`

Repeat the whole array multiple times.

Return the elements, either from x or y, depending on the condition.

Broadcast the first input to match the shape argument.

Broadcast the first input to match the shape of the second input.

Broadcast the first input to match the shape argument


Elementwise add with broadcasting

.........with broadcasting
Perform resize to input array with nearest neighbour or bilinear interpolation.

Perform resize to input array with nearest neighbour or bilinear interpolation.

Perform resize to input array with nearest neighbour or bilinear interpolation.

Perform crop and resize to input array with nearest neighbour or bilinear interpolation.
Perform upsampling on input array with nearest neighbour or bilinear interpolation.

Perform upsampling on input array with nearest neighbour or bilinear interpolation.

Reshapes the input array based on the values in the newshape array.

Repeat the whole array multiple times.

Strided slice of an array.

Insert one new axis at the position given by `axis`


Remove axes of value 1 in input tensor at the dimensions given by axes
Take elements from an array along an axis.

Create coordinate matrices from coordinate vectors.

Reverses the tensor for variable length slices.


Strided set of an array.

Slice the first input respect to the second input.

Reshapes the input array where the special values are inferred from

Gather values along given axis from given indices.


Gather elements or slices from data and store to a tensor whose shape is defined by indices.

Sets all elements outside the expected length of the sequence to a constant value.

Converts a flat index or array of flat indices into a tuple of coordinate arrays.

Returns a tensor with the diagonals of input tensor replaced with the provided diagonal values.

Numpy style advanced indexing. Index with a list of tensors.

Computes the inverse permutation of a tensor.


Perform upsampling on input array with nearest neighbour or bilinear interpolation.

Perform upsampling on input array with nearest neighbour or bilinear interpolation.

affine_grid operator that generates 2D sampling grid.

Applies grid sampling to input feature map.

Evaluates the Einstein summation convention on the operands.

Pad for n-D tensor.


MirrorPad for n-D tensor.

Pad for n-D tensor.

Perform resize to input array with nearest neighbour or bilinear interpolation.

Returns a tensor representing the number of elements of input tensor.

Divide spatial dimensions of the input into a grid of blocks

Reshape the batch dimension into spatial dimensions.


This function takes a tensor, a minimum value `a_min`, and a maximum value `a_max`, and returns a clipped tensor where all v

fixed point multiplication

Fill array with scalar value.

Cast the data into a new data type.

Cast the data into the type of another tensor.


Reinterpret the data into a new data type.

Fill array with scalar value.

Return an scalar value array with the same shape


Returns the error function value for input array, computed element-wise.

Returns the error function value for input array, computed element-wise.
Returns the fast_tanh of input array, computed element-wise.
Returns whether the input contains any NaN, computed element-wise.

Returns the finiteness of input, computed element-wise.

Returns the infiniteness of input, computed element-wise.


ns a clipped tensor where all values below `a_min` are set to `a_min` and all values above `a_max` are set to `a_max`. `a_min` and `a_max`
`a_max`. `a_min` and `a_max` are cast to the tensor's dtype.

You might also like