NNVM Core Tensor Operators

This page contains the list of core tensor operator primitives pre-defined in NNVM. The core tensor operator primitives(nnvm.top) covers typical workloads in deep learning. They can represent workloads in front-end frameworks, and provide basic building blocks for optimization. Since deep learning is a fast evolving field and it is that possible to have operators that are not in here. NNVM is designed for this problem and can easily new operators without changing the core library.

Note

Each operator node in the graph IR contains the following two kinds of parameters.

  • inputs: positional list of input tensors
  • attrs: attributes about operator(e.g. kernel_size in conv2d)

This document lists both inputs and attributes in the parameter field. You can distinguish them by the marked type. The inputs are of type Tensor, while the rest parameters are attributes. To construct the graph with NNVM python API, a user can pass in the input Tensors as positional arguments, and attributes as keyword arguments.

Overview of Operators

Level 1: Basic Operators

This level enables fully connected multi-layer perceptron.

nnvm.symbol.dense Applies a linear transformation: \(Y = XW^T + b\).
nnvm.symbol.relu Computes rectified linear.
nnvm.symbol.tanh Computes hyperbolic tangent.
nnvm.symbol.sigmoid Computes sigmoid.
nnvm.symbol.exp Returns the exp input array, computed element-wise.
nnvm.symbol.log Returns the log input array, computed element-wise.
nnvm.symbol.sqrt Returns the sqrt input array, computed element-wise.
nnvm.symbol.elemwise_add Element-wise add
nnvm.symbol.elemwise_sub Element-wise substraction
nnvm.symbol.elemwise_mul Element-wise multiplication
nnvm.symbol.elemwise_div Element-wise multiplication
nnvm.symbol.elemwise_sum Adds all input arguments element-wise.
nnvm.symbol.flatten Flattens the input into a 2-D array.
nnvm.symbol.concatenate Joins input arrays along a given axis.
nnvm.symbol.expand_dims Inserts a new axis of size 1 into the array shape
nnvm.symbol.squeeze Squeeze axises in the array.
nnvm.symbol.split Splits an array along a particular axis into multiple sub-arrays.
nnvm.symbol.dropout Applies dropout operation to input array.
nnvm.symbol.batch_norm Batch normalization layer (Ioffe and Szegedy, 2014).
nnvm.symbol.softmax Computes softmax.
nnvm.symbol.log_softmax Computes log softmax.
nnvm.symbol.pad Pad for n-D tensor.
nnvm.symbol.block_grad Blocks gradient computation for input.

Level 2: Convolutions

This level enables typical convnet models.

nnvm.symbol.conv2d 2D convolution layer (e.g.
nnvm.symbol.conv2d_transpose Transposed 2D convolution layer (sometimes called Deconvolution).
nnvm.symbol.max_pool2d Max pooling operation for one dimensional data.
nnvm.symbol.avg_pool2d Average pooling operation for one dimensional data.
nnvm.symbol.global_max_pool2d Global max pooling operation for 2D data.
nnvm.symbol.global_avg_pool2d Global average pooling operation for 2D data.

Level 3: Additional Tensor Ops

nnvm.symbol.reshape Reshapes the input array.
nnvm.symbol.copy Copy tensor to another one.
nnvm.symbol.negative Elemenwise numeric negative
nnvm.symbol.floor Take floor input array, computed element-wise.
nnvm.symbol.ceil Take ceil input array, computed element-wise.
nnvm.symbol.round Round elements of the input to nearest integer.
nnvm.symbol.trunc Take truncated value of the input, element-wise.
nnvm.symbol.leaky_relu Leaky version of a Rectified Linear Unit.
nnvm.symbol.__add_scalar__ Tensor add scalar
nnvm.symbol.__sub_scalar__ Tensor substract scalar
nnvm.symbol.__rsub_scalar__ scalar substract Tensor
nnvm.symbol.__mul_scalar__ Tensor multiplies scalar
nnvm.symbol.__div_scalar__ Tensor divides scalar
nnvm.symbol.__rdiv_scalar__ scalar divides Tensor
nnvm.symbol.__pow_scalar__ Tensor power scalar
nnvm.symbol.__rpow_scalar__ scalar power Tensor
nnvm.symbol.__lshift_scalar__ Tensor left shift by scalar
nnvm.symbol.__rshift_scalar__ Tensor right shift by scalar

Level 4: Broadcast and Reductions

nnvm.symbol.transpose Permutes the dimensions of an array.
nnvm.symbol.broadcast_to Broadcasts the input array to a new shape.
nnvm.symbol.sum Computes the sum of array elements over given axes.
nnvm.symbol.min Computes the min of array elements over given axes.
nnvm.symbol.max Computes the max of array elements over given axes.
nnvm.symbol.broadcast_add Returns element-wise sum of the input arrays with broadcasting.
nnvm.symbol.broadcast_sub Returns element-wise difference of the input arrays with broadcasting.
nnvm.symbol.broadcast_mul Returns element-wise product of the input arrays with broadcasting.
nnvm.symbol.broadcast_div Returns element-wise division of the input arrays with broadcasting.
nnvm.symbol.clip Clips (limits) the values in an array.
nnvm.symbol.greater Greater function that returns a mask tensor with 1.0 if (left > right), otherwise 0.0 element-wise.
nnvm.symbol.less Less function that returns a mask tensor with 1.0 if (left < right), otherwise 0.0 element-wise.
nnvm.symbol.expand_like Expand an input array with the shape of second array.
nnvm.symbol.reshape_like Reshapes the input array by the size of another array.
nnvm.symbol.full Fill array with scalar value
nnvm.symbol.full_like Return an scalar value array with the same shape and type as the input array
nnvm.symbol.ones Fill target with ones
nnvm.symbol.ones_like Return an array of ones with the same shape and type as the input array.
nnvm.symbol.zeros Fill target with zeros
nnvm.symbol.zeros_like Return an array of zeros with the same shape and type as the input array.

Detailed Definitions

nnvm.symbol.dense(*args, **kwargs)

Applies a linear transformation: \(Y = XW^T + b\).

  • data: (x1, x2, …, xn, input_dim)
  • weight: (units, input_dim)
  • bias: (units,)
  • out: (x1, x2, …, xn, units)

The learnable parameters include both weight and bias.

If use_bias is set to be false, then the bias term is ignored.

Defined in /workspace/nnvm/src/top/nn/nn.cc:L77

Parameters:
  • data (nD Tensor) – Input data.
  • weight (2D Tensor) – Weight matrix.
  • bias (1D Tensor) – Bias parameter.
  • units (int, required) – Number of hidden units of the dense transformation.
  • use_bias (boolean, optional, default=1) – Whether to use bias parameter
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.relu(*args, **kwargs)

Computes rectified linear.

\[max(input, 0)\]

Defined in /workspace/nnvm/src/top/nn/nn.cc:L128

Parameters:data (Tensor) – The input tensor.
Returns:result – The result Tensor.
Return type:Tensor
nnvm.symbol.tanh(*args, **kwargs)

Computes hyperbolic tangent.

\[Y = sinh(X) / cosh(X)\]

Defined in /workspace/nnvm/src/top/tensor/elemwise.cc:L119

Parameters:data (Tensor) – The input tensor.
Returns:result – The result Tensor.
Return type:Tensor
nnvm.symbol.sigmoid(*args, **kwargs)

Computes sigmoid.

\[Y = 1 / (1 + exp(-X))\]

Defined in /workspace/nnvm/src/top/tensor/elemwise.cc:L89

Parameters:data (Tensor) – The input tensor.
Returns:result – The result Tensor.
Return type:Tensor
nnvm.symbol.exp(*args, **kwargs)

Returns the exp input array, computed element-wise.

\[exp(x)\]

Defined in /workspace/nnvm/src/top/tensor/elemwise.cc:L149

Parameters:data (Tensor) – The input tensor.
Returns:result – The result Tensor.
Return type:Tensor
nnvm.symbol.log(*args, **kwargs)

Returns the log input array, computed element-wise.

\[log(x)\]

Defined in /workspace/nnvm/src/top/tensor/elemwise.cc:L175

Parameters:data (Tensor) – The input tensor.
Returns:result – The result Tensor.
Return type:Tensor
nnvm.symbol.sqrt(*args, **kwargs)

Returns the sqrt input array, computed element-wise.

\[\sqrt(x)\]

Defined in /workspace/nnvm/src/top/tensor/elemwise.cc:L201

Parameters:data (Tensor) – The input tensor.
Returns:result – The result Tensor.
Return type:Tensor
nnvm.symbol.elemwise_add(*args, **kwargs)

Element-wise add

Parameters:
  • lhs (Tensor) – first input
  • rhs (Tensor) – second input
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.elemwise_sub(*args, **kwargs)

Element-wise substraction

Defined in /workspace/nnvm/src/top/tensor/elemwise.cc:L250

Parameters:
  • lhs (Tensor) – first input
  • rhs (Tensor) – second input
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.elemwise_mul(*args, **kwargs)

Element-wise multiplication

Defined in /workspace/nnvm/src/top/tensor/elemwise.cc:L273

Parameters:
  • lhs (Tensor) – first input
  • rhs (Tensor) – second input
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.elemwise_div(*args, **kwargs)

Element-wise multiplication

Defined in /workspace/nnvm/src/top/tensor/elemwise.cc:L298

Parameters:
  • lhs (Tensor) – first input
  • rhs (Tensor) – second input
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.elemwise_sum(*args, **kwargs)

Adds all input arguments element-wise.

Defined in /workspace/nnvm/src/top/tensor/elemwise.cc:L686

Parameters:args (Symbol[]) – Positional input arguments
Returns:result – The result Tensor.
Return type:Tensor
nnvm.symbol.flatten(*args, **kwargs)

Flattens the input into a 2-D array.

For an input array with shape (d1, d2, ..., dk), flatten operation reshapes the input array into an output array of shape (d1, d2*...*dk).

Example:

x = [[
    [1,2,3],
    [4,5,6],
    [7,8,9]
],
[   [1,2,3],
    [4,5,6],
    [7,8,9]
]],

flatten(x) = [[ 1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.,  9.],
   [ 1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.,  9.]]

Defined in /workspace/nnvm/src/top/tensor/transform.cc:L62

Parameters:data (Tensor) – Input data.
Returns:result – The result Tensor.
Return type:Tensor
nnvm.symbol.concatenate(*args, **kwargs)

Joins input arrays along a given axis.

The dimensions of the input arrays should be the same except the axis along which they will be concatenated. The dimension of the output array along the concatenated axis will be equal to the sum of the corresponding dimensions of the input arrays.

Example:

x = [[1,1],[2,2]]
y = [[3,3],[4,4],[5,5]]
z = [[6,6], [7,7],[8,8]]

concatenate(x,y,z,dim=0) = [[ 1.,  1.],
                            [ 2.,  2.],
                            [ 3.,  3.],
                            [ 4.,  4.],
                            [ 5.,  5.],
                            [ 6.,  6.],
                            [ 7.,  7.],
                            [ 8.,  8.]]

Note that you cannot concat x,y,z along dimension 1 since dimension
0 is not the same for all the input arrays.

concatenate(y,z,dim=1) = [[ 3.,  3.,  6.,  6.],
                          [ 4.,  4.,  7.,  7.],
                          [ 5.,  5.,  8.,  8.]]

Defined in /workspace/nnvm/src/top/tensor/transform.cc:L170

Parameters:
  • data (Tensor-or-Tensor[]) – List of arrays to concatenate
  • axis (int, optional, default='1') – the axis to be concated.
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.expand_dims(*args, **kwargs)

Inserts a new axis of size 1 into the array shape

For example, given x with shape (2,3,4), then expand_dims(x, axis=1, num_newaxis=5) will return a new array with shape (2,1,1,1,1,1,3,4).

Defined in /workspace/nnvm/src/top/tensor/transform.cc:L223

Parameters:
  • data (Tensor) – Input tensor
  • axis (int, required) – the axis to be expanded.
  • num_newaxis (int, optional, default='1') – Number of new axis to be inserted.
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.squeeze(*args, **kwargs)

Squeeze axises in the array.

Examples:

x = [[[0], [1], [2]]]
x.shape = (1, 3, 1)

squeeze(x) = [0, 1, 2]

squeeze(x, 0) = [[0], [1], [2]]

squeeze(x, (0, 2)) = [0, 1, 2]

Defined in /workspace/nnvm/src/top/tensor/transform.cc:L687

Parameters:
  • data (Tensor) – Source input
  • axis (, optional, default=[]) – The axis to squeeze in the input tensor.
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.split(*args, **kwargs)

Splits an array along a particular axis into multiple sub-arrays.

Note that indices_or_sections should evenly divide the length of the axis along which to split the array.

Defined in /workspace/nnvm/src/top/tensor/transform.cc:L365

Parameters:
  • data (Tensor) – Array to be splitted
  • indices_or_sections (tuple of <int>, required) – Number of outputs to be splitted
  • axis (int, optional, default='1') – the axis to be splitted.
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.dropout(*args, **kwargs)

Applies dropout operation to input array.

  • During training, each element of the input is set to zero with probability p. The whole array is rescaled by \(1/(1-p)\) to keep the expected sum of the input unchanged.

Defined in /workspace/nnvm/src/top/nn/nn.cc:L161

Parameters:
  • data (Tensor) – Input to which dropout will be applied
  • rate (float, optional, default=0.5) – Fraction of the input that gets dropped out during training time.
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.batch_norm(*args, **kwargs)

Batch normalization layer (Ioffe and Szegedy, 2014). Normalizes the input at each batch, i.e. applies a transformation that maintains the mean activation close to 0 and the activation standard deviation close to 1.

\[\begin{split}data\_mean[i] = mean(data[:,i,:,...]) \\ data\_var[i] = var(data[:,i,:,...])\end{split}\]

Then compute the normalized output, which has the same shape as input, as following:

\[out[:,i,:,...] = \frac{data[:,i,:,...] - data\_mean[i]}{\sqrt{data\_var[i]+\epsilon}} * gamma[i] + beta[i]\]

Both mean and var returns a scalar by treating the input as a vector.

Assume the input has size k on axis 1, then both gamma and beta have shape (k,).

Besides the inputs and the outputs, this operator accepts two auxiliary states, moving_mean and moving_var, which are k-length vectors. They are global statistics for the whole dataset, which are updated by:

moving_mean = moving_mean * momentum + data_mean * (1 - momentum)
moving_var = moving_var * momentum + data_var * (1 - momentum)

The parameter axis specifies which axis of the input shape denotes the ‘channel’ (separately normalized groups). The default is 1. Specifying -1 sets the channel axis to be the last item in the input shape.

Note

This operator can be optimized away for inference.

Defined in /workspace/nnvm/src/top/nn/nn.cc:L301

Parameters:
  • data (Tensor) – Input to which dropout will be applied
  • gamma (Tensor) – The gamma scale factor
  • beta (Tensor) – The beta offset factor
  • moving_mean (Tensor) – running mean of input
  • moving_var (Tensor) – running variance of input
  • axis (int, optional, default='1') – Specify which shape axis the channel is specified.
  • epsilon (double, optional, default=1e-05) – Small float added to variance to avoid dividing by zero.
  • center (boolean, optional, default=1) – If True, add offset of beta to normalized tensor.If False, beta is ignored.
  • scale (boolean, optional, default=1) – If True, multiply by gamma. If False, gamma is not used.When the next layer is piecewise linear (also e.g. nn.relu),this can be disabled since the scalingwill be done by the next layer.
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.softmax(*args, **kwargs)

Computes softmax.

\[\text{softmax}(x)_i = \frac{exp(x_i)}{\sum_j exp(x_j)}\]

Note

This operator can be optimized away for inference.

Defined in /workspace/nnvm/src/top/nn/nn.cc:L339

Parameters:
  • data (Tensor) – Input data.
  • axis (int, optional, default='-1') – The axis to sum over when computing softmax.
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.log_softmax(*args, **kwargs)

Computes log softmax.

\[\text{log_softmax}(x)_i = \log \frac{exp(x_i)}{\sum_j exp(x_j)}\]

Note

This operator can be optimized away for inference.

Defined in /workspace/nnvm/src/top/nn/nn.cc:L398

Parameters:
  • data (Tensor) – Input data.
  • axis (int, optional, default='-1') – The axis to sum over when computing softmax.
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.pad(*args, **kwargs)

Pad for n-D tensor.

Defined in /workspace/nnvm/src/top/nn/nn.cc:L595

Parameters:
  • data (n-D Tensor) – Input data.
  • pad_value (float, optional, default=0) – The value to be padded.
  • pad_width (tuple of <tuple of <int>>, required) – Number of values padded to the edges of each axis, in the format of ((before_1, after_1), … (before_N, after_N))
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.block_grad(*args, **kwargs)

Blocks gradient computation for input.

Defined in /workspace/nnvm/src/top/tensor/elemwise.cc:L702

Parameters:data (Tensor) – The input tensor.
Returns:result – The result Tensor.
Return type:Tensor
nnvm.symbol.conv2d(*args, **kwargs)

2D convolution layer (e.g. spatial convolution over images).

This layer creates a convolution kernel that is convolved with the layer input to produce a tensor of outputs. If use_bias is True, a bias vector is created and added to the outputs.

  • data: This depends on the layout parameter. Input is 4D array of shape
    (batch_size, in_channels, height, width) if layout is NCHW.
  • weight: (channels, in_channels, kernel_size[0], kernel_size[1])
  • bias: (channels,)
  • out: This depends on the layout parameter. Output is 4D array of shape
    (batch_size, channels, out_height, out_width) if layout is NCHW.

Defined in /workspace/nnvm/src/top/nn/convolution.cc:L183

Parameters:
  • data (4D Tensor) – Input data.
  • weight (4D Tensor) – Weight matrix.
  • bias (1D Tensor) – Bias parameter.
  • channels (int, required) – The dimensionality of the output spacei.e. the number of output channels in the convolution.
  • kernel_size (, required) – Specifies the dimensions of the convolution window.
  • strides (, optional, default=[1,1]) – Specifies the strides of the convolution.
  • padding (, optional, default=[0,0]) – If padding is non-zero, then the input is implicitly zero-paddedon both sides for padding number of points
  • dilation (, optional, default=[1,1]) – Specifies the dilation rate to use for dilated convolution.
  • groups (int, optional, default='1') – Controls the connections between inputs and outputs.At groups=1, all inputs are convolved to all outputs.At groups=2, the operation becomes equivalent to having two convolutionlayers side by side, each seeing half the input channels, and producinghalf the output channels, and both subsequently concatenated.
  • layout (string, optional, default='NCHW') – Dimension ordering of input data. Can be ‘NCHW’, ‘NHWC’, etc.’N’, ‘C’, ‘H’, ‘W’ stands for batch, channel, height, and widthdimensions respectively. Convolution is applied on the ‘H’ and’W’ dimensions.
  • out_layout (string, optional, default='__undef__') – Dimension ordering of output. Can be ‘NCHW’, ‘NHWC’, etc.’N’, ‘C’, ‘H’, ‘W’ stands for batch, channel, height, and widthdimensions respectively. Default to be same as input layout.
  • kernel_layout (string, optional, default='OIHW') – Dimension ordering of weight. Can be ‘OIHW’, ‘OIHW16o16i’, etc.’O’, ‘I’, ‘H’, ‘W’ stands for num_filter, input_channel, height, and widthdimensions respectively.
  • use_bias (boolean, optional, default=1) – Whether the layer uses a bias vector.
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.conv2d_transpose(*args, **kwargs)

Transposed 2D convolution layer (sometimes called Deconvolution).

The need for transposed convolutions generally arises from the desire to use a transformation going in the opposite direction of a normal convolution, i.e., from something that has the shape of the output of some convolution to something that has the shape of its input while maintaining a connectivity pattern that is compatible with said convolution.

  • data: This depends on the layout parameter. Input is 4D array of shape

    (batch_size, in_channels, height, width) if layout is NCHW.

  • weight: (in_channels, channels, kernel_size[0], kernel_size[1])

  • bias: (channels,)

  • out: This depends on the layout parameter. Output is 4D array of shape

    (batch_size, channels, out_height, out_width) if layout is NCHW.

    out_height and out_width are calculated as::

    out_height = (height-1)*strides[0]-2*padding[0]+kernel_size[0]+output_padding[0] out_width = (width-1)*strides[1]-2*padding[1]+kernel_size[1]+output_padding[1]

Defined in /workspace/nnvm/src/top/nn/convolution.cc:L357

Parameters:
  • data (4D Tensor) – Input data.
  • weight (4D Tensor) – Weight matrix.
  • bias (1D Tensor) – Bias parameter.
  • channels (int, required) – The dimensionality of the output spacei.e. the number of output channels in the convolution.
  • kernel_size (, required) – Specifies the dimensions of the convolution window.
  • strides (, optional, default=[1,1]) – Specifies the strides of the convolution.
  • output_padding (, optional, default=[0,0]) – Zero-padding added to one side of the output.
  • padding (, optional, default=[0,0]) – If padding is non-zero, then the input is implicitly zero-paddedon both sides for padding number of points
  • dilation (, optional, default=[1,1]) – Specifies the dilation rate to use for dilated convolution.
  • groups (int, optional, default='1') – Controls the connections between inputs and outputs.At groups=1, all inputs are convolved to all outputs.At groups=2, the operation becomes equivalent to having two convolutionlayers side by side, each seeing half the input channels, and producinghalf the output channels, and both subsequently concatenated.
  • layout (string, optional, default='NCHW') – Dimension ordering of data. Can be ‘NCHW’, ‘NHWC’, etc.’N’, ‘C’, ‘H’, ‘W’ stands for batch, channel, height, and widthdimensions respectively. Convolution is applied on the ‘H’ and’W’ dimensions.
  • kernel_layout (string, optional, default='OIHW') – Dimension ordering of data and weight. Can be ‘OIHW’, ‘OIHW16o16i’, etc.’O’, ‘I’, ‘H’, ‘W’ stands for num_filter, input_channel, height, and widthdimensions respectively.
  • use_bias (boolean, optional, default=1) – Whether the layer uses a bias vector.
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.max_pool2d(*args, **kwargs)

Max pooling operation for one dimensional data.

  • data: This depends on the layout parameter. Input is 4D array of shape

    (batch_size, channels, height, width) if layout is NCHW.

  • out: This depends on the layout parameter. Output is 4D array of shape

    (batch_size, channels, out_height, out_width) if layout is NCHW. out_height and out_width are calculated as:

    out_height = floor((height+2*padding[0]-pool_size[0])/strides[0])+1
    out_width = floor((width+2*padding[1]-pool_size[1])/strides[1])+1
    

    When ceil_mode is True, ceil will be used instead of floor in this equation.

Defined in /workspace/nnvm/src/top/nn/pooling.cc:L117

Parameters:
  • data (4D Tensor) – Input data.
  • pool_size (, required) – Size of the pooling windows..
  • strides (, optional, default=[1,1]) – Specifies the strides of the convolution.
  • padding (, optional, default=[0,0]) – If padding is non-zero, then the input is implicitly zero-paddedon both sides for padding number of points
  • layout (string, optional, default='NCHW') – Dimension ordering of data and weight. Can be ‘NCHW’, ‘NHWC’, etc.’N’, ‘C’, ‘H’, ‘W’ stands for batch, channel, height, and widthdimensions respectively. Convolution is applied on the ‘H’ and’W’ dimensions.
  • ceil_mode (boolean, optional, default=0) – When true, will use ceil instead of floor to compute the output shape.
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.avg_pool2d(*args, **kwargs)

Average pooling operation for one dimensional data.

  • data: This depends on the layout parameter. Input is 4D array of shape

    (batch_size, channels, height, width) if layout is NCHW.

  • out: This depends on the layout parameter. Output is 4D array of shape

    (batch_size, channels, out_height, out_width) if layout is NCHW. out_height and out_width are calculated as:

    out_height = floor((height+2*padding[0]-pool_size[0])/strides[0])+1
    out_width = floor((width+2*padding[1]-pool_size[1])/strides[1])+1
    

    When ceil_mode is True, ceil will be used instead of floor in this equation.

Defined in /workspace/nnvm/src/top/nn/pooling.cc:L191

Parameters:
  • data (4D Tensor) – Input data.
  • pool_size (, required) – Size of the pooling windows..
  • strides (, optional, default=[1,1]) – Specifies the strides of the convolution.
  • padding (, optional, default=[0,0]) – If padding is non-zero, then the input is implicitly zero-paddedon both sides for padding number of points
  • layout (string, optional, default='NCHW') – Dimension ordering of data and weight. Can be ‘NCHW’, ‘NHWC’, etc.’N’, ‘C’, ‘H’, ‘W’ stands for batch, channel, height, and widthdimensions respectively. Convolution is applied on the ‘H’ and’W’ dimensions.
  • ceil_mode (boolean, optional, default=0) – When true, will use ceil instead of floor to compute the output shape.
  • count_include_pad (boolean, optional, default=0) – When true, will include padding to compute the average
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.global_max_pool2d(*args, **kwargs)

Global max pooling operation for 2D data.

  • data: This depends on the layout parameter. Input is 4D array of shape
    (batch_size, channels, height, width) if layout is NCHW.
  • out: This depends on the layout parameter. Output is 4D array of shape
    (batch_size, channels, 1, 1) if layout is NCHW.

Defined in /workspace/nnvm/src/top/nn/pooling.cc:L298

Parameters:
  • data (4D Tensor) – Input data.
  • layout (string, optional, default='NCHW') – Dimension ordering of data and weight. Can be ‘NCHW’, ‘NHWC’, etc.’N’, ‘C’, ‘H’, ‘W’ stands for batch, channel, height, and widthdimensions respectively. Convolution is applied on the ‘H’ and’W’ dimensions.
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.global_avg_pool2d(*args, **kwargs)

Global average pooling operation for 2D data.

  • data: This depends on the layout parameter. Input is 4D array of shape
    (batch_size, channels, height, width) if layout is NCHW.
  • out: This depends on the layout parameter. Output is 4D array of shape
    (batch_size, channels, 1, 1) if layout is NCHW.

Defined in /workspace/nnvm/src/top/nn/pooling.cc:L339

Parameters:
  • data (4D Tensor) – Input data.
  • layout (string, optional, default='NCHW') – Dimension ordering of data and weight. Can be ‘NCHW’, ‘NHWC’, etc.’N’, ‘C’, ‘H’, ‘W’ stands for batch, channel, height, and widthdimensions respectively. Convolution is applied on the ‘H’ and’W’ dimensions.
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.reshape(*args, **kwargs)

Reshapes the input array.

Given an array and a shape, this function returns a copy of the array in the new shape. The shape is a tuple of integers such as (2,3,4). The size of the new shape should be same as the size of the input array.

Example:

reshape([1,2,3,4], shape=(2,2)) = [[1,2], [3,4]]

To give user more convenience in without doing manual shape inference, some dimensions of the shape can take special values from the set {0, -1, -2, -3, -4}. The significance of each is explained below:

  • 0 copy this dimension from the input to the output shape.

    Example:

    - input shape = (2,3,4), shape = (4,0,2), output shape = (4,3,2)
    - input shape = (2,3,4), shape = (2,0,0), output shape = (2,3,4)
    
  • -1 infers the dimension of the output shape by using the remainder of the input dimensions keeping the size of the new array same as that of the input array. At most one dimension of shape can be -1.

    Example:

    - input shape = (2,3,4), shape = (6,1,-1), output shape = (6,1,4)
    - input shape = (2,3,4), shape = (3,-1,8), output shape = (3,1,8)
    - input shape = (2,3,4), shape=(-1,), output shape = (24,)
    
  • -2 copy all/remainder of the input dimensions to the output shape.

    Example:

    - input shape = (2,3,4), shape = (-2,), output shape = (2,3,4)
    - input shape = (2,3,4), shape = (2,-2), output shape = (2,3,4)
    - input shape = (2,3,4), shape = (-2,1,1), output shape = (2,3,4,1,1)
    
  • -3 use the product of two consecutive dimensions of the input shape as the output dimension.

    Example:

    - input shape = (2,3,4), shape = (-3,4), output shape = (6,4)
    - input shape = (2,3,4,5), shape = (-3,-3), output shape = (6,20)
    - input shape = (2,3,4), shape = (0,-3), output shape = (2,12)
    - input shape = (2,3,4), shape = (-3,-2), output shape = (6,4)
    
  • -4 split one dimension of the input into two dimensions passed subsequent to -4 in shape (can contain -1).

    Example:

    - input shape = (2,3,4), shape = (-4,1,2,-2), output shape =(1,2,3,4)
    - input shape = (2,3,4), shape = (2,-4,-1,3,-2), output shape = (2,1,3,4)
    

Defined in /workspace/nnvm/src/top/tensor/transform.cc:L560

Parameters:
  • data (Tensor) – Input data.
  • shape (tuple of <>, required) –
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.copy(*args, **kwargs)

Copy tensor to another one.

Defined in /workspace/nnvm/src/top/tensor/elemwise.cc:L352

Parameters:data (Tensor) – The input tensor.
Returns:result – The result Tensor.
Return type:Tensor
nnvm.symbol.negative(*args, **kwargs)

Elemenwise numeric negative

Defined in /workspace/nnvm/src/top/tensor/elemwise.cc:L330

Parameters:data (Tensor) – The input tensor.
Returns:result – The result Tensor.
Return type:Tensor
nnvm.symbol.floor(*args, **kwargs)

Take floor input array, computed element-wise.

Defined in /workspace/nnvm/src/top/tensor/elemwise.cc:L37

Parameters:data (Tensor) – The input tensor.
Returns:result – The result Tensor.
Return type:Tensor
nnvm.symbol.ceil(*args, **kwargs)

Take ceil input array, computed element-wise.

Defined in /workspace/nnvm/src/top/tensor/elemwise.cc:L49

Parameters:data (Tensor) – The input tensor.
Returns:result – The result Tensor.
Return type:Tensor
nnvm.symbol.round(*args, **kwargs)

Round elements of the input to nearest integer.

Defined in /workspace/nnvm/src/top/tensor/elemwise.cc:L73

Parameters:data (Tensor) – The input tensor.
Returns:result – The result Tensor.
Return type:Tensor
nnvm.symbol.trunc(*args, **kwargs)

Take truncated value of the input, element-wise.

Defined in /workspace/nnvm/src/top/tensor/elemwise.cc:L61

Parameters:data (Tensor) – The input tensor.
Returns:result – The result Tensor.
Return type:Tensor
nnvm.symbol.leaky_relu(*args, **kwargs)

Leaky version of a Rectified Linear Unit.

y = x > 0 ? x : alpha * x

Defined in /workspace/nnvm/src/top/nn/nn.cc:L458

Parameters:
  • data (Tensor) – Input data.
  • alpha (double, optional, default=0.25) – slope coefficient for the negative half axis.
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.__add_scalar__(*args, **kwargs)

Tensor add scalar

Defined in /workspace/nnvm/src/top/tensor/elemwise.cc:L461

Parameters:
  • data (Tensor) – The input tensor.
  • scalar (double, required) –
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.__sub_scalar__(*args, **kwargs)

Tensor substract scalar

Defined in /workspace/nnvm/src/top/tensor/elemwise.cc:L480

Parameters:
  • data (Tensor) – The input tensor.
  • scalar (double, required) –
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.__rsub_scalar__(*args, **kwargs)

scalar substract Tensor

Defined in /workspace/nnvm/src/top/tensor/elemwise.cc:L498

Parameters:
  • data (Tensor) – The input tensor.
  • scalar (double, required) –
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.__mul_scalar__(*args, **kwargs)

Tensor multiplies scalar

Defined in /workspace/nnvm/src/top/tensor/elemwise.cc:L551

Parameters:
  • data (Tensor) – The input tensor.
  • scalar (double, required) –
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.__div_scalar__(*args, **kwargs)

Tensor divides scalar

Defined in /workspace/nnvm/src/top/tensor/elemwise.cc:L574

Parameters:
  • data (Tensor) – The input tensor.
  • scalar (double, required) –
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.__rdiv_scalar__(*args, **kwargs)

scalar divides Tensor

Defined in /workspace/nnvm/src/top/tensor/elemwise.cc:L597

Parameters:
  • data (Tensor) – The input tensor.
  • scalar (double, required) –
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.__pow_scalar__(*args, **kwargs)

Tensor power scalar

Defined in /workspace/nnvm/src/top/tensor/elemwise.cc:L627

Parameters:
  • data (Tensor) – The input tensor.
  • scalar (double, required) –
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.__rpow_scalar__(*args, **kwargs)

scalar power Tensor

Defined in /workspace/nnvm/src/top/tensor/elemwise.cc:L657

Parameters:
  • data (Tensor) – The input tensor.
  • scalar (double, required) –
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.__lshift_scalar__(*args, **kwargs)

Tensor left shift by scalar

Defined in /workspace/nnvm/src/top/tensor/elemwise.cc:L519

Parameters:
  • data (Tensor) – The input tensor.
  • scalar (double, required) –
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.__rshift_scalar__(*args, **kwargs)

Tensor right shift by scalar

Defined in /workspace/nnvm/src/top/tensor/elemwise.cc:L535

Parameters:
  • data (Tensor) – The input tensor.
  • scalar (double, required) –
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.transpose(*args, **kwargs)

Permutes the dimensions of an array.

Examples:

x = [[ 1, 2],
     [ 3, 4]]

transpose(x) = [[ 1.,  3.],
                [ 2.,  4.]]

x = [[[ 1.,  2.],
      [ 3.,  4.]],

     [[ 5.,  6.],
      [ 7.,  8.]]]

transpose(x) = [[[ 1.,  5.],
                 [ 3.,  7.]],

                [[ 2.,  6.],
                 [ 4.,  8.]]]

transpose(x, axes=(1,0,2)) = [[[ 1.,  2.],
                               [ 5.,  6.]],

                              [[ 3.,  4.],
                               [ 7.,  8.]]]

Defined in /workspace/nnvm/src/top/tensor/transform.cc:L804

Parameters:
  • data (Tensor) – Source input
  • axes (, optional, default=[]) – Target axis order. By default the axes will be inverted.
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.broadcast_to(*args, **kwargs)

Broadcasts the input array to a new shape.

Broadcasting is a mechanism that allows NDArrays to perform arithmetic operations with arrays of different shapes efficiently without creating multiple copies of arrays. Also see, Broadcasting for more explanation.

Broadcasting is allowed on axes with size 1, such as from (2,1,3,1) to (2,8,3,9). Elements will be duplicated on the broadcasted axes.

For example:

broadcast_to([[1,2,3]], shape=(2,3)) = [[ 1.,  2.,  3.],
                                        [ 1.,  2.,  3.]])

The dimension which you do not want to change can also be kept as 0 which means copy the original value. So with shape=(2,0), we will obtain the same result as in the above example.

Defined in /workspace/nnvm/src/top/tensor/broadcast.cc:L71

Parameters:
  • data (Tensor) – Input data.
  • shape (, optional, default=[]) – The shape of the desired array. We can set the dim to zero if it’s same as the original. E.g A = broadcast_to(B, shape=(10, 0, 0))
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.sum(*args, **kwargs)

Computes the sum of array elements over given axes.

Example:

data = [[[1,2],[2,3],[1,3]],
        [[1,4],[4,3],[5,2]],
        [[7,1],[7,2],[7,3]]]

sum(data, axis=1)
[[  4.   8.]
 [ 10.   9.]
 [ 21.   6.]]

sum(data, axis=[1,2])
[ 12.  19.  27.]

Defined in /workspace/nnvm/src/top/tensor/reduce.cc:L136

Parameters:
  • data (Tensor) – The input
  • axis (, optional, default=[]) –

    The axis or axes along which to perform the reduction.

    The default, axis=(), will compute over all elements into a scalar array with shape (1,).

    If axis is int, a reduction is performed on a particular axis.

    If axis is a tuple of ints, a reduction is performed on all the axes specified in the tuple.

    If exclude is true, reduction will be performed on the axes that are NOT in axis instead.

  • keepdims (boolean, optional, default=0) – If this is set to True, the reduced axes are left in the result as dimension with size one.
  • exclude (boolean, optional, default=0) – Whether to perform reduction on axis that are NOT in axis instead.
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.min(*args, **kwargs)

Computes the min of array elements over given axes.

Defined in /workspace/nnvm/src/top/tensor/reduce.cc:L207

Parameters:
  • data (Tensor) – The input
  • axis (, optional, default=[]) –

    The axis or axes along which to perform the reduction.

    The default, axis=(), will compute over all elements into a scalar array with shape (1,).

    If axis is int, a reduction is performed on a particular axis.

    If axis is a tuple of ints, a reduction is performed on all the axes specified in the tuple.

    If exclude is true, reduction will be performed on the axes that are NOT in axis instead.

  • keepdims (boolean, optional, default=0) – If this is set to True, the reduced axes are left in the result as dimension with size one.
  • exclude (boolean, optional, default=0) – Whether to perform reduction on axis that are NOT in axis instead.
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.max(*args, **kwargs)

Computes the max of array elements over given axes.

Defined in /workspace/nnvm/src/top/tensor/reduce.cc:L175

Parameters:
  • data (Tensor) – The input
  • axis (, optional, default=[]) –

    The axis or axes along which to perform the reduction.

    The default, axis=(), will compute over all elements into a scalar array with shape (1,).

    If axis is int, a reduction is performed on a particular axis.

    If axis is a tuple of ints, a reduction is performed on all the axes specified in the tuple.

    If exclude is true, reduction will be performed on the axes that are NOT in axis instead.

  • keepdims (boolean, optional, default=0) – If this is set to True, the reduced axes are left in the result as dimension with size one.
  • exclude (boolean, optional, default=0) – Whether to perform reduction on axis that are NOT in axis instead.
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.broadcast_add(*args, **kwargs)

Returns element-wise sum of the input arrays with broadcasting.

Example:

x = [[ 1.,  1.,  1.],
     [ 1.,  1.,  1.]]

y = [[ 0.],
     [ 1.]]

broadcast_add(x, y) = [[ 1.,  1.,  1.],
                       [ 2.,  2.,  2.]]

Defined in /workspace/nnvm/src/top/tensor/broadcast.cc:L241

Parameters:
  • lhs (Tensor) – first input
  • rhs (Tensor) – second input
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.broadcast_sub(*args, **kwargs)

Returns element-wise difference of the input arrays with broadcasting.

Example:

x = [[ 1.,  1.,  1.],
     [ 1.,  1.,  1.]]

y = [[ 0.],
     [ 1.]]

broadcast_sub(x, y) = [[ 1.,  1.,  1.],
                       [ 0.,  0.,  0.]]

Defined in /workspace/nnvm/src/top/tensor/broadcast.cc:L259

Parameters:
  • lhs (Tensor) – first input
  • rhs (Tensor) – second input
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.broadcast_mul(*args, **kwargs)

Returns element-wise product of the input arrays with broadcasting.

Example:

x = [[ 1.,  1.,  1.],
     [ 1.,  1.,  1.]]

y = [[ 0.],
     [ 1.]]

broadcast_mul(x, y) = [[ 0.,  0.,  0.],
                       [ 1.,  1.,  1.]]

Defined in /workspace/nnvm/src/top/tensor/broadcast.cc:L276

Parameters:
  • lhs (Tensor) – first input
  • rhs (Tensor) – second input
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.broadcast_div(*args, **kwargs)

Returns element-wise division of the input arrays with broadcasting.

Example:

x = [[ 6.,  6.,  6.],
     [ 6.,  6.,  6.]]

y = [[ 2.],
     [ 3.]]

broadcast_div(x, y) = [[ 3.,  3.,  3.],
                       [ 2.,  2.,  2.]]

Defined in /workspace/nnvm/src/top/tensor/broadcast.cc:L294

Parameters:
  • lhs (Tensor) – first input
  • rhs (Tensor) – second input
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.clip(*args, **kwargs)

Clips (limits) the values in an array. Given an interval, values outside the interval are clipped to the interval edges. Clipping x between a_min and a_x would be:

clip(x, a_min, a_max) = max(min(x, a_max), a_min))
Example::
x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] clip(x,1,8) = [ 1., 1., 2., 3., 4., 5., 6., 7., 8., 8.]

Defined in /workspace/nnvm/src/top/tensor/elemwise.cc:L773

Parameters:
  • data (NDArray-or-Symbol) – Input array.
  • a_min (double, required) – Minimum value such that value smaller then this will be clipped.
  • a_max (double, required) – Maximum value such that value larger then this will be clipped.
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.greater(*args, **kwargs)

Greater function that returns a mask tensor with 1.0 if (left > right), otherwise 0.0 element-wise.

Defined in /workspace/nnvm/src/top/tensor/elemwise.cc:L717

Parameters:
  • lhs (Tensor) – First input
  • rhs (Tensor) – Second input
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.less(*args, **kwargs)

Less function that returns a mask tensor with 1.0 if (left < right), otherwise 0.0 element-wise.

Defined in /workspace/nnvm/src/top/tensor/elemwise.cc:L729

Parameters:
  • lhs (Tensor) – First input
  • rhs (Tensor) – Second input
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.expand_like(*args, **kwargs)

Expand an input array with the shape of second array. This operation can always be composed of unsqueezing and expanding dims. Examples:

input = [ 12.  19.  27.]
input.shape = (3,)
new_shape_array = [[[1,2],[2,3],[1,3]],
                   [[1,4],[4,3],[5,2]],
                   [[7,1],[7,2],[7,3]]]
new_shape_array.shape = (3, 3, 2)
expand_like(input, [1,2], new_shape_array) =
                  [[[12,12],[12,12],[12,12]],
                   [[19,19],[19,19],[19,19]],
                   [[27,27],[27,27],[27,27]]]

Defined in /workspace/nnvm/src/top/tensor/transform.cc:L265

Parameters:
  • input (Tensor) – Source input
  • shape_like (Tensor) – Input with new shape
  • axis (, optional, default=[]) –

    The axis or axes along which to perform the indicator rule.

    The default, axis=(), will compute over all elements into a scalar array with shape (1,).

    If axis is int, rule is applied on a particular axis.

    If axis is a tuple of ints, rule is applied on all the axes specified in the tuple.

    If exclude is true, rule will be applied on the axes that are NOT in axis instead.

  • exclude (boolean, optional, default=0) – Whether to apply rule on axis that are NOT in axis instead.
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.reshape_like(*args, **kwargs)

Reshapes the input array by the size of another array. For an input array with shape (d1, d2, ..., dk), reshape_like operation reshapes the input array into an output array with the same shape as the second input array. .. note:

Sizes for both array should be compatible.

Defined in /workspace/nnvm/src/top/tensor/transform.cc:L592

Parameters:
  • data (Tensor) – Input data.
  • shape_like (Tensor) – Input data.
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.full(*args, **kwargs)

Fill array with scalar value

Defined in /workspace/nnvm/src/top/tensor/elemwise.cc:L377

Parameters:
  • shape (, optional, default=[]) –
  • dtype ({'float16', 'float32', 'float64', 'int16', 'int32', 'int64', 'int8', 'uint16', 'uint32', 'uint64', 'uint8'},optional, default='float32') – Target data type.
  • fill_value (double, required) – Scalar value to fill
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.full_like(*args, **kwargs)

Return an scalar value array with the same shape and type as the input array

Defined in /workspace/nnvm/src/top/tensor/elemwise.cc:L418

Parameters:
  • data (Tensor) – The input tensor.
  • fill_value (double, required) – Scalar value to be filled
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.ones(*args, **kwargs)

Fill target with ones

Defined in /workspace/nnvm/src/top/tensor/elemwise.cc:L403

Parameters:
  • shape (, optional, default=[]) –
  • dtype ({'float16', 'float32', 'float64', 'int16', 'int32', 'int64', 'int8', 'uint16', 'uint32', 'uint64', 'uint8'},optional, default='float32') – Target data type.
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.ones_like(*args, **kwargs)

Return an array of ones with the same shape and type as the input array.

Parameters:data (Tensor) – The input tensor.
Returns:result – The result Tensor.
Return type:Tensor
nnvm.symbol.zeros(*args, **kwargs)

Fill target with zeros

Defined in /workspace/nnvm/src/top/tensor/elemwise.cc:L390

Parameters:
  • shape (, optional, default=[]) –
  • dtype ({'float16', 'float32', 'float64', 'int16', 'int32', 'int64', 'int8', 'uint16', 'uint32', 'uint64', 'uint8'},optional, default='float32') – Target data type.
Returns:

result – The result Tensor.

Return type:

Tensor

nnvm.symbol.zeros_like(*args, **kwargs)

Return an array of zeros with the same shape and type as the input array.

Parameters:data (Tensor) – The input tensor.
Returns:result – The result Tensor.
Return type:Tensor