mindspore.mint

mindspore.mint提供了大量的functional、nn、优化器接口,API用法及功能等与业界主流用法一致,方便用户参考使用。 mint接口当前是实验性接口,在图编译模式为O0和PyNative模式下性能比ops更优。当前暂不支持图下沉模式及CPU、GPU后端,后续会逐步完善。

模块导入方法如下:

from mindspore import mint

MindSpore中 mindspore.mint 接口与上一版本相比,新增、删除和支持平台的变化信息请参考 mindspore.mint API接口变更

Tensor

创建运算

接口名

概述

支持平台

警告

mindspore.mint.arange

创建一个从 start 开始, end 结束(不含),步长为 step 序列(一维张量)。

Ascend

mindspore.mint.bernoulli

从伯努利分布中进行采样,并根据输入 input 中第 i 个元素给出的概率值将输出 output 中的第 i 元素随机设置为0或1。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.bincount

统计 input 中每个值的出现次数。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.clone

返回一个输入Tensor的副本。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.eye

创建一个主对角线上元素为1,其余元素为0的Tensor。

Ascend

mindspore.mint.einsum

基于爱因斯坦求和约定(Einsum)符号,沿着指定维度对输入Tensor元素的乘积求和。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.empty

创建一个数据没有初始化的Tensor。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.empty_like

创建一个未初始化的Tesnor,shape和 input 相同,dtype由 dtype 决定,Tensor使用的内存由 device 决定。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.full

创建一个指定shape的Tensor,并用指定值填充。

Ascend

mindspore.mint.full_like

返回一个shape与 input 相同并且使用 fill_value 填充的Tensor。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.linspace

返回一个在区间 startend (包括 startend )内均匀分布的,包含 steps 个值的一维Tensor。

Ascend

Atlas训练系列产品暂不支持int16数据类型。

mindspore.mint.ones

创建一个值全为1的Tensor。

Ascend

mindspore.mint.ones_like

创建一个数值全为1的Tensor,shape和 input 相同,dtype由 dtype 决定。

Ascend

mindspore.mint.randint

返回一个Tensor,shape和dtype由输入决定,其元素为 [ low , high ) 区间的随机整数。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.randint_like

返回一个Tensor,其元素为 [ low , high ) 区间的随机整数,根据 input 决定shape和dtype。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.randn

返回一个Tensor,shape和dtype由输入决定,其元素为服从标准正态分布的数字。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.randn_like

返回shape与输入相同,类型为 dtype 的Tensor,dtype由输入决定,其元素取值服从 \([0, 1)\) 区间内的正态分布。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.randperm

生成从 0 到 n-1 的整数随机排列。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.zeros

创建一个值全为0的Tensor。

Ascend

mindspore.mint.zeros_like

创建一个数值全为0的Tensor,shape和 input 相同,dtype由 dtype 决定。

Ascend

索引、切分、连接、突变运算

接口名

概述

支持平台

警告

mindspore.mint.cat

在指定维度上拼接输入Tensor。

Ascend

mindspore.mint.chunk

沿着指定轴 dim 将输入Tensor切分成 chunks 个sub-tensor。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.concat

mindspore.mint.cat() 的别名。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.count_nonzero

计算输入Tensor指定轴上的非零元素的数量。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.gather

返回输入Tensor在指定 index 索引对应的元素组成的切片。

Ascend

在Ascend后端,以下场景将导致不可预测的行为: 正向执行流程中,当 index 的取值不在范围 [-input.shape[dim], input.shape[dim]) 内; 反向执行流程中,当 index 的取值不在范围 [0, input.shape[dim]) 内。

mindspore.mint.index_select

返回一个新的Tensor,该Tensor沿维度 dimindex 中给定的索引对 input 进行选择。

Ascend

mindspore.mint.masked_select

返回一个一维Tensor,其中的内容是 input 中对应于 mask 中True位置的值。

Ascend

mindspore.mint.permute

按照输入 dims 的维度顺序排列输入Tensor。

Ascend

mindspore.mint.reshape

基于给定的 shape ,对输入Tensor进行重新排列。

Ascend

mindspore.mint.scatter

根据指定索引将 src 中的值更新到 input 中返回输出。

Ascend

mindspore.mint.scatter_add

src 中所有的元素添加到 inputindex 指定的索引处。

Ascend

mindspore.mint.split

根据指定的轴将输入Tensor切分成块。

Ascend

mindspore.mint.narrow

沿着指定的轴,指定起始位置获取指定长度的Tensor。

Ascend

mindspore.mint.nonzero

返回所有非零元素下标位置。

Ascend

mindspore.mint.tile

通过复制 dimsinput 来创建新的Tensor。

Ascend

mindspore.mint.tril

返回输入Tensor input 的下三角形部分(包含对角线和下面的元素),并将其他元素设置为0。

Ascend

mindspore.mint.select

在给定索引处沿选定维度对输入张量进行切片。

Ascend

这是一个实验性API,可能会更改或删除。

mindspore.mint.squeeze

返回删除指定 dim 中大小为1的维度后的Tensor。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.stack

在指定轴上对输入Tensor序列进行堆叠。

Ascend

mindspore.mint.swapaxes

mindspore.mint.transpose() 的别名。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.transpose

交换Tensor的两个维度。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.triu

返回输入Tensor input 的上三角形部分(包含对角线和下面的元素),并将其他元素设置为0。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.unbind

根据指定轴对Tensor进行分解。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.unique_consecutive

对输入Tensor中连续且重复的元素去重。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.unsqueeze

对输入 input 在给定维上添加额外维度。

Ascend

mindspore.mint.where

返回一个Tensor,Tensor的元素从 inputother 中根据 condition 选择。

Ascend

随机采样

接口名

概述

支持平台

警告

mindspore.mint.multinomial

根据输入生成一个多项式分布的Tensor。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.normal

根据正态(高斯)随机数分布生成随机数。

Ascend

mindspore.mint.rand_like

返回shape与输入相同,类型为 dtype 的Tensor,dtype由输入决定,其元素取值服从 \([0, 1)\) 区间内的均匀分布。

Ascend

mindspore.mint.rand

返回一个Tensor,shape和dtype由输入决定,其元素为服从均匀分布的 \([0, 1)\) 区间的数字。

Ascend

数学运算

逐元素运算

接口名

概述

支持平台

警告

mindspore.mint.abs

逐元素计算输入Tensor的绝对值。

Ascend

mindspore.mint.add

other 缩放 scalar 后与 input 相加。

Ascend

mindspore.mint.addmv

matvec 矩阵向量相乘,且将输入向量 input 加到最终结果中。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.acos

逐元素计算输入Tensor的反余弦。

Ascend

mindspore.mint.acosh

逐元素计算输入Tensor的反双曲余弦。

Ascend

mindspore.mint.arccos

mindspore.mint.acos() 的别名。

Ascend

mindspore.mint.arccosh

mindspore.mint.acosh() 的别名。

Ascend

mindspore.mint.arcsin

mindspore.mint.asin() 的别名。

Ascend

mindspore.mint.arcsinh

mindspore.mint.asinh() 的别名。

Ascend

mindspore.mint.arctan

mindspore.mint.atan() 的别名。

Ascend

mindspore.mint.arctan2

mindspore.mint.atan2() 的别名。

Ascend

mindspore.mint.arctanh

mindspore.mint.atanh() 的别名。

Ascend

mindspore.mint.asin

逐元素计算输入Tensor的反正弦。

Ascend

mindspore.mint.asinh

计算输入元素的反双曲正弦。

Ascend

mindspore.mint.atan

逐元素计算输入Tensor的反正切值。

Ascend

mindspore.mint.atan2

逐元素计算input/other的反正切值。

Ascend

mindspore.mint.atanh

逐元素计算输入Tensor的反双曲正切值。

Ascend

mindspore.mint.bitwise_and

逐元素执行两个Tensor的与运算。

Ascend

mindspore.mint.bitwise_or

逐元素执行两个Tensor的或运算。

Ascend

mindspore.mint.bitwise_xor

逐元素执行两个Tensor的异或运算。

Ascend

mindspore.mint.ceil

向上取整函数。

Ascend

mindspore.mint.clamp

将输入Tensor的值裁剪到指定的最小值和最大值之间。

Ascend

mindspore.mint.cos

逐元素计算输入的余弦。

Ascend

如果使用float64,可能会存在精度丢失的问题。

mindspore.mint.cosh

逐元素计算 input 的双曲余弦值。

Ascend

mindspore.mint.cross

返回沿着维度 dim 上,inputother 的向量积(叉积)。

Ascend

mindspore.mint.diff

计算沿给定维度的第n个正向差。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.div

逐元素计算当前Tensor除以输入的另一个Tensor的商。

Ascend

mindspore.mint.divide

mindspore.mint.div() 的别名。

Ascend

mindspore.mint.erf

逐元素计算 input 的高斯误差函数。

Ascend

mindspore.mint.erfc

逐元素计算 input 的互补误差函数。

Ascend

mindspore.mint.erfinv

计算输入的逆误差函数。

Ascend

mindspore.mint.exp

逐元素计算 input 的指数。

Ascend

mindspore.mint.exp2

逐元素计算Tensor input 以2为底的指数。

Ascend

mindspore.mint.expm1

逐元素计算输入Tensor的指数,然后减去1。

Ascend

mindspore.mint.fix

mindspore.mint.trunc() 的别名。

Ascend

mindspore.mint.float_power

使用双精度计算 input 中每个元素的 exponent 次幂,并返回一个float64类型的Tensor。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.floor

逐元素向下取整函数。

Ascend

mindspore.mint.fmod

计算除法运算 input/other 的浮点余数。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.frac

计算 input 中每个元素的小数部分。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.lerp

基于权重参数计算两个Tensor之间的线性插值。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.log

逐元素返回Tensor的自然对数。

Ascend

如果输入值在(0, 0.01]或[0.95, 1.05]范围内,则输出精度可能会存在误差。

mindspore.mint.log1p

对输入Tensor逐元素加一后计算自然对数。

Ascend

mindspore.mint.log2

逐元素返回Tensor以2为底的对数。

Ascend

这是一个实验性API,后续可能修改或删除。 如果输入值在(0, 0.01]或[0.95, 1.05]范围内,则输出精度可能会存在误差。

mindspore.mint.log10

逐元素返回Tensor以10为底的对数。

Ascend

这是一个实验性API,后续可能修改或删除。 如果输入值在(0, 0.01]或[0.95, 1.05]范围内,则输出精度可能会存在误差。

mindspore.mint.logaddexp

计算输入的指数和的对数。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.logical_and

逐元素计算两个Tensor的逻辑与运算。

Ascend

mindspore.mint.logical_not

逐元素计算一个Tensor的逻辑非运算。

Ascend

mindspore.mint.logical_or

逐元素计算两个Tensor的逻辑或运算。

Ascend

mindspore.mint.logical_xor

逐元素计算两个Tensor的逻辑异或运算。

Ascend

mindspore.mint.mul

otherinput 相乘。

Ascend

mindspore.mint.mv

实现矩阵 input 和向量 vec 相乘。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.nansum

计算 input 指定维度元素的和,将非数字(NaNs)处理为零。

Ascend

仅支持 Atlas A2 训练系列产品。 这是一个实验性API,后续可能修改或删除。

mindspore.mint.nan_to_num

input 中的 NaN 、正无穷大和负无穷大值分别替换为 nanposinfneginf 指定的值。

Ascend

对于Ascend,仅支持 Atlas A2 训练系列产品。 这是一个实验性API,后续可能修改或删除。

mindspore.mint.neg

计算输入input的相反数并返回。

Ascend

mindspore.mint.negative

mindspore.mint.neg() 的别名。

Ascend

mindspore.mint.pow

计算 input 中每个元素的 exponent 次幂。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.polar

将极坐标转化为笛卡尔坐标。

Ascend

mindspore.mint.ravel

沿着0轴方向,将多维Tensor展开成一维。

Ascend

mindspore.mint.reciprocal

返回输入Tensor每个元素的倒数。

Ascend

mindspore.mint.remainder

逐元素计算 input 除以 other 后的余数。

Ascend

mindspore.mint.roll

沿轴移动Tensor的元素。

Ascend

mindspore.mint.round

对输入数据进行四舍五入到最接近的整数数值。

Ascend

mindspore.mint.rsqrt

逐元素计算输入Tensor元素的平方根倒数。

Ascend

mindspore.mint.sigmoid

逐元素计算Sigmoid激活函数。

Ascend

mindspore.mint.sign

按sign公式逐元素计算输入Tensor。

Ascend

mindspore.mint.sin

逐元素计算输入Tensor的正弦。

Ascend

mindspore.mint.sinc

计算输入的归一化正弦值。

Ascend

mindspore.mint.sinh

逐元素计算输入Tensor的双曲正弦。

Ascend

mindspore.mint.softmax

mindspore.mint.nn.functional.softmax() 的别名。

Ascend

mindspore.mint.sqrt

逐元素返回当前Tensor的平方根。

Ascend

mindspore.mint.square

逐元素返回Tensor的平方。

Ascend

mindspore.mint.sub

other 缩放 scalar 后与 input 相减。

Ascend

mindspore.mint.t

转置输入Tensor。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.tan

逐元素计算输入元素的正切值。

Ascend

mindspore.mint.tanh

逐元素计算输入元素的双曲正切。

Ascend

mindspore.mint.trunc

返回一个新的Tensor,该Tensor具有输入元素的截断整数值。

Ascend

mindspore.mint.xlogy

计算第一个输入乘以第二个输入的对数。

Ascend

Reduction运算

接口名

概述

支持平台

警告

mindspore.mint.amax

计算输入 input 中指定 dim 维度上所有元素的最大值,并根据 keepdim 参数决定是否保留该维度。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.amin

计算输入 input 中指定 dim 维度上所有元素的最小值,并根据 keepdim 参数决定是否保留该维度。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.argmax

返回输入Tensor最大值索引。

Ascend

mindspore.mint.argmin

返回输入Tensor在指定轴上的最小值索引。

Ascend

mindspore.mint.all

input 中所有元素进行“逻辑与”。

Ascend

mindspore.mint.any

默认情况下,通过对维度中所有元素进行“逻辑或”来减少 input 的维度。

Ascend

mindspore.mint.cumprod

计算输入Tensor input 沿轴 dim 的累计积,当前为实验性接口。

Ascend

mindspore.mint.histc

计算Tensor的直方图。

Ascend

这是一个实验性API,后续可能修改或删除。 如果 input 是int64,有效取值在int32范围内,超出范围可能产生精度误差。

mindspore.mint.logsumexp

计算输入 input 中指定 dim 维度上所有元素指数和的对数(计算过程经过数值稳定处理), 并根据 keepdim 参数决定是否保留该维度。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.max

返回输入Tensor的最大值。

Ascend

mindspore.mint.mean

移除输入所有维度,返回 input 中所有元素的平均值。

Ascend

mindspore.mint.median

输出指定维度 dim 上的中值与其对应的索引。

Ascend

mindspore.mint.min

返回输入Tensor的最小值。

Ascend

mindspore.mint.norm

返回给定Tensor的矩阵范数或向量范数。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.prod

计算Tensor所有元素的乘积。

Ascend

mindspore.mint.sum

计算Tensor所有元素的和。

Ascend

mindspore.mint.std

计算指定维度 dim 上的标准差。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.std_mean

默认情况下,返回Tensor各维度上的标准差和均值。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.unique

对输入Tensor中元素去重。

Ascend

mindspore.mint.var

计算指定维度 dim 上的方差。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.var_mean

默认情况下,返回Tensor各维度上的方差和均值。

Ascend

这是一个实验性API,后续可能修改或删除。

比较运算

接口名

概述

支持平台

警告

mindspore.mint.allclose

返回一个布尔型标量,表示 input 的每个元素均与 other 的对应元素在给定容忍度内“接近”。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.argsort

按指定顺序对输入Tensor沿给定维度进行排序,并返回排序后的索引。

Ascend

这是一个实验性API,后续可能修改或删除

mindspore.mint.eq

逐元素比较两个输入Tensor是否相等。

Ascend

mindspore.mint.equal

比较两个输入是否相等。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.greater

按元素比较输入参数 \(input > other\) 的值,输出结果为bool值。

Ascend

mindspore.mint.greater_equal

给定两个张量(Tensors),逐元素比较它们,以检查第一个张量中的每个元素是否大于或等于第二个张量中的相应元素。

Ascend

mindspore.mint.gt

按元素比较输入参数 \(input,other\) 的值,输出结果为bool值。

Ascend

mindspore.mint.isclose

返回一个布尔型Tensor,表示 input 的每个元素与 other 的对应元素在给定容忍度内是否“接近”。

Ascend

mindspore.mint.isfinite

判断输入数据每个位置上的元素是否是有限数。

Ascend

mindspore.mint.isinf

确定输入Tensor每个位置上的元素是否为正无穷或负无穷。

Ascend

这是一个实验性API,后续可能修改或删除。 该API目前只支持在Atlas A2训练系列产品上使用。

mindspore.mint.isneginf

确定输入Tensor每个位置上的元素是否为负无穷。

Ascend

这是一个实验性API,后续可能修改或删除。 该API目前只支持在Atlas A2训练系列产品上使用。

mindspore.mint.le

逐元素计算 \(input <= other\) 的bool值。

Ascend

mindspore.mint.less

逐元素计算 \(input < other\) ,返回为bool。

Ascend

mindspore.mint.less_equal

逐元素计算 \(input <= other\) 的bool值。

Ascend

mindspore.mint.lt

mindspore.mint.less() 的别名。

Ascend

mindspore.mint.maximum

逐元素计算两个输入Tensor中的最大值。

Ascend

如果所有输入都为标量int类型,在Graph模式下,输出为int32类型的Tensor,在PyNative模式下,输出为int64类型的Tensor。

mindspore.mint.minimum

逐元素计算两个输入Tensor中的最小值。

Ascend

mindspore.mint.ne

计算两个Tensor是否不相等。

Ascend

mindspore.mint.not_equal

mindspore.mint.ne() 的别名。

Ascend

mindspore.mint.topk

沿给定维度查找 k 个最大或最小元素和对应的索引。

Ascend

如果 sorted 设置为False, 由于在不同平台上存在内存排布以及遍历方式不同等问题,sorted 设置为False时计算结果的显示顺序可能会出现不一致的情况。

mindspore.mint.sort

按指定顺序对输入Tensor的指定维上的元素进行排序。

Ascend

目前能良好支持的数据类型有:float16、uint8、int8、int16、int32、int64。如果使用float32,可能产生精度误差。

BLAS和LAPACK运算

接口名

概述

支持平台

警告

mindspore.mint.addbmm

batch1batch2 应用批量矩阵乘法后进行reduced add, input 和最终的结果相加。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.addmm

对输入的两个二维矩阵mat1与mat2相乘,并将结果与input相加。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.baddbmm

对输入的两个三维矩阵batch1与batch2相乘,并将结果与input相加。

Ascend

mindspore.mint.bmm

基于batch维度的两个Tensor的矩阵乘法,仅支持三维。

Ascend

mindspore.mint.dot

计算两个1DTensor的点积。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.inverse

计算输入矩阵的逆。

Ascend

mindspore.mint.matmul

计算两个数组的矩阵乘积。

Ascend

mindspore.mint.meshgrid

从给定的Tensor生成网格矩阵。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.mm

计算两个矩阵的乘积。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.outer

计算 inputvec2 的外积。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.trace

返回 input 的主对角线方向上的总和。

Ascend

其他运算

接口名

概述

支持平台

警告

mindspore.mint.broadcast_to

将输入shape广播到目标shape。

Ascend

mindspore.mint.cdist

计算两个Tensor每对行向量之间的p-norm距离。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.cummax

返回一个元组(最值、索引),其中最值是输入Tensor input 沿维度 dim 的累积最大值,索引是每个最大值的索引位置。

Ascend

mindspore.mint.cummin

返回一个元组(最值、索引),其中最值是输入Tensor input 沿维度 dim 的累积最小值,索引是每个最小值的索引位置。

Ascend

mindspore.mint.cumsum

计算输入Tensor input 沿轴 dim 的累积和。

Ascend

mindspore.mint.flatten

沿着从 start_dimend_dim 的维度,对输入Tensor进行展平。

Ascend

mindspore.mint.flip

沿给定轴翻转Tensor中元素的顺序。

Ascend

mindspore.mint.repeat_interleave

沿着轴重复Tensor的元素,类似 mindspore.numpy.repeat()

Ascend

仅Atlas A2训练系列产品支持。

mindspore.mint.searchsorted

返回位置索引,根据这个索引将 values 插入 sorted_sequence 后,sorted_sequence 的最内维度的顺序保持不变。

Ascend

mindspore.mint.tril

返回输入Tensor input 的下三角形部分(包含对角线和下面的元素),并将其他元素设置为0。

Ascend

mindspore.mint.nn

损失函数

接口名

概述

支持平台

警告

mindspore.mint.nn.L1Loss

L1Loss用于计算预测值和目标值之间的平均绝对误差。

Ascend

卷积层

接口名

概述

支持平台

警告

mindspore.mint.nn.Conv2d

二维卷积层。

Ascend

mindspore.mint.nn.Conv3d

三维卷积层。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.nn.ConvTranspose2d

将2D转置卷积运算应用于由多个输入平面组成的输入图像。

Ascend

这是一个实验性API,后续可能修改或删除。 在输入非连续场景下, output_padding 必须小于 stride 。 在Atlas训练系列产品上,float32类型输入时,仅支持 groups 为1。

mindspore.mint.nn.Fold

将提取出的滑动局部区域块还原成更大的输出Tensor。

Ascend

mindspore.mint.nn.Unfold

从一个batch的输入Tensor中提取滑动局部块。

Ascend

归一化层

接口名

概述

支持平台

警告

mindspore.mint.nn.BatchNorm1d

在二维或三维输入上应用批归一化。

Ascend

该接口不支持动态Rank。 这是一个实验性API,后续可能修改或删除。

mindspore.mint.nn.BatchNorm2d

在四维输入上应用批归一化。

Ascend

该接口不支持动态Rank。 这是一个实验性API,后续可能修改或删除。

mindspore.mint.nn.BatchNorm3d

在五维输入上应用批归一化。

Ascend

该接口不支持动态Rank。 这是一个实验性API,后续可能修改或删除。

mindspore.mint.nn.GroupNorm

在mini-batch输入上进行组归一化。

Ascend

mindspore.mint.nn.LayerNorm

在mini-batch输入上应用层归一化(Layer Normalization)。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.nn.SyncBatchNorm

在N维输入上进行跨设备同步批归一化(Batch Normalization,BN)。

Ascend

这是一个实验性API,后续可能修改或删除。

非线性激活层 (加权和,非线性)

接口名

概述

支持平台

警告

mindspore.mint.nn.ELU

指数线性单元激活函数(Exponential Linear Unit activation function)。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.nn.GELU

高斯误差线性单元激活函数(Gaussian Error Linear Unit)。

Ascend

mindspore.mint.nn.Hardshrink

逐元素计算Hard Shrink激活函数。

Ascend

mindspore.mint.nn.Hardsigmoid

逐元素计算Hard Sigmoid激活函数。

Ascend

mindspore.mint.nn.Hardswish

逐元素计算Hard Swish激活函数。

Ascend

mindspore.mint.nn.LogSigmoid

逐元素计算LogSigmoid激活函数。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.nn.LogSoftmax

在指定轴上对输入Tensor应用LogSoftmax函数。

Ascend

mindspore.mint.nn.Mish

逐元素计算输入Tensor的MISH(A Self Regularized Non-Monotonic Neural Activation Function 自正则化非单调神经激活函数)。

Ascend

mindspore.mint.nn.PReLU

逐元素计算PReLU(PReLU Activation Operator)激活函数。

Ascend

mindspore.mint.nn.ReLU

逐元素计算ReLU(Rectified Linear Unit activation function)修正线性单元激活函数。

Ascend

mindspore.mint.nn.ReLU6

ReLU6激活函数。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.nn.SELU

逐元素计算激活函数SELU(Scaled exponential Linear Unit)。

Ascend

mindspore.mint.nn.SiLU

逐元素计算SiLU激活函数。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.nn.Softmax

将Softmax函数应用于n维输入Tensor。

Ascend

mindspore.mint.nn.Softshrink

逐元素计算Soft Shrink激活函数。

Ascend

mindspore.mint.nn.Tanh

逐元素计算Tanh(双曲正切值)激活函数,返回一个新的Tensor。

Ascend

这是一个实验性API,后续可能修改或删除。

嵌入层

接口名

概述

支持平台

警告

mindspore.mint.nn.Embedding

input 中的值作为索引,从 weight 中查询对应的embedding向量。

Ascend

这是一个实验性API,后续可能修改或删除。 在Ascend后端, input 的值非法将导致不可预测的行为。

线性层

接口名

概述

支持平台

警告

mindspore.mint.nn.Linear

全连接层。

Ascend

在PyNative模式下,如果 biasFalsex 不可以大于6D。

Dropout层

接口名

概述

支持平台

警告

mindspore.mint.nn.Dropout

随机丢弃层。

Ascend

mindspore.mint.nn.Dropout2d

在训练期间,以服从伯努利分布的概率 p 随机将输入Tensor的某些通道归零(对于shape为 \(NCHW\) 的四维Tensor,其通道特征图指的是后两维 \(HW\) 的二维特征图)。

Ascend

这是一个实验性API,后续可能修改或删除。

池化层

接口名

概述

支持平台

警告

mindspore.mint.nn.AdaptiveAvgPool1d

对由多个输入平面组成的输入信号应用1D自适应平均池化。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.nn.AdaptiveAvgPool2d

对由多个输入平面组成的输入信号应用2D自适应平均池化。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.nn.AdaptiveAvgPool3d

对输入Tensor,提供三维的自适应平均池化操作。

Ascend

对于Ascend,仅支持 Atlas A2 训练系列产品。 这是一个实验性API,后续可能修改或删除。

mindspore.mint.nn.AvgPool2d

对输入张量应用二维平均池化,可视为二维输入平面的组合。

Ascend

mindspore.mint.nn.MaxUnpool2d

Maxpool2d 的逆过程。

Ascend

这是一个实验性API,后续可能修改或删除。

填充层

接口名

概述

支持平台

警告

mindspore.mint.nn.ConstantPad1d

根据参数 padding 以及 value 对输入 input 最后1维进行填充。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.nn.ConstantPad2d

根据参数 padding 以及 value 对输入 input 最后2维进行填充。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.nn.ConstantPad3d

根据参数 padding 以及 value 对输入 input 最后3维进行填充。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.nn.ReflectionPad1d

使用输入边界的反射对输入最后1维 input 进行填充。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.nn.ReflectionPad2d

使用输入边界的反射对输入最后2维 input 进行填充。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.nn.ReflectionPad3d

使用输入边界的反射对输入最后3维 input 进行填充。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.nn.ReplicationPad1d

使用输入边界值对输入最后1维 input 进行填充。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.nn.ReplicationPad2d

使用输入边界值对输入最后2维 input 进行填充。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.nn.ReplicationPad3d

使用输入边界值对输入最后3维 input 进行填充。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.nn.ZeroPad1d

根据参数 padding 对输入 input 最后1维填充零。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.nn.ZeroPad2d

根据参数 padding 对输入 input 最后2维填充零。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.nn.ZeroPad3d

根据参数 padding 对输入 input 最后3维填充零。

Ascend

这是一个实验性API,后续可能修改或删除。

损失函数

接口名

概述

支持平台

警告

mindspore.mint.nn.BCELoss

计算目标值和预测值之间的二值交叉熵损失值。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.nn.BCEWithLogitsLoss

输入 input 经过sigmoid激活函数后作为预测值, 用此预测值计算和目标值之间的二值交叉熵损失。

Ascend

mindspore.mint.nn.CrossEntropyLoss

获取预测值和目标值之间的交叉熵损失。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.nn.MSELoss

用于计算预测值与标签值之间的均方误差。

Ascend

mindspore.mint.nn.NLLLoss

reduction为'none'时,负对数似然损失公式如下:。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.nn.SmoothL1Loss

计算平滑L1损失,该L1损失函数有稳健性。

Ascend

这是一个实验性API,后续可能修改或删除。

图像处理层

接口名

概述

支持平台

警告

mindspore.mint.nn.Upsample

按照给定的 sizescale_factor 根据 mode 设置的插值方式,对输入 input 进行插值。

Ascend

这是一个实验性API,后续可能修改或删除。

工具

接口名

概述

支持平台

警告

mindspore.mint.nn.Identity

网络占位符,返回与输入完全一致。

Ascend

mindspore.mint.nn.functional

卷积函数

接口名

概述

支持平台

警告

mindspore.mint.nn.functional.conv2d

对输入Tensor计算二维卷积。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.nn.functional.conv3d

对输入Tensor计算三维卷积。

Ascend

该API不支持Atlas系列产品。 这是一个实验性API,后续可能修改或删除。

mindspore.mint.nn.functional.conv_transpose2d

将2D转置卷积运算应用于由多个输入平面组成的输入图像,有时也称为反卷积(尽管它不是实际的反卷积)。

Ascend

这是一个实验性API,后续可能修改或删除。 在输入非连续场景下, output_padding 必须小于 stride 。 在Atlas训练系列产品上,float32类型输入时,仅支持 groups 为1。

mindspore.mint.nn.functional.fold

将提取出的滑动局部区域块还原成更大的输出Tensor。

Ascend

目前,只支持3-D或4-D(包含批维度)的类图像输出Tensor。

mindspore.mint.nn.functional.unfold

从一个batch的输入Tensor中提取滑动局部块。

Ascend

目前,只支持4-D(包含批维度)的类图像Tensor。 对于Ascend,仅Atlas A2以上平台支持。

池化函数

接口名

概述

支持平台

警告

mindspore.mint.nn.functional.adaptive_avg_pool1d

对一个多平面输入信号执行一维自适应平均池化。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.nn.functional.adaptive_avg_pool2d

对一个多平面输入信号执行二维自适应平均池化。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.nn.functional.avg_pool1d

在输入Tensor上应用1D平均池化,输入Tensor可以看作是由一系列1D平面组成的。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.nn.functional.avg_pool2d

在输入Tensor上应用2D平均池化,输入Tensor可以看作是由一系列2D平面组成的。

Ascend

mindspore.mint.nn.functional.max_pool2d

二维最大值池化。

Ascend

只支持 Atlas A2 训练系列产品。

mindspore.mint.nn.functional.max_unpool2d

max_pool2d 的逆过程。

Ascend

这是一个实验性API,后续可能修改或删除。

非线性激活函数

接口名

概述

支持平台

警告

mindspore.mint.nn.functional.batch_norm

对输入数据进行批量归一化和更新参数。

Ascend

mindspore.mint.nn.functional.elu

指数线性单元激活函数。

Ascend

mindspore.mint.nn.functional.gelu

高斯误差线性单元激活函数。

Ascend

mindspore.mint.nn.functional.group_norm

在mini-batch输入上进行组归一化。

Ascend

mindspore.mint.nn.functional.hardshrink

Hard Shrink激活函数。

Ascend

mindspore.mint.nn.functional.hardsigmoid

Hard Sigmoid激活函数。

Ascend

mindspore.mint.nn.functional.hardswish

Hard Swish激活函数。

Ascend

mindspore.mint.nn.functional.layer_norm

在mini-batch输入上应用层归一化(Layer Normalization)。

Ascend

mindspore.mint.nn.functional.leaky_relu

leaky_relu激活函数。

Ascend

mindspore.mint.nn.functional.log_softmax

在指定轴上对输入Tensor应用LogSoftmax函数。

Ascend

mindspore.mint.nn.functional.logsigmoid

按元素计算LogSigmoid激活函数。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.nn.functional.mish

逐元素计算输入Tensor的MISH(A Self Regularized Non-Monotonic Neural Activation Function 自正则化非单调神经激活函数)。

Ascend

mindspore.mint.nn.functional.prelu

带参数的线性修正单元激活函数(Parametric Rectified Linear Unit activation function)。

Ascend

mindspore.mint.nn.functional.relu

对输入Tensor逐元素计算线性修正单元激活函数(Rectified Linear Unit)值。

Ascend

mindspore.mint.nn.functional.relu6

逐元素计算输入Tensor的ReLU(修正线性单元),其上限为6。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.nn.functional.relu_

对输入Tensor逐元素原地计算线性修正单元激活函数(Rectified Linear Unit)值。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.nn.functional.selu

激活函数selu(Scaled exponential Linear Unit)。

Ascend

mindspore.mint.nn.functional.sigmoid

逐元素计算Sigmoid激活函数。

Ascend

mindspore.mint.nn.functional.silu

逐元素计算激活函数SiLU(Sigmoid Linear Unit)。

Ascend

mindspore.mint.nn.functional.softmax

在指定轴上对输入Tensor执行Softmax激活函数做归一化操作。

Ascend

mindspore.mint.nn.functional.softplus

将softplus函数作用于 input 的每个元素上。

Ascend

mindspore.mint.nn.functional.softshrink

Soft Shrink激活函数。

Ascend

mindspore.mint.nn.functional.tanh

逐元素计算输入元素的双曲正切。

Ascend

归一化函数

接口名

概述

支持平台

警告

mindspore.mint.nn.functional.normalize

将输入的张量按照指定维度进行归一化。

Ascend

这是一个实验性API,后续可能修改或删除。

线性函数

接口名

概述

支持平台

警告

mindspore.mint.nn.functional.linear

对输入 input 应用全连接操作。

Ascend

这是一个实验性API,后续可能修改或删除。 在PyNative模式下,如果 bias 不是1D, input 不可以大于6D。

Dropout函数

接口名

概述

支持平台

警告

mindspore.mint.nn.functional.dropout

在训练期间,以服从伯努利分布的概率 p 随机将输入Tensor的某些值归零,起到减少神经元相关性的作用,避免过拟合。

Ascend

mindspore.mint.nn.functional.dropout2d

在训练期间,以服从伯努利分布的概率 p 随机将输入Tensor的某些通道归零(对于形状为 \(NCHW\) 的四维Tensor,其通道特征图指的是后两维 \(HW\) 形状的二维特征图)。

Ascend

这是一个实验性API,后续可能修改或删除。

稀疏函数

接口名

概述

支持平台

警告

mindspore.mint.nn.functional.embedding

input 中的值作为索引,从 weight 中查询对应的embedding向量。

Ascend

在Ascend后端, input 的值非法将导致不可预测的行为。

mindspore.mint.nn.functional.one_hot

返回一个one-hot类型的Tensor。

Ascend

损失函数

接口名

概述

支持平台

警告

mindspore.mint.nn.functional.binary_cross_entropy

计算预测值 input 和 目标值 target 之间的二值交叉熵(度量两个概率分布间的差异性信息)损失。

Ascend

input 的值必须要在0-1范围内。

mindspore.mint.nn.functional.binary_cross_entropy_with_logits

输入经过sigmoid激活函数后作为预测值, binary_cross_entropy_with_logits 计算预测值和目标值之间的二值交叉熵损失。

Ascend

mindspore.mint.nn.functional.l1_loss

用于计算预测值和目标值之间的平均绝对误差。

Ascend

mindspore.mint.nn.functional.mse_loss

计算预测值和标签值之间的均方误差。

Ascend

mindspore.mint.nn.functional.nll_loss

获取预测值和目标值之间的负对数似然损失。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.nn.functional.smooth_l1_loss

计算平滑L1损失,该L1损失函数有稳健性。

Ascend

这是一个实验性API,后续可能修改或删除。

Vision函数

接口名

概述

支持平台

警告

mindspore.mint.nn.functional.interpolate

按照给定的 sizescale_factor 根据 mode 设置的插值方式,对输入 input 进行插值。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.nn.functional.grid_sample

给定一个输入和一个网格,使用网格中的输入值和像素位置计算输出。

Ascend

mindspore.mint.nn.functional.pad

根据参数 pad 对输入进行填充。

Ascend

circular 模式性能较差,不推荐使用。

mindspore.mint.optim

接口名

概述

支持平台

警告

mindspore.mint.optim.Adam

Adaptive Moment Estimation (Adam)算法的实现。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.optim.AdamW

Adaptive Moment Estimation Weight Decay(AdamW)算法的实现。

Ascend

这是一个实验性的优化器接口,需要和 LRScheduler 下的动态学习率接口配合使用。 对于Ascend,仅Atlas A2以上平台支持。

mindspore.mint.linalg

逆数

接口名

概述

支持平台

警告

mindspore.mint.linalg.inv

计算输入矩阵的逆。

Ascend

mindspore.mint.linalg.matrix_norm

返回给定Tensor在指定维度上的矩阵范数。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.linalg.norm

返回给定Tensor的矩阵范数或向量范数。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.linalg.vector_norm

返回给定Tensor在指定维度上的向量范数。

Ascend

这是一个实验性API,后续可能修改或删除。

mindspore.mint.special

逐元素运算

接口名

概述

支持平台

警告

mindspore.mint.special.erfc

逐元素计算 input 的互补误差函数。

Ascend

mindspore.mint.special.exp2

逐元素计算Tensor input 以2为底的指数。

Ascend

mindspore.mint.special.expm1

逐元素计算输入Tensor的指数,然后减去1。

Ascend

mindspore.mint.special.log1p

对输入Tensor逐元素加一后计算自然对数。

Ascend

mindspore.mint.special.log_softmax

在指定轴上对输入Tensor应用LogSoftmax函数。

Ascend

mindspore.mint.special.round

对输入数据进行四舍五入到最接近的整数数值。

Ascend

mindspore.mint.special.sinc

计算输入的归一化正弦值。

Ascend

mindspore.mint.distributed

接口名

概述

支持平台

警告

mindspore.mint.distributed.all_gather

汇聚指定的通信组中的Tensor,并返回汇聚后的张量。

Ascend

mindspore.mint.distributed.all_gather_into_tensor

汇聚指定的通信组中的Tensor,并返回汇聚后的张量。

Ascend

mindspore.mint.distributed.all_gather_object

汇聚指定的通信组中的Python对象。

Ascend

mindspore.mint.distributed.all_reduce

使用指定方式对通信组内的所有设备的Tensor数据进行规约操作,所有设备都得到相同的结果,返回规约操作后的张量。

Ascend

mindspore.mint.distributed.all_to_all

根据用户输入的张量列表,将对应的张量发送到远端设备,并从其他设备接收张量,返回一个接收的张量列表。

Ascend

mindspore.mint.distributed.all_to_all_single

根据用户输入的切分大小,把输入tensor切分后,发送到其他的设备上,并从其他设备接收切分块,然后合并到一个输出tensor中。

Ascend

mindspore.mint.distributed.barrier

同步通信域内的多个进程。

Ascend

mindspore.mint.distributed.batch_isend_irecv

异步地发送和接收张量。

Ascend

mindspore.mint.distributed.broadcast

对输入数据整组广播。

Ascend

mindspore.mint.distributed.broadcast_object_list

对输入Python对象进行整组广播。

Ascend

mindspore.mint.distributed.destroy_process_group

销毁指定通讯group。

Ascend

mindspore.mint.distributed.gather

对通信组的输入张量进行聚合。

Ascend

mindspore.mint.distributed.gather_object

对通信组的输入Python对象进行聚合。

Ascend

mindspore.mint.distributed.get_backend

在指定通信组中获取当前分布式后端的名称。

Ascend

mindspore.mint.distributed.get_global_rank

由指定通信组中的设备序号获取通信集群中的全局设备序号。

Ascend

mindspore.mint.distributed.get_group_rank

由通信集群中的全局设备序号获取指定用户通信组中的rank ID。

Ascend

mindspore.mint.distributed.get_process_group_ranks

获取指定通信组中的进程,并将通信组中的进程编号以列表方式返回。

Ascend

mindspore.mint.distributed.get_rank

在指定通信组中获取当前的设备序号。

Ascend

mindspore.mint.distributed.get_world_size

获取指定通信组实例的rank_size。

Ascend

mindspore.mint.distributed.init_process_group

初始化通信服务并创建默认通讯group(group=GlobalComm.WORLD_COMM_GROUP)。

Ascend

mindspore.mint.distributed.irecv

异步接收张量到指定线程。

Ascend

mindspore.mint.distributed.isend

异步发送张量到指定线程。

Ascend

mindspore.mint.distributed.new_group

创建用户自定义的通信组实例。

Ascend

mindspore.mint.distributed.P2POp

用于存放关于'isend'、'irecv'相关的信息, 并用于 batch_isend_irecv 接口的入参。

Ascend

mindspore.mint.distributed.recv

同步接收张量到指定线程。

Ascend

mindspore.mint.distributed.reduce

规约指定通信组中的张量,并将规约结果发送到目标为dst的进程(全局的进程编号)中,返回发送到目标进程的张量。

Ascend

mindspore.mint.distributed.reduce_scatter

规约并且分发指定通信组中的张量,返回分发后的张量。

Ascend

mindspore.mint.distributed.reduce_scatter_tensor

规约并且分发指定通信组中的张量,返回分发后的张量。

Ascend

mindspore.mint.distributed.scatter

对输入张量进行均匀散射到通信域的卡上。

Ascend

mindspore.mint.distributed.scatter_object_list

对输入Python对象列表进行均匀散射到通信域的卡上。

Ascend

mindspore.mint.distributed.send

同步发送张量到指定线程。

Ascend