mindspore.mint
mindpsore.mint provides a large number of functional, nn, optimizer interfaces. The API usages and functions are consistent with the mainstream usage in the industry for easy reference. The mint interface is currently an experimental interface and performs better than ops in graph mode of O0 and PyNative mode. Currently, the graph sinking mode and CPU/GPU backend are not supported, and it will be gradually improved in the future.
The module import method is as follows:
from mindspore import mint
Tensor
Creation Operations
API Name |
Description |
Supported Platforms |
Warning |
Creates a sequence of numbers that begins at start and extends by increments of step up to but not including end. |
|
None |
|
Creates a tensor with ones on the diagonal and zeros in the rest. |
|
None |
|
Creates a tensor filled with value ones. |
|
None |
|
Creates a tensor filled with 1, with the same shape as input, and its data type is determined by the given dtype. |
|
None |
|
Creates a tensor filled with 0 with shape described by size and fills it with value 0 in type of dtype. |
|
None |
|
Creates a tensor filled with 0, with the same size as input. |
|
None |
Indexing, Slicing, Joining, Mutating Operations
API Name |
Description |
Supported Platforms |
Warning |
Connect input tensors along with the given dimension. |
|
None |
|
Gather data from a tensor by indices. |
|
On Ascend, the behavior is unpredictable in the following cases: the value of index is not in the range [-input.shape[dim], input.shape[dim]) in forward; the value of index is not in the range [0, input.shape[dim]) in backward. |
|
Generates a new Tensor that accesses the values of input along the specified dim dimension using the indices specified in index. |
|
None |
|
Permutes the dimensions of the input tensor according to input dims . |
|
None |
|
Add all elements in src to the index specified by index to input along dimension specified by dim. |
|
None |
|
Splits the Tensor into chunks along the given dim. |
|
None |
|
Returns a narrowed tensor from input tensor, and the dimension axis is input from start to start + length. |
|
None |
|
Return the positions of all non-zero values. |
|
None |
|
Creates a new tensor by replicating input dims times. |
|
None |
|
Stacks a list of tensors in specified dim. |
|
None |
|
Selects elements from input or other based on condition and returns a tensor. |
|
None |
Random Sampling
API Name |
Description |
Supported Platforms |
Warning |
Generates random numbers according to the standard Normal (or Gaussian) random number distribution. |
|
None |
|
Returns a new tensor that fills numbers from the uniform distribution over an interval \([0, 1)\) based on the given dtype and shape of the input tensor. |
|
None |
|
Returns a new tensor that fills numbers from the uniform distribution over an interval \([0, 1)\) based on the given shape and dtype. |
|
None |
Math Operations
Pointwise Operations
API Name |
Description |
Supported Platforms |
Warning |
Returns absolute value of a tensor element-wise. |
|
None |
|
Adds scaled other value to input Tensor. |
|
None |
|
Clamps tensor values between the specified minimum value and maximum value. |
|
None |
|
Returns arctangent of input/other element-wise. |
|
None |
|
Alias for |
|
None |
|
Rounds a tensor up to the closest integer element-wise. |
|
None |
|
Computes cosine of input element-wise. |
|
Using float64 may cause a problem of missing precision. |
|
Divides the first input tensor by the second input tensor in floating-point type element-wise. |
|
None |
|
Alias for |
|
None |
|
Computes the Gauss error function of input element-wise. |
|
None |
|
Returns the result of the inverse error function with input, which is defined in the range (-1, 1) as: |
|
None |
|
Returns exponential of a tensor element-wise. |
|
None |
|
Rounds a tensor down to the closest integer element-wise. |
|
None |
|
Returns the natural logarithm of a tensor element-wise. |
|
If the input value of operator Log is within the range (0, 0.01] or [0.95, 1.05], the output accuracy may be affacted. |
|
Computes the "logical AND" of two tensors element-wise. |
|
None |
|
Computes the "logical NOT" of a tensor element-wise. |
|
None |
|
Computes the "logical OR" of two tensors element-wise. |
|
None |
|
Multiplies two tensors element-wise. |
|
None |
|
Returns a tensor with negative values of the input tensor element-wise. |
|
None |
|
Alias for |
|
None |
|
Calculates the exponent power of each element in input. |
|
None |
|
Returns reciprocal of a tensor element-wise. |
|
None |
|
Computes reciprocal of square root of input tensor element-wise. |
|
None |
|
Computes Sigmoid of input element-wise. |
|
None |
|
Computes sine of the input element-wise. |
|
None |
|
Returns sqrt of a tensor element-wise. |
|
None |
|
Returns square of a tensor element-wise. |
|
None |
|
Subtracts scaled other value from input Tensor. |
|
None |
|
Computes hyperbolic tangent of input element-wise. |
|
None |
Reduction Operations
API Name |
Description |
Supported Platforms |
Warning |
Return the indices of the maximum values of a tensor across a dimension. |
|
None |
|
Reduces a dimension of input by the "logical AND" of all elements in the dimension, by default. |
|
None |
|
Reduces a dimension of input by the "logical OR" of all elements in the dimension, by default. |
|
None |
|
Calculates the maximum value along with the given dimension for the input tensor. |
|
None |
|
Reduces all dimension of a tensor by averaging all elements in the dimension, by default. |
|
None |
|
Calculates the minimum value along with the given dimension for the input tensor. |
|
None |
|
Reduces a dimension of a tensor by multiplying all elements in the dimension, by default. |
|
None |
|
Calculate sum of Tensor elements over a given dim. |
|
None |
|
Returns the unique elements of input tensor. |
|
None |
Comparison Operations
API Name |
Description |
Supported Platforms |
Warning |
Computes the equivalence between two tensors element-wise. |
|
None |
|
Compare the value of the input parameters \(input > other\) element-wise, and the output result is a bool value. |
|
None |
|
Given two Tensors, compares them element-wise to check if each element in the first Tensor is greater than or equal to the corresponding element in the second Tensor. |
|
None |
|
Compare the value of the input parameters \(input,other\) element-wise, and the output result is a bool value. |
|
None |
|
Returns a new Tensor with boolean elements representing if each element of input is “close” to the corresponding element of other. |
|
None |
|
Determine which elements are finite for each position. |
|
None |
|
Computes the boolean value of \(input <= other\) element-wise. |
|
None |
|
Computes the boolean value of \(input < other\) element-wise. |
|
None |
|
Computes the boolean value of \(input <= other\) element-wise. |
|
None |
|
Alias for |
|
None |
|
Computes the maximum of input tensors element-wise. |
|
None |
|
Computes the minimum of input tensors element-wise. |
|
None |
|
Computes the non-equivalence of two tensors element-wise. |
|
None |
|
Finds values and indices of the k largest or smallest entries along a given dimension. |
|
If sorted is set to False, due to different memory layout and traversal methods on different platforms, the display order of calculation results may be inconsistent when sorted is False. |
|
Sorts the elements of the input tensor along the given dimension in the specified order. |
|
Currently, the data types of float16, uint8, int8, int16, int32, int64 are well supported. If use float32, it may cause loss of accuracy. |
BLAS and LAPACK Operations
API Name |
Description |
Supported Platforms |
Warning |
Performs batch matrix-matrix multiplication of two three-dimensional tensors. |
|
None |
|
Compute the inverse of the input matrix. |
|
None |
|
Returns the matrix product of two tensors. |
|
None |
Other Operations
API Name |
Description |
Supported Platforms |
Warning |
Broadcasts input tensor to a given shape. |
|
None |
|
Computes the cumulative sum of input Tensor along dim. |
|
None |
|
Reverses the order of elements in a tensor along the given axis. |
|
None |
|
Return the position indices such that after inserting the values into the sorted_sequence, the order of innermost dimension of the sorted_sequence remains unchanged. |
|
None |
mindspore.mint.nn
Convolution Layers
API Name |
Description |
Supported Platforms |
Warning |
Combines an array of sliding local blocks into a large containing tensor. |
|
None |
|
Extracts sliding local blocks from a batched input tensor. |
|
None |
Linear Layers
API Name |
Description |
Supported Platforms |
Warning |
The linear connected layer. |
|
None |
Dropout Layers
API Name |
Description |
Supported Platforms |
Warning |
Dropout layer for the input. |
|
None |
Loss Functions
API Name |
Description |
Supported Platforms |
Warning |
Adds sigmoid activation function to input as logits, and uses this logits to compute binary cross entropy between the logits and the target. |
|
None |
mindspore.mint.nn.functional
Convolution functions
API Name |
Description |
Supported Platforms |
Warning |
Combines an array of sliding local blocks into a large containing tensor. |
|
Currently, only unbatched(3D) or batched(4D) image-like output tensors are supported. |
|
Extracts sliding local blocks from a batched input tensor. |
|
Currently, batched(4D) image-like tensors are supported. For Ascend, it is only supported on platforms above Atlas A2. |
Pooling functions
API Name |
Description |
Supported Platforms |
Warning |
Performs a 2D max pooling on the input Tensor. |
|
Only support on Atlas A2 training series. |
Non-linear activation functions
API Name |
Description |
Supported Platforms |
Warning |
Batch Normalization for input data and updated parameters. |
|
None |
|
Exponential Linear Unit activation function. |
|
None |
|
Gaussian Error Linear Units activation function. |
|
None |
|
Group Normalization over a mini-batch of inputs. |
|
None |
|
Applies the Layer Normalization on the mini-batch input. |
|
None |
|
leaky_relu activation function. |
|
None |
|
Computes ReLU (Rectified Linear Unit activation function) of input tensors element-wise. |
|
None |
|
Computes Sigmoid of input element-wise. |
|
None |
|
Computes Sigmoid Linear Unit of input element-wise. |
|
None |
|
Applies the Softmax operation to the input tensor on the specified axis. |
|
None |
|
Applies softplus function to input element-wise. |
|
None |
|
Computes hyperbolic tangent of input element-wise. |
|
None |
Linear functions
API Name |
Description |
Supported Platforms |
Warning |
Applies the dense connected operation to the input. |
|
This is an experimental API that is subject to change or deletion. |
Dropout functions
API Name |
Description |
Supported Platforms |
Warning |
During training, randomly zeroes some of the elements of the input tensor with probability p from a Bernoulli distribution. |
|
None |
Sparse functions
API Name |
Description |
Supported Platforms |
Warning |
Retrieve the word embeddings in weight using indices specified in input. |
|
On Ascend, the behavior is unpredictable when the value of input is invalid. |
|
Computes a one-hot tensor. |
|
None |
Loss Functions
API Name |
Description |
Supported Platforms |
Warning |
Computes the binary cross entropy(Measure the difference information between two probability distributions) between predictive value logits and target value labels. |
|
The value of logits must range from 0 to l. |
|
|
Adds sigmoid activation function to input as logits, and uses this logits to compute binary cross entropy between the logits and the target. |
|
None |
Vision functions
API Name |
Description |
Supported Platforms |
Warning |
Given an input and a flow-field grid, computes the output using input values and pixel locations from grid. |
|
None |
|
Pads the input tensor according to the pad. |
|
circular mode has poor performance and is not recommended. |
mindspore.mint.optim
API Name |
Description |
Supported Platforms |
Warning |
Implements Adam Weight Decay algorithm. |
|
This is an experimental optimizer API that is subject to change. This module must be used with lr scheduler module in LRScheduler Class . For Ascend, it is only supported on platforms above Atlas A2. |
mindspore.mint.linalg
Inverses
API Name |
Description |
Supported Platforms |
Warning |
Compute the inverse of the input matrix. |
|
None |