PyTorch与MindSpore API映射表

查看源文件

由社区提供的PyTorch APIs和MindSpore APIs之间的映射,可能在参数、输入、输出、逻辑功能和特定场景等方面存在差异,可详见各API描述或已提供的差异对比。

也欢迎更多的MindSpore开发者参与完善映射内容。关于PyTorch与MindSpore关于框架机制差异,请参考:优化器对比随机数策略对比参数初始化对比

API映射一致标准及例外场景

API映射一致标准:API功能一致,参数个数或顺序一致,参数数据类型一致,参数默认值一致,参数名一致。同时满足所有一致条件被认为是API映射一致。

以下例外场景也被认为是API映射一致,

例外场景1:相较于API映射一致标准,仅API参数的输入数据类型支持范围不一样,包含以下3种子场景:

(1)MindSpore的API支持传入int,float,bool等类型的参数,但不支持传入int8或float64等小位宽数据类型的参数。

(2)MindSpore的API不支持传入复数类型的参数。

例外场景2:相较于MindSpore的API,PyTorch的API多出的参数是通用差异参数。通用差异参数存在的原因是PyTorch有部分参数是为性能优化等非功能性而增加的参数,MindSpore的性能优化机制与PyTorch不同。

例外场景3:如果能保证MindSpore的API在使用默认配置(或用户不配置)的情况下,能够实现与PyTorch对应API完全一致的功能,则MindSpore的API多于PyTorch的API的参数,功能不被认为是差异。

例外场景4:MindSpore将API中与PyTorch重载机制相关参数的默认值设置为None,PyTorch对应API的相应参数无默认值。

下面是例外场景4的举例, 在PyTorch 2.1中,torch.argmax具有两种API重载形式,分别是torch.argmax(input)和torch.argmax(input, dim, keepdim=False),其中torch.argmax(input)返回输入Tensor中的最大值元素的索引,torch.argmax(input, dim, keepdim=False)返回输入Tensor在指定轴上最大值的索引。

mindspore.mint.argmax只有一种API形式,即mindspore.mint.argmax(input, dim=None, keepdim=False),但mindspore.mint.argmax(input)与torch.argmax(input)功能相同,mindspore.mint.argmax(input, dim, keepdim)与torch.argmax(input, dim, keepdim)功能相同。相较于torch.argmax,mindspore.mint.argmax参数dim的默认值被设置为None,仅是为了适配torch.argmax的两种API重载形式,因此例外场景4也被认为是API映射一致。

通用差异参数表

因为框架机制原因,MindSpore不提供PyTorch的以下参数:

参数名

功能

说明

out

表示输出的Tensor

把运算结果赋值给out参数,MindSpore目前无此机制

layout

表示内存分布策略

PyTorch支持torch.strided和torch.sparse_coo两种模式, MindSpore目前无此机制

device

表示Tensor存放位置

包含设备类型及可选设备号,MindSpore目前支持算子或网络级别的设备调度

requires_grad

表示是否更新梯度

MindSpore中可以通过Parameter.requires_grad控制

pin_memory

表示是否使用锁页内存

MindSpore目前无此机制

memory_format

表示Tensor的内存格式

MindSpore目前无此机制

stable

表示是否稳定排序

一般用在排序算法的API中,MindSpore目前无此功能

sparse_grad

表示是否对梯度稀疏化

MindSpore目前无此机制

size_average

PyTorch废弃参数

MindSpore中可以使用reduction参数替代

reduce

PyTorch废弃参数

MindSpore中可以使用reduction参数替代

torch

PyTorch 2.1 APIs

MindSpore APIs

说明

torch.abs

mindspore.mint.abs

一致

torch.acos

mindspore.mint.acos

一致

torch.acosh

mindspore.mint.acosh

一致

torch.add

mindspore.mint.add

一致

torch.addbmm

mindspore.mint.addbmm

一致

torch.addmm

mindspore.mint.addmm

一致

torch.addmv

mindspore.mint.addmv

一致

torch.all

mindspore.mint.all

一致

torch.allclose

mindspore.mint.allclose

一致

torch.amax

mindspore.mint.amax

功能一致,参数dim默认值不同

torch.amin

mindspore.mint.amin

功能一致,参数dim默认值不同

torch.any

mindspore.mint.any

一致

torch.arange

mindspore.mint.arange

功能一致,参数end默认值不同

torch.arccos

mindspore.mint.arccos

一致

torch.arccosh

mindspore.mint.arccosh

一致

torch.arcsin

mindspore.mint.arcsin

功能一致,参数名不一致

torch.arcsinh

mindspore.mint.arcsinh

一致

torch.arctan

mindspore.mint.arctan

一致

torch.arctan2

mindspore.mint.arctan2

一致

torch.arctanh

mindspore.mint.arctanh

一致

torch.argmax

mindspore.mint.argmax

一致

torch.argmin

mindspore.mint.argmin

一致

torch.argsort

mindspore.mint.argsort

一致

torch.asin

mindspore.mint.asin

一致

torch.asinh

mindspore.mint.asinh

一致

torch.atan

mindspore.mint.atan

一致

torch.atan2

mindspore.mint.atan2

一致

torch.atanh

mindspore.mint.atanh

一致

torch.baddbmm

mindspore.mint.baddbmm

一致

torch.bernoulli

mindspore.mint.bernoulli

一致

torch.bincount

mindspore.mint.bincount

一致

torch.bitwise_and

mindspore.mint.bitwise_and

一致

torch.bitwise_or

mindspore.mint.bitwise_or

一致

torch.bitwise_xor

mindspore.mint.bitwise_xor

一致

torch.bmm

mindspore.mint.bmm

一致

torch.broadcast_to

mindspore.mint.broadcast_to

一致

torch.cat

mindspore.mint.cat

一致

torch.cdist

mindspore.mint.cdist

一致

torch.chunk

mindspore.mint.chunk

一致

torch.ceil

mindspore.mint.ceil

一致

torch.clamp

mindspore.mint.clamp

一致

torch.clone

mindspore.mint.clone

一致

torch.concat

mindspore.mint.concat

一致

torch.count_nonzero

mindspore.mint.count_nonzero

一致

torch.cos

mindspore.mint.cos

一致

torch.cosh

mindspore.mint.cosh

一致

torch.cross

mindspore.mint.cross

一致

torch.cummax

mindspore.mint.cummax

一致

torch.cummin

mindspore.mint.cummin

一致

torch.cumprod

mindspore.mint.cumprod

一致

torch.cumsum

mindspore.mint.cumsum

一致

torch.diff

mindspore.mint.diff

一致

torch.div

mindspore.mint.div

一致

torch.divide

mindspore.mint.divide

一致

torch.dot

mindspore.mint.dot

一致

torch.einsum

mindspore.mint.einsum

一致

torch.empty

mindspore.mint.empty

一致

torch.empty_like

mindspore.mint.empty_like

一致

torch.equal

mindspore.mint.equal

一致

torch.eq

mindspore.mint.eq

一致

torch.erf

mindspore.mint.erf

一致

torch.erfc

mindspore.mint.erfc

一致

torch.erfinv

mindspore.mint.erfinv

一致

torch.exp

mindspore.mint.exp

一致

torch.exp2

mindspore.mint.exp2

一致

torch.expm1

mindspore.mint.expm1

一致

torch.eye

mindspore.mint.eye

一致

torch.float_power

mindspore.mint.float_power

一致

torch.flatten

mindspore.mint.flatten

一致

torch.flip

mindspore.mint.flip

一致

torch.floor

mindspore.mint.floor

一致

torch.fmod

mindspore.mint.fmod

一致

torch.frac

mindspore.mint.frac

一致

torch.full

mindspore.mint.full

一致

torch.full_like

mindspore.mint.full_like

一致

torch.gather

mindspore.mint.gather

一致

torch.greater

mindspore.mint.greater

一致

torch.greater_equal

mindspore.mint.greater_equal

一致

torch.gt

mindspore.mint.gt

一致

torch.histc

mindspore.mint.histc

一致

torch.index_select

mindspore.mint.index_select

一致

torch.inverse

mindspore.mint.inverse

一致

torch.isclose

mindspore.mint.isclose

一致

torch.isfinite

mindspore.mint.isfinite

一致

torch.isinf

mindspore.mint.isinf

一致

torch.isneginf

mindspore.mint.isneginf

一致

torch.le

mindspore.mint.le

一致

torch.lerp

mindspore.mint.lerp

一致

torch.less

mindspore.mint.less

一致

torch.less_equal

mindspore.mint.less_equal

一致

torch.linspace

mindspore.mint.linspace

一致

torch.log

mindspore.mint.log

一致

torch.log2

mindspore.mint.log2

一致

torch.log10

mindspore.mint.log10

一致

torch.logaddexp

mindspore.mint.logaddexp

一致

torch.logsumexp

mindspore.mint.logsumexp

一致

torch.log1p

mindspore.mint.log1p

一致

torch.logical_and

mindspore.mint.logical_and

一致

torch.logical_not

mindspore.mint.logical_not

一致

torch.logical_or

mindspore.mint.logical_or

一致

torch.logical_xor

mindspore.mint.logical_xor

一致

torch.lt

mindspore.mint.lt

一致

torch.masked_select

mindspore.mint.masked_select

一致

torch.matmul

mindspore.mint.matmul

一致

torch.max

mindspore.mint.max

一致

torch.maximum

mindspore.mint.maximum

一致

torch.mean

mindspore.mint.mean

一致

torch.median

mindspore.mint.median

功能一致,MindSpore多dim和keepdim两个参数

torch.meshgrid

mindspore.mint.meshgrid

功能一致,参数indexing默认值不同

torch.mul

mindspore.mint.mul

一致

torch.min

mindspore.mint.min

一致

torch.minimum

mindspore.mint.minimum

一致

torch.mm

mindspore.mint.mm

一致

torch.multinomial

mindspore.mint.multinomial

一致

torch.mv

mindspore.mint.mv

一致

torch.nansum

mindspore.mint.nansum

功能一致,参数列表不一致

torch.nan_to_num

mindspore.mint.nan_to_num

一致

torch.narrow

mindspore.mint.narrow

一致

torch.ne

mindspore.mint.ne

一致

torch.neg

mindspore.mint.neg

一致

torch.negative

mindspore.mint.negative

一致

torch.nonzero

mindspore.mint.nonzero

一致

torch.normal

mindspore.mint.normal

接口重载的参数不同

torch.norm

mindspore.mint.norm

一致

torch.ones

mindspore.mint.ones

一致

torch.ones_like

mindspore.mint.ones_like

一致

torch.outer

mindspore.mint.outer

一致

torch.permute

mindspore.mint.permute

一致

torch.polar

mindspore.mint.polar

一致

torch.pow

mindspore.mint.pow

一致

torch.prod

mindspore.mint.prod

一致

torch.rand

mindspore.mint.rand

一致

torch.rand_like

mindspore.mint.rand_like

一致

torch.randint

mindspore.mint.randint

一致

torch.randint_like

mindspore.mint.randint_like

功能一致,参数low默认值不同

torch.randn

mindspore.mint.randn

一致

torch.randn_like

mindspore.mint.randn_like

一致

torch.randperm

mindspore.mint.randperm

一致

torch.ravel

mindspore.mint.ravel

一致

torch.reciprocal

mindspore.mint.reciprocal

一致

torch.remainder

mindspore.mint.remainder

一致

torch.repeat_interleave

mindspore.mint.repeat_interleave

功能一致,PyTorch涉及重载

torch.reshape

mindspore.mint.reshape

一致

torch.roll

mindspore.mint.roll

一致

torch.round

mindspore.mint.round

一致

torch.rsqrt

mindspore.mint.rsqrt

一致

torch.scatter

mindspore.mint.scatter

一致

torch.scatter_add

mindspore.mint.scatter_add

一致

torch.searchsorted

mindspore.mint.searchsorted

功能一致,参数side默认值不同

torch.select

mindspore.mint.select

一致

torch.sigmoid

mindspore.mint.sigmoid

一致

torch.sign

mindspore.mint.sign

一致

torch.sin

mindspore.mint.sin

一致

torch.sinc

mindspore.mint.sinc

一致

torch.sinh

mindspore.mint.sinh

一致

torch.sort

mindspore.mint.sort

一致

torch.split

mindspore.mint.split

一致

torch.sqrt

mindspore.mint.sqrt

一致

torch.square

mindspore.mint.square

一致

torch.squeeze

mindspore.mint.squeeze

一致

torch.stack

mindspore.mint.stack

一致

torch.std

mindspore.mint.std

一致

torch.std_mean

mindspore.mint.std_mean

一致

torch.sub

mindspore.mint.sub

一致

torch.sum

mindspore.mint.sum

一致

torch.swapaxes

mindspore.mint.swapaxes

一致

torch.t

mindspore.mint.t

一致

torch.tan

mindspore.mint.tan

一致

torch.tanh

mindspore.mint.tanh

一致

torch.tile

mindspore.mint.tile

一致

torch.topk

mindspore.mint.topk

功能一致,参数dim默认值不同

torch.trace

mindspore.mint.trace

一致

torch.transpose

mindspore.mint.transpose

一致

torch.tril

mindspore.mint.tril

一致

torch.triu

mindspore.mint.triu

一致

torch.trunc

mindspore.mint.trunc

一致

torch.unbind

mindspore.mint.unbind

一致

torch.unique

mindspore.mint.unique

一致

torch.unique_consecutive

mindspore.mint.unique_consecutive

一致

torch.unsqueeze

mindspore.mint.unsqueeze

一致

torch.var

mindspore.mint.var

一致

torch.var_mean

mindspore.mint.var_mean

一致

torch.where

mindspore.mint.where

一致

torch.xlogy

mindspore.mint.xlogy

一致

torch.zeros

mindspore.mint.zeros

一致

torch.zeros_like

mindspore.mint.zeros_like

一致

torch.linalg

PyTorch 2.1 APIs

MindSpore APIs

说明

torch.linalg.inv

mindspore.mint.linalg.inv

一致

torch.linalg.matrix_norm

mindspore.mint.linalg.matrix_norm

一致

torch.linalg.norm

mindspore.mint.linalg.norm

一致

torch.linalg.vector_norm

mindspore.mint.linalg.vector_norm

一致

torch.distributed

PyTorch 2.1 APIs

MindSpore APIs

说明

torch.distributed.P2POp

mindspore.mint.distributed.P2POp

一致

torch.distributed.all_gather

mindspore.mint.distributed.all_gather

一致

torch.distributed.all_gather_into_tensor

mindspore.mint.distributed.all_gather_into_tensor

一致

torch.distributed.all_gather_object

mindspore.mint.distributed.all_gather_object

一致

torch.distributed.all_reduce

mindspore.mint.distributed.all_reduce

一致

torch.distributed.all_to_all_single

mindspore.mint.distributed.all_to_all_single

一致

torch.distributed.all_to_all

mindspore.mint.distributed.all_to_all

一致

torch.distributed.barrier

mindspore.mint.distributed.barrier

一致

torch.distributed.batch_isend_irecv

mindspore.mint.distributed.batch_isend_irecv

一致

torch.distributed.broadcast

mindspore.mint.distributed.broadcast

一致

torch.distributed.broadcast_object_list

mindspore.mint.distributed.broadcast_object_list

一致

mindspore.mint.distributed.destroy_process_group

MindSpore独有

torch.distributed.gather

mindspore.mint.distributed.gather

一致

torch.distributed.gather_object

mindspore.mint.distributed.gather_object

一致

torch.distributed.get_backend

mindspore.mint.distributed.get_backend

一致

torch.distributed.get_global_rank

mindspore.mint.distributed.get_global_rank

一致

torch.distributed.get_group_rank

mindspore.mint.distributed.get_group_rank

一致

torch.distributed.get_process_group_ranks

mindspore.mint.distributed.get_process_group_ranks

一致

torch.distributed.get_rank

mindspore.mint.distributed.get_rank

一致

torch.distributed.get_world_size

mindspore.mint.distributed.get_world_size

一致

torch.distributed.init_process_group

mindspore.mint.distributed.init_process_group

功能一致,参数名不一致

torch.distributed.irecv

mindspore.mint.distributed.irecv

一致

torch.distributed.isend

mindspore.mint.distributed.isend

一致

torch.distributed.new_group

mindspore.mint.distributed.new_group

MindSpore多参数group_desc=None

torch.distributed.recv

mindspore.mint.distributed.recv

一致

torch.distributed.reduce

mindspore.mint.distributed.reduce

一致

torch.distributed.reduce_scatter

mindspore.mint.distributed.reduce_scatter

一致

torch.distributed.reduce_scatter_tensor

mindspore.mint.distributed.reduce_scatter_tensor

一致

torch.distributed.scatter

mindspore.mint.distributed.scatter

功能一致,参数scatter_list默认值不同

torch.distributed.scatter_object_list

mindspore.mint.distributed.scatter_object_list

一致

torch.distributed.send

mindspore.mint.distributed.send

一致

torch.nn

PyTorch 2.1 APIs

MindSpore APIs

说明

torch.nn.AdaptiveAvgPool1d

mindspore.mint.nn.AdaptiveAvgPool1d

一致

torch.nn.AdaptiveAvgPool2d

mindspore.mint.nn.AdaptiveAvgPool2d

一致

torch.nn.AdaptiveAvgPool3d

mindspore.mint.nn.AdaptiveAvgPool3d

一致

torch.nn.AvgPool2d

mindspore.mint.nn.AvgPool2d

一致

torch.nn.BCELoss

mindspore.mint.nn.BCELoss

一致

torch.nn.BCEWithLogitsLoss

mindspore.mint.nn.BCEWithLogitsLoss

一致

torch.nn.BatchNorm1d

mindspore.mint.nn.BatchNorm1d

一致

torch.nn.BatchNorm2d

mindspore.mint.nn.BatchNorm2d

一致

torch.nn.BatchNorm3d

mindspore.mint.nn.BatchNorm3d

一致

torch.nn.ConstantPad1d

mindspore.mint.nn.ConstantPad1d

一致

torch.nn.ConstantPad2d

mindspore.mint.nn.ConstantPad2d

一致

torch.nn.ConstantPad3d

mindspore.mint.nn.ConstantPad3d

一致

torch.nn.Conv2d

mindspore.mint.nn.Conv2d

一致

torch.nn.Conv3d

mindspore.mint.nn.Conv3d

一致

torch.nn.ConvTranspose2d

mindspore.mint.nn.ConvTranspose2d

一致

torch.nn.CrossEntropyLoss

mindspore.mint.nn.CrossEntropyLoss

一致

torch.nn.Dropout

mindspore.mint.nn.Dropout

一致

torch.nn.Dropout2d

mindspore.mint.nn.Dropout2d

功能一致,MindSpore不含参数inplace

torch.nn.ELU

mindspore.mint.nn.ELU

功能一致,MindSpore不含参数inplace

torch.nn.Embedding

mindspore.mint.nn.Embedding

一致

torch.nn.Flatten

mindspore.mint.flatten

一致

torch.nn.Fold

mindspore.mint.nn.Fold

一致

torch.nn.GELU

mindspore.mint.nn.GELU

一致

torch.nn.GroupNorm

mindspore.mint.nn.GroupNorm

一致

torch.nn.Hardshrink

mindspore.mint.nn.Hardshrink

一致

torch.nn.Hardsigmoid

mindspore.mint.nn.Hardsigmoid

一致

torch.nn.Hardswish

mindspore.mint.nn.Hardswish

一致

torch.nn.Identity

mindspore.mint.nn.Identity

一致

torch.nn.L1Loss

mindspore.mint.nn.L1Loss

一致

torch.nn.LayerNorm

mindspore.mint.nn.LayerNorm

一致

torch.nn.Linear

mindspore.mint.nn.Linear

功能一致,MindSpore多weight_init=None和bias_init=None两个参数

torch.nn.LogSigmoid

mindspore.mint.nn.LogSigmoid

一致

torch.nn.LogSoftMax

mindspore.mint.nn.LogSoftmax

一致

torch.nn.MSELoss

mindspore.mint.nn.MSELoss

一致

torch.nn.MaxUnpool2d

mindspore.mint.nn.MaxUnpool2d

一致

torch.nn.Mish

mindspore.mint.nn.Mish

一致

torch.nn.NLLLoss

mindspore.mint.nn.NLLLoss

一致

torch.nn.PReLU

mindspore.mint.nn.PReLU

一致

torch.nn.ReLU

mindspore.mint.nn.ReLU

一致

torch.nn.ReLU6

mindspore.mint.nn.ReLU6

一致

torch.nn.ReflectionPad1d

mindspore.mint.nn.ReflectionPad1d

一致

torch.nn.ReflectionPad2d

mindspore.mint.nn.ReflectionPad2d

一致

torch.nn.ReflectionPad3d

mindspore.mint.nn.ReflectionPad3d

一致

torch.nn.ReplicationPad1d

mindspore.mint.nn.ReplicationPad1d

一致

torch.nn.ReplicationPad2d

mindspore.mint.nn.ReplicationPad2d

一致

torch.nn.ReplicationPad3d

mindspore.mint.nn.ReplicationPad3d

一致

torch.nn.SeLU

mindspore.mint.nn.SELU

一致

torch.nn.SiLU

mindspore.mint.nn.SiLU

一致

torch.nn.SmoothL1Loss

mindspore.mint.nn.SmoothL1Loss

一致

torch.nn.Softmax

mindspore.mint.nn.Softmax

一致

torch.nn.Softshrink

mindspore.mint.nn.Softshrink

一致

torch.nn.SyncBatchNorm

mindspore.mint.nn.SyncBatchNorm

一致

torch.nn.Tanh

mindspore.mint.nn.Tanh

一致

torch.nn.Unfold

mindspore.mint.nn.Unfold

一致

torch.nn.Upsample

mindspore.mint.nn.Upsample

一致

torch.nn.ZeroPad1d

mindspore.mint.nn.ZeroPad1d

一致

torch.nn.ZeroPad2d

mindspore.mint.nn.ZeroPad2d

一致

torch.nn.ZeroPad3d

mindspore.mint.nn.ZeroPad3d

一致

torch.nn.functional

PyTorch 2.1 APIs

MindSpore APIs

说明

torch.nn.functional.adaptive_avg_pool1d

mindspore.mint.nn.functional.adaptive_avg_pool1d

一致

torch.nn.functional.adaptive_avg_pool2d

mindspore.mint.nn.functional.adaptive_avg_pool2d

一致

torch.nn.functional.avg_pool1d

mindspore.mint.nn.functional.avg_pool1d

一致

torch.nn.functional.avg_pool2d

mindspore.mint.nn.functional.avg_pool2d

一致

torch.nn.functional.batch_norm

mindspore.mint.nn.functional.batch_norm

一致

torch.nn.functional.binary_cross_entropy

mindspore.mint.nn.functional.binary_cross_entropy

一致

torch.nn.functional.binary_cross_entropy_with_logits

mindspore.mint.nn.functional.binary_cross_entropy_with_logits

一致

torch.nn.functional.conv2d

mindspore.mint.nn.functional.conv2d

一致

torch.nn.functional.conv3d

mindspore.mint.nn.functional.conv3d

一致

torch.nn.functional.conv_transpose2d

mindspore.mint.nn.functional.conv_transpose2d

一致

torch.nn.functional.dropout

mindspore.mint.nn.functional.dropout

一致

torch.nn.functional.dropout2d

mindspore.mint.nn.functional.dropout2d

功能一致,MindSpore不含参数inplace

torch.nn.functional.elu

mindspore.mint.nn.functional.elu

功能一致,MindSpore不含参数inplace

torch.nn.functional.embedding

mindspore.mint.nn.functional.embedding

功能一致,MindSpore不含参数sparse

torch.nn.functional.fold

mindspore.mint.nn.functional.fold

一致

torch.nn.functional.gelu

mindspore.mint.nn.functional.gelu

一致

torch.nn.functional.grid_sample

mindspore.mint.nn.functional.grid_sample

功能一致,参数align_corners默认值不同

torch.nn.functional.hardshrink

mindspore.mint.nn.functional.hardshrink

一致

torch.nn.functional.hardsigmoid

mindspore.mint.nn.functional.hardsigmoid

功能一致,MindSpore不含参数inplace

torch.nn.functional.hardswish

mindspore.mint.nn.functional.hardswish

功能一致,MindSpore不含参数inplace

torch.nn.functional.interpolate

mindspore.mint.nn.functional.interpolate

功能一致,MindSpore不含参数antialias

torch.nn.functional.l1_loss

mindspore.mint.nn.functional.l1_loss

一致

torch.nn.functional.leaky_relu

mindspore.mint.nn.functional.leaky_relu

功能一致,MindSpore不含参数inplace

torch.nn.functional.linear

mindspore.mint.nn.functional.linear

一致

torch.nn.functional.log_softmax

mindspore.mint.nn.functional.log_softmax

一致

torch.nn.functional.logsigmoid

mindspore.mint.nn.functional.logsigmoid

一致

torch.nn.functional.max_pool2d

mindspore.mint.nn.functional.max_pool2d

一致

torch.nn.functional.max_unpool2d

mindspore.mint.nn.functional.max_unpool2d

一致

torch.nn.functional.mish

mindspore.mint.nn.functional.mish

功能一致,MindSpore不含参数inplace

torch.nn.functional.mse_loss

mindspore.mint.nn.functional.mse_loss

一致

torch.nn.functional.nll_loss

mindspore.mint.nn.functional.nll_loss

一致

torch.nn.functional.normalize

mindspore.mint.nn.functional.normalize

一致

torch.nn.functional.one_hot

mindspore.mint.nn.functional.one_hot

一致

torch.nn.functional.pad

mindspore.mint.nn.functional.pad

一致

torch.nn.functional.prelu

mindspore.mint.nn.functional.prelu

一致

torch.nn.functional.relu

mindspore.mint.nn.functional.relu

一致

torch.nn.functional.relu6

mindspore.mint.nn.functional.relu6

一致

torch.nn.functional.relu_

mindspore.mint.nn.functional.relu_

一致

torch.nn.functional.selu

mindspore.mint.nn.functional.selu

功能一致,MindSpore不含参数inplace

torch.nn.functional.sigmoid

mindspore.mint.nn.functional.sigmoid

一致

torch.nn.functional.silu

mindspore.mint.nn.functional.silu

功能一致,MindSpore不含参数inplace

torch.nn.functional.smooth_l1_loss

mindspore.mint.nn.functional.smooth_l1_loss

一致

torch.nn.functional.softmax

mindspore.mint.nn.functional.softmax

一致

torch.nn.functional.softplus

mindspore.mint.nn.functional.softplus

一致

torch.nn.functional.softshrink

mindspore.mint.nn.functional.softshrink

一致

torch.nn.functional.tanh

mindspore.mint.nn.functional.tanh

一致

torch.nn.functional.unfold

mindspore.mint.nn.functional.unfold

一致

torch.special

PyTorch 2.1 APIs

MindSpore APIs

说明

torch.special.erfc

mindspore.mint.special.erfc

一致

torch.special.exp2

mindspore.mint.special.exp2

一致

torch.special.expm1

mindspore.mint.special.expm1

一致

torch.special.log1p

mindspore.mint.special.log1p

一致

torch.special.log_softmax

mindspore.mint.special.log_softmax

一致

torch.special.round

mindspore.mint.special.round

一致

torch.special.sinc

mindspore.mint.special.sinc

一致

torch.Tensor

PyTorch 2.1 APIs

MindSpore APIs

说明

torch.Tensor.abs

mindspore.Tensor.abs

一致

torch.Tensor.absolute

mindspore.Tensor.absolute

一致

torch.Tensor.add

mindspore.Tensor.add

一致

torch.Tensor.all

mindspore.Tensor.all

一致

torch.Tensor.any

mindspore.Tensor.any

一致

torch.Tensor.argmax

mindspore.Tensor.argmax

一致

torch.Tensor.arctan2

mindspore.Tensor.arctan2

一致

torch.Tensor.argmin

mindspore.Tensor.argmin

一致

torch.Tensor.atan2

mindspore.Tensor.atan2

一致

torch.Tensor.bool

mindspore.Tensor.bool

一致

torch.Tensor.ceil

mindspore.Tensor.ceil

一致

torch.Tensor.chunk

mindspore.Tensor.chunk

一致

torch.Tensor.clamp

mindspore.Tensor.clamp

一致

torch.Tensor.clamp_

mindspore.Tensor.clamp_

一致

torch.Tensor.clip

mindspore.Tensor.clip

一致

torch.Tensor.cos

mindspore.Tensor.cos

一致

torch.Tensor.cumsum

mindspore.Tensor.cumsum

一致

torch.Tensor.div

mindspore.Tensor.div

一致

torch.Tensor.divide

mindspore.Tensor.divide

一致

torch.Tensor.eq

mindspore.Tensor.eq

一致

torch.Tensor.erf

mindspore.Tensor.erf

一致

torch.Tensor.exp

mindspore.Tensor.exp

一致

torch.Tensor.expand_as

mindspore.Tensor.expand_as

一致

torch.Tensor.flatten

mindspore.Tensor.flatten

一致

torch.Tensor.float

mindspore.Tensor.float

一致

torch.Tensor.floor

mindspore.Tensor.floor

一致

torch.Tensor.gather

mindspore.Tensor.gather

一致

torch.Tensor.greater

mindspore.Tensor.greater

一致

torch.Tensor.gt

mindspore.Tensor.gt

一致

torch.Tensor.half

mindspore.Tensor.half

一致

torch.Tensor.index_select

mindspore.Tensor.index_select

一致

torch.Tensor.int

mindspore.Tensor.int

一致

torch.Tensor.isfinite

mindspore.Tensor.isfinite

一致

torch.Tensor.isnan

mindspore.Tensor.isnan

一致

torch.Tensor.item

mindspore.Tensor.item

一致

torch.Tensor.le

mindspore.Tensor.le

一致

torch.Tensor.less

mindspore.Tensor.less

一致

torch.Tensor.less_equal

mindspore.Tensor.less_equal

一致

torch.Tensor.log

mindspore.Tensor.log

一致

torch.Tensor.logical_and

mindspore.Tensor.logical_and

一致

torch.Tensor.logical_not

mindspore.Tensor.logical_not

一致

torch.Tensor.logical_or

mindspore.Tensor.logical_or

一致

torch.Tensor.long

mindspore.Tensor.long

一致

torch.Tensor.lt

mindspore.Tensor.lt

一致

torch.Tensor.masked_fill

mindspore.Tensor.masked_fill

一致

torch.Tensor.masked_select

mindspore.Tensor.masked_select

一致

torch.Tensor.matmul

mindspore.Tensor.matmul

一致

torch.Tensor.max

mindspore.Tensor.max

一致

torch.Tensor.maximum

mindspore.Tensor.maximum

一致

torch.Tensor.mean

mindspore.Tensor.mean

一致

torch.Tensor.min

mindspore.Tensor.min

一致

torch.Tensor.minimum

mindspore.Tensor.minimum

一致

torch.Tensor.mul

mindspore.Tensor.mul

一致

torch.Tensor.nan_to_num

mindspore.Tensor.nan_to_num

一致

torch.Tensor.ne

mindspore.Tensor.ne

一致

torch.Tensor.neg

mindspore.Tensor.neg

一致

torch.Tensor.negative

mindspore.Tensor.negative

一致

torch.Tensor.not_equal

mindspore.Tensor.not_equal

一致

torch.Tensor.pow

mindspore.Tensor.pow

一致

torch.Tensor.prod

mindspore.Tensor.prod

一致

torch.Tensor.reciprocal

mindspore.Tensor.reciprocal

一致

torch.Tensor.remainder

mindspore.Tensor.remainder

一致

torch.Tensor.repeat_interleave

mindspore.Tensor.repeat_interleave

一致

torch.Tensor.reshape

mindspore.Tensor.reshape

一致

torch.Tensor.round

mindspore.Tensor.round

一致

torch.Tensor.rsqrt

mindspore.Tensor.rsqrt

一致

torch.Tensor.scatter

mindspore.Tensor.scatter

一致

torch.Tensor.scatter_add

mindspore.Tensor.scatter_add

一致

torch.Tensor.sigmoid

mindspore.Tensor.sigmoid

一致

torch.Tensor.sin

mindspore.Tensor.sin

一致

torch.Tensor.sort

mindspore.Tensor.sort

一致

torch.Tensor.split

mindspore.Tensor.split

一致

torch.Tensor.sqrt

mindspore.Tensor.sqrt

一致

torch.Tensor.square

mindspore.Tensor.square

一致

torch.Tensor.sub

mindspore.Tensor.sub

一致

torch.Tensor.sum

mindspore.Tensor.sum

一致

torch.Tensor.t

mindspore.Tensor.t

一致

torch.Tensor.tanh

mindspore.Tensor.tanh

一致

torch.Tensor.tile

mindspore.Tensor.tile

一致

torch.Tensor.topk

mindspore.Tensor.topk

一致

torch.Tensor.tril

mindspore.Tensor.tril

一致

torch.Tensor.trunc

mindspore.Tensor.trunc

一致

torch.Tensor.view_as

mindspore.Tensor.view_as

一致

torch.Tensor.where

mindspore.Tensor.where

一致

torch.optim

PyTorch 2.1 APIs

MindSpore APIs

说明

torch.optim.Adam

mindspore.mint.optim.Adam

功能一致,PyTorch多一些优化参数

torch.optim.AdamW

mindspore.mint.optim.AdamW

功能一致,PyTorch多一些优化参数

torch.utils

PyTorch 1.8.1 APIs

MindSpore APIs

说明

torch.utils.data.DataLoader

mindspore.dataset.GeneratorDataset

差异对比

torch.utils.data.distributed.DistributedSampler

mindspore.dataset.DistributedSampler

差异对比

torch.utils.data.RandomSampler

mindspore.dataset.RandomSampler

差异对比

torch.utils.data.SequentialSampler

mindspore.dataset.SequentialSampler

差异对比

torch.utils.data.SubsetRandomSampler

mindspore.dataset.SubsetRandomSampler

差异对比

torch.utils.data.WeightedRandomSampler

mindspore.dataset.WeightedRandomSampler

差异对比

torch.utils.checkpoint.checkpoint

mindspore.nn.Cell.recompute

差异对比

torchaudio

当前API映射表对应的PyTorch版本是1.8.1,Python版本不高于Python 3.9。

TorchAudio 0.8.1 APIs

MindSpore APIs

说明

torchaudio.datasets.CMUARCTIC

mindspore.dataset.CMUArcticDataset

差异对比

torchaudio.datasets.GTZAN

mindspore.dataset.GTZANDataset

差异对比

torchaudio.datasets.LIBRITTS

mindspore.dataset.LibriTTSDataset

差异对比

torchaudio.datasets.LJSPEECH

mindspore.dataset.LJSpeechDataset

差异对比

torchaudio.datasets.SPEECHCOMMANDS

mindspore.dataset.SpeechCommandsDataset

差异对比

torchaudio.datasets.TEDLIUM

mindspore.dataset.TedliumDataset

差异对比

torchaudio.datasets.YESNO

mindspore.dataset.YesNoDataset

差异对比

torchaudio.transforms.AmplitudeToDB

mindspore.dataset.audio.AmplitudeToDB

差异对比

torchaudio.transforms.ComplexNorm

mindspore.dataset.audio.ComplexNorm

一致

torchaudio.transforms.ComputeDeltas

mindspore.dataset.audio.ComputeDeltas

功能一致,参数名不同

torchaudio.transforms.Fade

mindspore.dataset.audio.Fade

一致

torchaudio.transforms.FrequencyMasking

mindspore.dataset.audio.FrequencyMasking

差异对比

torchaudio.transforms.GriffinLim

mindspore.dataset.audio.GriffinLim

差异对比

torchaudio.transforms.InverseMelScale

mindspore.dataset.audio.InverseMelScale

差异对比

torchaudio.transforms.MelScale

mindspore.dataset.audio.MelScale

差异对比

torchaudio.transforms.MelSpectrogram

mindspore.dataset.audio.MelSpectrogram

差异对比

torchaudio.transforms.MFCC

mindspore.dataset.audio.MFCC

一致

torchaudio.transforms.MuLawEncoding

mindspore.dataset.audio.MuLawEncoding

一致

torchaudio.transforms.MuLawDecoding

mindspore.dataset.audio.MuLawDecoding

一致

torchaudio.transforms.Resample

mindspore.dataset.audio.Resample

差异对比

torchaudio.transforms.SlidingWindowCmn

mindspore.dataset.audio.SlidingWindowCmn

一致

torchaudio.transforms.SpectralCentroid

mindspore.dataset.audio.SpectralCentroid

差异对比

torchaudio.transforms.Spectrogram

mindspore.dataset.audio.Spectrogram

差异对比

torchaudio.transforms.TimeMasking

mindspore.dataset.audio.TimeMasking

差异对比

torchaudio.transforms.TimeStretch

mindspore.dataset.audio.TimeStretch

一致

torchaudio.transforms.Vad

mindspore.dataset.audio.Vad

一致

torchaudio.transforms.Vol

mindspore.dataset.audio.Vol

一致

torchtext

当前API映射表对应的PyTorch版本是1.8.1,Python版本不高于Python 3.9。

TorchText 0.9.1 APIs

MindSpore APIs

说明

torchtext.data.functional.custom_replace

mindspore.dataset.text.RegexReplace

差异对比

torchtext.data.functional.load_sp_model

mindspore.dataset.text.SentencePieceTokenizer

差异对比

torchtext.data.functional.numericalize_tokens_from_iterator

mindspore.dataset.text.Lookup

差异对比

torchtext.data.functional.sentencepiece_numericalizer

mindspore.dataset.text.SentencePieceTokenizer

差异对比

torchtext.data.functional.sentencepiece_tokenizer

mindspore.dataset.text.SentencePieceTokenizer

差异对比

torchtext.data.functional.simple_space_split

mindspore.dataset.text.WhitespaceTokenizer

差异对比

torchtext.data.utils.ngrams_iterator

mindspore.dataset.text.Ngram

差异对比

torchtext.datasets.AG_NEWS

mindspore.dataset.AGNewsDataset

差异对比

torchtext.datasets.AmazonReviewFull

mindspore.dataset.AmazonReviewDataset

差异对比

torchtext.datasets.AmazonReviewPolarity

mindspore.dataset.AmazonReviewDataset

差异对比

torchtext.datasets.CoNLL2000Chunking

mindspore.dataset.CoNLL2000Dataset

差异对比

torchtext.datasets.DBpedia

mindspore.dataset.DBpediaDataset

差异对比

torchtext.datasets.IMDB

mindspore.dataset.IMDBDataset

差异对比

torchtext.datasets.IWSLT2016

mindspore.dataset.IWSLT2016Dataset

差异对比

torchtext.datasets.IWSLT2017

mindspore.dataset.IWSLT2017Dataset

差异对比

torchtext.datasets.PennTreebank

mindspore.dataset.PennTreebankDataset

差异对比

torchtext.datasets.SogouNews

mindspore.dataset.SogouNewsDataset

差异对比

torchtext.datasets.SQuAD1

mindspore.dataset.SQuADDataset

差异对比

torchtext.datasets.SQuAD2

mindspore.dataset.SQuADDataset

差异对比

torchtext.datasets.UDPOS

mindspore.dataset.UDPOSDataset

差异对比

torchtext.datasets.WikiText103

mindspore.dataset.WikiTextDataset

差异对比

torchtext.datasets.WikiText2

mindspore.dataset.WikiTextDataset

差异对比

torchtext.datasets.YahooAnswers

mindspore.dataset.YahooAnswersDataset

差异对比

torchtext.datasets.YelpReviewFull

mindspore.dataset.YelpReviewDataset

差异对比

torchtext.datasets.YelpReviewPolarity

mindspore.dataset.YelpReviewDataset

差异对比

torchvision

当前API映射表对应的PyTorch版本是1.8.1,Python版本不高于Python 3.9。

TorchVision 0.9.1 APIs

MindSpore APIs

说明

torchvision.datasets.CelebA

mindspore.dataset.CelebADataset

差异对比

torchvision.datasets.Cityscapes

mindspore.dataset.CityscapesDataset

差异对比

torchvision.datasets.CIFAR10

mindspore.dataset.Cifar10Dataset

差异对比

torchvision.datasets.CIFAR100

mindspore.dataset.Cifar100Dataset

差异对比

torchvision.datasets.CocoDetection

mindspore.dataset.CocoDataset

差异对比

torchvision.datasets.ImageFolder

mindspore.dataset.ImageFolderDataset

差异对比

torchvision.datasets.MNIST

mindspore.dataset.MnistDataset

差异对比

torchvision.datasets.VOCDetection

mindspore.dataset.VOCDataset

差异对比

torchvision.datasets.VOCSegmentation

mindspore.dataset.VOCDataset

差异对比

torchvision.ops.nms

mindspore.ops.NMSWithMask

差异对比

torchvision.ops.roi_align

mindspore.ops.ROIAlign

差异对比

torchvision.transforms.CenterCrop

mindspore.dataset.vision.CenterCrop

一致

torchvision.transforms.ColorJitter

mindspore.dataset.vision.RandomColorAdjust

一致

torchvision.transforms.Compose

mindspore.dataset.transforms.Compose

一致

torchvision.transforms.ConvertImageDtype

mindspore.dataset.transforms.TypeCast

差异对比

torchvision.transforms.FiveCrop

mindspore.dataset.vision.FiveCrop

一致

torchvision.transforms.GaussianBlur

mindspore.dataset.vision.GaussianBlur

一致

torchvision.transforms.Grayscale

mindspore.dataset.vision.Grayscale

一致

torchvision.transforms.LinearTransformation

mindspore.dataset.vision.LinearTransformation

一致

torchvision.transforms.Normalize

mindspore.dataset.vision.Normalize

差异对比

torchvision.transforms.Pad

mindspore.dataset.vision.Pad

功能一致,参数名不同

torchvision.transforms.RandomAffine

mindspore.dataset.vision.RandomAffine

差异对比

torchvision.transforms.RandomApply

mindspore.dataset.transforms.RandomApply

功能一致,参数名不同

torchvision.transforms.RandomChoice

mindspore.dataset.transforms.RandomChoice

一致

torchvision.transforms.RandomCrop

mindspore.dataset.vision.RandomCrop

功能一致,参数名不同

torchvision.transforms.RandomGrayscale

mindspore.dataset.vision.RandomGrayscale

功能一致,参数名不同

torchvision.transforms.RandomHorizontalFlip

mindspore.dataset.vision.RandomHorizontalFlip

功能一致,参数名不同

torchvision.transforms.RandomOrder

mindspore.dataset.transforms.RandomOrder

一致

torchvision.transforms.RandomPerspective

mindspore.dataset.vision.RandomPerspective

差异对比

torchvision.transforms.RandomResizedCrop

mindspore.dataset.vision.RandomResizedCrop

差异对比

torchvision.transforms.RandomRotation

mindspore.dataset.vision.RandomRotation

差异对比

torchvision.transforms.RandomVerticalFlip

mindspore.dataset.vision.RandomVerticalFlip

功能一致,参数名不同

torchvision.transforms.Resize

mindspore.dataset.vision.Resize

一致

torchvision.transforms.TenCrop

mindspore.dataset.vision.TenCrop

功能一致,参数名不同

torchvision.transforms.ToPILImage

mindspore.dataset.vision.ToPIL

差异对比

torchvision.transforms.ToTensor

mindspore.dataset.vision.ToTensor

差异对比

torchvision.ops.deform_conv2d

mindspore.ops.deformable_conv2d

差异对比