PyTorch and MindSpore API Mapping Table

View Source On Gitee

Mapping between PyTorch APIs and MindSpore APIs, which is provided by the community. There may be differences in parameters, inputs, outputs, logic functions, and specific scenarios. For details, see the description of each API or the difference comparison provided.

More MindSpore developers are also welcome to participate in improving the mapping content. For more information on the differences in framework mechanisms of PyTorch and MindSpore, see: Optimizer Comparison, Random Number Strategy Comparison, and Parameter Initialization Comparison.

API Mapping Consistency Criteria and Exceptions

API mapping consistency criteria: consistent API function, consistent number or sequence of parameters, consistent parameter data type, consistent default value, consistent parameter name. Satisfying all the consistency conditions at the same time is considered as consistent API mapping.

The API mapping is also consistent in the following exception scenarios:

Exception Scenario 1: Compared to the API mapping consistency criteria, only the input data types of API parameters are not supported in the same range, including the following 3 sub-scenarios:

(1) MindSpore API supports passing parameters of int, float, bool, but does not support passing parameters of small bit-width data types such as int8 or float64.

(2) MindSpore API does not support passing parameters of plural type.

Exception Scenario 2: Compared to MindSpore APIss, the extra parameters of PyTorch API are general difference parameters. General difference parameters exist because PyTorch has some parameters that are added for non-functionality such as performance optimization, and the performance optimization mechanism of MindSpore is different from that of PyTorch.

Exception Scenario 3: If it can be guaranteed that MindSpore API uses the default configuration (or that the user does not configure it), MindSpore API can implement the same functionality as the PyTorch API, and MindSpore API has more parameters than PyTorch API. The functionality is not considered a difference.

Exception Scenario 4: MindSpore sets the default value of the parameters related to the PyTorch overloading mechanism in the API to None, and the corresponding parameters of the PyTorch counterpart API have no default value.

The following is an example of the exception scenario 4. In PyTorch 2.1, torch.argmax has two API overloads in the form of torch.argmax(input) and torch.argmax(input, dim, keepdim=False), respectively, where torch.argmax(input) returns the index of the maximum value element in the input Tensor, and torch.argmax(input, dim, keepdim=False) returns the index of the maximum value of the input Tensor on the specified axis.

mindspore.mint.argmax has only one API form, namely mindspore.mint.argmax(input, dim=None, keepdim=False), but mindspore.mint.argmax(input) and torch.argmax(input) have the same function. mindspore.mint.argmax(input, dim, keepdim) and torch.argmax(input, dim, keepdim)have the same function. Compared to torch.argmax, the default value of mindspore.ops.argmax parameter dim is set to None only to adapt the two API overload forms of torch.argmax, so the exception scenario 4 is also considered to be consistent API mapping.

General Difference Parameter Table

Because of the framework mechanism, MindSpore does not provide the following parameters for PyTorch:

Parameter Names

Functions

Descriptions

out

Indicates the output Tensor

Assign the operation result to the out parameter, not supported in MindSpore.

layout

Indicates the memory distribution strategy

PyTorch supports torch.striped and torch.split_coo, not supported in MindSpore.

device

Indicates the Tensor storage location

Including device type and optional device number, MindSpore currently supports operator or network-level device scheduling.

requires_grad

Indicates whether to update the gradient

MindSpore can be accessed through the Parameter.requires_grad attribute to control.

pin_memory

Indicates whether to use locking page memory

Not supported in MindSpore.

memory_format

Indicates the memory format of the Tensor

Not supported in MindSpore.

stable

Indicates whether the sorting is stable

Generally used in the API of Sorting algorithm, not supported in MindSpore.

sparse_grad

Indicates whether to perform sparsification on the gradient

Not supported in MindSpore.

size_average

The deprecated parameter in PyTorch

The reduction parameter can be used instead.

reduce

The deprecated parameter in PyTorch

The reduction parameter can be used instead.

torch

PyTorch 2.1 APIs

MindSpore APIs

Descriptions

torch.abs

mindspore.mint.abs

Consistent

torch.acos

mindspore.mint.acos

Consistent

torch.acosh

mindspore.mint.acosh

Consistent

torch.add

mindspore.mint.add

Consistent

torch.addbmm

mindspore.mint.addbmm

Consistent

torch.addmm

mindspore.mint.addmm

Consistent

torch.addmm

mindspore.mint.addmv

Consistent

torch.all

mindspore.mint.all

Consistent

torch.allclose

mindspore.mint.allclose

Consistent

torch.amax

mindspore.mint.amax

The functions are consistent, but the default value of dim is different.

torch.amin

mindspore.mint.amin

The functions are consistent, but the default value of dim is different.

torch.any

mindspore.mint.any

Consistent

torch.arange

mindspore.mint.arange

The functions are consistent, but the default value of end is different.

torch.arccos

mindspore.mint.arccos

Consistent

torch.arccosh

mindspore.mint.arccosh

Consistent

torch.arcsin

mindspore.mint.arcsin

Consistent functions, inconsistent parameter names.

torch.arcsinh

mindspore.mint.arcsinh

Consistent

torch.arctan

mindspore.mint.arctan

Consistent

torch.arctan2

mindspore.mint.arctan2

Consistent

torch.arctanh

mindspore.mint.arctanh

Consistent

torch.argmax

mindspore.mint.argmax

Consistent

torch.argmin

mindspore.mint.argmin

Consistent

torch.argsort

mindspore.mint.argsort

Consistent

torch.asin

mindspore.mint.asin

Consistent

torch.asinh

mindspore.mint.asinh

Consistent

torch.atan

mindspore.mint.atan

Consistent

torch.atan2

mindspore.mint.atan2

Consistent

torch.atanh

mindspore.mint.atanh

Consistent

torch.baddbmm

mindspore.mint.baddbmm

Consistent

torch.bernoulli

mindspore.mint.bernoulli

Consistent

torch.bincount

mindspore.mint.bincount

Consistent

torch.bitwise_and

mindspore.mint.bitwise_and

Consistent

torch.bitwise_or

mindspore.mint.bitwise_or

Consistent

torch.bitwise_xor

mindspore.mint.bitwise_xor

Consistent

torch.bmm

mindspore.mint.bmm

Consistent

torch.broadcast_to

mindspore.mint.broadcast_to

Consistent

torch.cat

mindspore.mint.cat

Consistent

torch.cdist

mindspore.mint.cdist

Consistent

torch.chunk

mindspore.mint.chunk

Consistent

torch.ceil

mindspore.mint.ceil

Consistent

torch.clamp

mindspore.mint.clamp

Consistent

torch.clone

mindspore.mint.clone

Consistent

torch.concat

mindspore.mint.concat

Consistent

torch.count_nonzero

mindspore.mint.count_nonzero

Consistent

torch.cos

mindspore.mint.cos

Consistent

torch.cosh

mindspore.mint.cosh

Consistent

torch.cross

mindspore.mint.cross

Consistent

torch.cummax

mindspore.mint.cummax

Consistent

torch.cummin

mindspore.mint.cummin

Consistent

torch.cumprod

mindspore.mint.cumprod

Consistent

torch.cumsum

mindspore.mint.cumsum

Consistent

torch.diff

mindspore.mint.diff

Consistent

torch.div

mindspore.mint.div

Consistent

torch.divide

mindspore.mint.divide

Consistent

torch.dot

mindspore.mint.dot

Consistent

torch.einsum

mindspore.mint.einsum

Consistent

torch.empty

mindspore.mint.empty

Consistent

torch.empty_like

mindspore.mint.empty_like

Consistent

torch.equal

mindspore.mint.equal

Consistent

torch.eq

mindspore.mint.eq

Consistent

torch.erf

mindspore.mint.erf

Consistent

torch.erfc

mindspore.mint.erfc

Consistent

torch.erfinv

mindspore.mint.erfinv

Consistent

torch.exp

mindspore.mint.exp

Consistent

torch.exp2

mindspore.mint.exp2

Consistent

torch.expm1

mindspore.mint.expm1

Consistent

torch.eye

mindspore.mint.eye

Consistent

torch.float_power

mindspore.mint.float_power

Consistent

torch.flatten

mindspore.mint.flatten

Consistent

torch.flip

mindspore.mint.flip

Consistent

torch.floor

mindspore.mint.floor

Consistent

torch.fmod

mindspore.mint.fmod

Consistent

torch.frac

mindspore.mint.frac

Consistent

torch.full

mindspore.mint.full

Consistent

torch.full_like

mindspore.mint.full_like

Consistent

torch.gather

mindspore.mint.gather

Consistent

torch.greater

mindspore.mint.greater

Consistent

torch.greater_equal

mindspore.mint.greater_equal

Consistent

torch.gt

mindspore.mint.gt

Consistent

torch.histc

mindspore.mint.histc

Consistent

torch.index_select

mindspore.mint.index_select

Consistent

torch.inverse

mindspore.mint.inverse

Consistent

torch.isclose

mindspore.mint.isclose

Consistent

torch.isfinite

mindspore.mint.isfinite

Consistent

torch.isinf

mindspore.mint.isinf

Consistent

torch.isneginf

mindspore.mint.isneginf

Consistent

torch.le

mindspore.mint.le

Consistent

torch.lerp

mindspore.mint.lerp

Consistent

torch.less

mindspore.mint.less

Consistent

torch.less_equal

mindspore.mint.less_equal

Consistent

torch.linspace

mindspore.mint.linspace

Consistent

torch.log

mindspore.mint.log

Consistent

torch.log2

mindspore.mint.log2

Consistent

torch.log10

mindspore.mint.log10

Consistent

torch.logaddexp

mindspore.mint.logaddexp

Consistent

torch.logsumexp

mindspore.mint.logsumexp

Consistent

torch.log1p

mindspore.mint.log1p

Consistent

torch.logical_and

mindspore.mint.logical_and

Consistent

torch.logical_not

mindspore.mint.logical_not

Consistent

torch.logical_or

mindspore.mint.logical_or

Consistent

torch.logical_xor

mindspore.mint.logical_xor

Consistent

torch.lt

mindspore.mint.lt

Consistent

torch.masked_select

mindspore.mint.masked_select

Consistent

torch.matmul

mindspore.mint.matmul

Consistent

torch.max

mindspore.mint.max

Consistent

torch.maximum

mindspore.mint.maximum

Consistent

torch.mean

mindspore.mint.mean

Consistent

torch.median

mindspore.mint.median

The functions are consistent, but the default value of dim is different.

torch.meshgrid

mindspore.mint.meshgrid

The functions are consistent, but the default value of indexing is different.

torch.mul

mindspore.mint.mul

Consistent

torch.min

mindspore.mint.min

Consistent

torch.minimum

mindspore.mint.minimum

Consistent

torch.mm

mindspore.mint.mm

Consistent

torch.multinomial

mindspore.mint.multinomial

Consistent

torch.mv

mindspore.mint.mv

Consistent

torch.nansum

mindspore.mint.nansum

The functions are consistent, but the default value of end is different.

torch.nan_to_num

mindspore.mint.nan_to_num

Consistent

torch.narrow

mindspore.mint.narrow

Consistent

torch.ne

mindspore.mint.ne

Consistent

torch.neg

mindspore.mint.neg

Consistent

torch.negative

mindspore.mint.negative

Consistent

torch.nonzero

mindspore.mint.nonzero

Consistent

torch.normal

mindspore.mint.normal

The parameters of interface overloading are different.

torch.norm

mindspore.mint.norm

Consistent

torch.ones

mindspore.mint.ones

Consistent

torch.ones_like

mindspore.mint.ones_like

Consistent

torch.outer

mindspore.mint.outer

Consistent

torch.permute

mindspore.mint.permute

Consistent

torch.polar

mindspore.mint.polar

Consistent

torch.pow

mindspore.mint.pow

Consistent

torch.prod

mindspore.mint.prod

Consistent

torch.rand

mindspore.mint.rand

Consistent

torch.rand_like

mindspore.mint.rand_like

Consistent

torch.randint

mindspore.mint.randint

Consistent

torch.randint_like

mindspore.mint.randint_like

The functions are consistent, but the default value of low is different.

torch.randn

mindspore.mint.randn

Consistent

torch.randn_like

mindspore.mint.randn_like

Consistent

torch.randperm

mindspore.mint.randperm

Consistent

torch.ravel

mindspore.mint.ravel

Consistent

torch.reciprocal

mindspore.mint.reciprocal

Consistent

torch.remainder

mindspore.mint.remainder

Consistent

torch.repeat_interleave

mindspore.mint.repeat_interleave

Consistent functions, PyTorch involves overloading.

torch.reshape

mindspore.mint.reshape

Consistent

torch.roll

mindspore.mint.roll

Consistent

torch.round

mindspore.mint.round

Consistent

torch.rsqrt

mindspore.mint.rsqrt

Consistent

torch.scatter

mindspore.mint.scatter

Consistent

torch.scatter_add

mindspore.mint.scatter_add

Consistent

torch.searchsorted

mindspore.mint.searchsorted

The functions are consistent, but the default value of side is different.

torch.select

mindspore.mint.select

Consistent

torch.sigmoid

mindspore.mint.sigmoid

Consistent

torch.sign

mindspore.mint.sign

Consistent

torch.sin

mindspore.mint.sin

Consistent

torch.sinc

mindspore.mint.sinc

Consistent

torch.sinh

mindspore.mint.sinh

Consistent

torch.sort

mindspore.mint.sort

Consistent

torch.split

mindspore.mint.split

Consistent

torch.sqrt

mindspore.mint.sqrt

Consistent

torch.square

mindspore.mint.square

Consistent

torch.squeeze

mindspore.mint.squeeze

Consistent

torch.stack

mindspore.mint.stack

Consistent

torch.std

mindspore.mint.std

Consistent

torch.std_mean

mindspore.mint.std_mean

Consistent

torch.sub

mindspore.mint.sub

Consistent

torch.sum

mindspore.mint.sum

Consistent

torch.swapaxes

mindspore.mint.swapaxes

Consistent

torch.t

mindspore.mint.t

Consistent

torch.tan

mindspore.mint.tan

Consistent

torch.tanh

mindspore.mint.tanh

Consistent

torch.tile

mindspore.mint.tile

Consistent

torch.topk

mindspore.mint.topk

The functions are consistent, but the default value of dim is different.

torch.trace

mindspore.mint.trace

Consistent

torch.transpose

mindspore.mint.transpose

Consistent

torch.tril

mindspore.mint.tril

Consistent

torch.triu

mindspore.mint.triu

Consistent

torch.trunc

mindspore.mint.trunc

Consistent

torch.unbind

mindspore.mint.unbind

Consistent

torch.unique

mindspore.mint.unique

Consistent

torch.unique_consecutive

mindspore.mint.unique_consecutive

Consistent

torch.unsqueeze

mindspore.mint.unsqueeze

Consistent

torch.var

mindspore.mint.var

Consistent

torch.var_mean

mindspore.mint.var_mean

Consistent

torch.where

mindspore.mint.where

Consistent

torch.xlogy

mindspore.mint.xlogy

Consistent

torch.zeros

mindspore.mint.zeros

Consistent

torch.zeros_like

mindspore.mint.zeros_like

Consistent

torch.linalg

PyTorch 2.1 APIs

MindSpore APIs

说明

torch.linalg.inv

mindspore.mint.linalg.inv

Consistent

torch.linalg.matrix_norm

mindspore.mint.linalg.matrix_norm

Consistent

torch.linalg.norm

mindspore.mint.linalg.norm

Consistent

torch.linalg.vector_norm

mindspore.mint.linalg.vector_norm

Consistent

torch.distributed

PyTorch 2.1 APIs

MindSpore APIs

Descriptions

torch.distributed.P2POp

mindspore.mint.distributed.P2POp

Consistent

torch.distributed.all_gather

mindspore.mint.distributed.all_gather

Consistent

torch.distributed.all_gather_into_tensor

mindspore.mint.distributed.all_gather_into_tensor

Consistent

torch.distributed.all_gather_object

mindspore.mint.distributed.all_gather_object

Consistent

torch.distributed.all_reduce

mindspore.mint.distributed.all_reduce

Consistent

torch.distributed.all_to_all_single

mindspore.mint.distributed.all_to_all_single

Consistent

torch.distributed.all_to_all

mindspore.mint.distributed.all_to_all

Consistent

torch.distributed.barrier

mindspore.mint.distributed.barrier

Consistent

torch.distributed.batch_isend_irecv

mindspore.mint.distributed.batch_isend_irecv

Consistent

torch.distributed.broadcast

mindspore.mint.distributed.broadcast

Consistent

torch.distributed.distributed.broadcast_object_list

mindspore.mint.distributed.distributed.broadcast_object_list

Consistent

mindspore.mint.distributed.destroy_process_group

Unique to MindSpore

torch.distributed.gather

mindspore.mint.distributed.gather

Consistent

torch.distributed.gather_object

mindspore.mint.distributed.gather

Consistent

torch.distributed.get_backend

mindspore.mint.distributed.get_backend

Consistent

torch.distributed.get_global_rank

mindspore.mint.distributed.get_global_rank

Consistent

torch.distributed.get_group_rank

mindspore.mint.distributed.get_group_rank

Consistent

torch.distributed.get_process_group_ranks

mindspore.mint.distributed.get_process_group_ranks

Consistent

torch.distributed.get_rank

mindspore.mint.distributed.get_rank

Consistent

torch.distributed.get_world_size

mindspore.mint.distributed.get_world_size

Consistent

torch.distributed.init_process_group

mindspore.mint.distributed.init_process_group

Consistent functions, inconsistent parameter names.

torch.distributed.irecv

mindspore.mint.distributed.irecv

Consistent

torch.distributed.isend

mindspore.mint.distributed.isend

Consistent

torch.distributed.new_group

mindspore.mint.distributed.new_group

Consistent functions, MindSpore has an additional parameter group_desc = None.

torch.distributed.recv

mindspore.mint.distributed.recv

Consistent

torch.distributed.reduce

mindspore.mint.distributed.reduce

Consistent

torch.distributed.reduce_scatter

mindspore.mint.distributed.reduce_scatter

Consistent

torch.distributed.reduce_scatter_tensor

mindspore.mint.distributed.reduce_scatter_tensor

Consistent

torch.distributed.scatter

mindspore.mint.distributed.scatter

The functions are consistent, but the default value of scatter_list is different.

torch.distributed.scatter_object_list

mindspore.mint.distributed.scatter_object_list

Consistent

torch.distributed.send

mindspore.mint.distributed.send

Consistent

torch.nn

PyTorch 2.1 APIs

MindSpore APIs

Descriptions

torch.nn.AdaptiveAvgPool1d

mindspore.mint.nn.AdaptiveAvgPool1d

Consistent

torch.nn.AdaptiveAvgPool2d

mindspore.mint.nn.AdaptiveAvgPool2d

Consistent

torch.nn.AdaptiveAvgPool3d

mindspore.mint.nn.AdaptiveAvgPool3d

Consistent

torch.nn.AvgPool2d

mindspore.mint.nn.AvgPool2d

Consistent

torch.nn.BCELoss

mindspore.mint.nn.BCELoss

Consistent

torch.nn.BCEWithLogitsLoss

mindspore.mint.nn.BCEWithLogitsLoss

Consistent

torch.nn.BatchNorm1d

mindspore.mint.nn.BatchNorm1d

Consistent

torch.nn.BatchNorm2d

mindspore.mint.nn.BatchNorm2d

Consistent

torch.nn.BatchNorm3d

mindspore.mint.nn.BatchNorm3d

Consistent

torch.nn.ConstantPad1d

mindspore.mint.nn.ConstantPad1d

Consistent

torch.nn.ConstantPad2d

mindspore.mint.nn.ConstantPad2d

Consistent

torch.nn.ConstantPad3d

mindspore.mint.nn.ConstantPad3d

Consistent

torch.nn.Conv2d

mindspore.mint.nn.Conv2d

Consistent

torch.nn.Conv3d

mindspore.mint.nn.Conv3d

Consistent

torch.nn.ConvTranspose2d

mindspore.mint.nn.ConvTranspose2d

Consistent

torch.nn.CrossEntropyLoss

mindspore.mint.nn.CrossEntropyLoss

Consistent

torch.nn.Dropout

mindspore.mint.nn.Dropout

Consistent

torch.nn.Dropout2d

mindspore.mint.nn.Dropout2d

Consistent functions, MindSpore has no parameter inplace.

torch.nn.ELU

mindspore.mint.nn.ELU

Consistent functions, MindSpore has no parameter inplace.

torch.nn.Embedding

mindspore.mint.nn.Embedding

Consistent

torch.nn.Flatten

mindspore.mint.flatten

Consistent

torch.nn.Fold

mindspore.mint.nn.Fold

Consistent

torch.nn.GroupNorm

mindspore.mint.nn.Fold

Consistent

torch.nn.GELU

mindspore.mint.nn.GELU

Consistent

torch.nn.GroupNorm

mindspore.mint.nn.GroupNorm

Consistent

torch.nn.Hardshrink

mindspore.mint.nn.Hardshrink

Consistent

torch.nn.Hardsigmoid

mindspore.mint.nn.Hardsigmoid

Consistent

torch.nn.Hardswish

mindspore.mint.nn.Hardswish

Consistent

torch.nn.Identity

mindspore.mint.nn.Identity

Consistent

torch.nn.L1Loss

mindspore.mint.nn.L1Loss

Consistent

torch.nn.LayerNorm

mindspore.mint.nn.LayerNorm

Consistent

torch.nn.Linear

mindspore.mint.nn.Linear

Consistent function, MindSpore has two different parameters: weight_init = None and bias_init = None.

torch.nn.LogSigmoid

mindspore.mint.nn.LogSigmoid

Consistent

torch.nn.LogSoftMax

mindspore.mint.nn.LogSoftmax

Consistent

torch.nn.MSELoss

mindspore.mint.nn.MSELoss

Consistent

torch.nn.MaxUnpool2d

mindspore.mint.nn.MaxUnpool2d

Consistent

torch.nn.Mish

mindspore.mint.nn.Mish

Consistent

torch.nn.NLLLoss

mindspore.mint.nn.NLLLoss

Consistent

torch.nn.PReLU

mindspore.mint.nn.PReLU

Consistent

torch.nn.ReLU

mindspore.mint.nn.ReLU

Consistent

torch.nn.ReLU6

mindspore.mint.nn.ReLU6

Consistent

torch.nn.ReflectionPad1d

mindspore.mint.nn.ReflectionPad1d

Consistent

torch.nn.ReflectionPad2d

mindspore.mint.nn.ReflectionPad2d

Consistent

torch.nn.ReflectionPad3d

mindspore.mint.nn.ReflectionPad3d

Consistent

torch.nn.ReplicationPad1d

mindspore.mint.nn.ReplicationPad1d

Consistent

torch.nn.ReplicationPad2d

mindspore.mint.nn.ReplicationPad2d

Consistent

torch.nn.ReplicationPad3d

mindspore.mint.nn.ReplicationPad3d

Consistent

torch.nn.SeLU

mindspore.mint.nn.SELU

Consistent

torch.nn.SiLU

mindspore.mint.nn.SiLU

Consistent

torch.nn.SmoothL1Loss

mindspore.mint.nn.SmoothL1Loss

Consistent

torch.nn.Softmax

mindspore.mint.nn.Softmax

Consistent

torch.nn.Softshrink

mindspore.mint.nn.Softshrink

Consistent

torch.nn.SyncBatchNorm

mindspore.mint.nn.SyncBatchNorm

Consistent

torch.nn.Tanh

mindspore.mint.nn.Tanh

Consistent

torch.nn.Unfold

mindspore.mint.nn.Unfold

Consistent

torch.nn.Upsample

mindspore.mint.nn.Upsample

Consistent

torch.nn.ZeroPad1d

mindspore.mint.nn.ZeroPad1d

Consistent

torch.nn.ZeroPad2d

mindspore.mint.nn.ZeroPad2d

Consistent

torch.nn.ZeroPad3d

mindspore.mint.nn.ZeroPad3d

Consistent

torch.nn.functional

PyTorch 2.1 APIs

MindSpore APIs

Descriptions

torch.nn.functional.adaptive_avg_pool1d

mindspore.mint.nn.functional.adaptive_avg_pool1d

Consistent

torch.nn.functional.adaptive_avg_pool2d

mindspore.mint.nn.functional.adaptive_avg_pool2d

Consistent

torch.nn.functional.avg_pool1d

mindspore.mint.nn.functional.avg_pool1d

Consistent

torch.nn.functional.avg_pool2d

mindspore.mint.nn.functional.avg_pool2d

Consistent

torch.nn.functional.batch_norm

mindspore.mint.nn.functional.batch_norm

Consistent

torch.nn.functional.binary_cross_entropy

mindspore.mint.nn.functional.binary_cross_entropy

Consistent

torch.nn.functional.binary_cross_entropy_with_logits

mindspore.mint.nn.functional.binary_cross_entropy_with_logits

Consistent

torch.nn.functional.conv2d

mindspore.mint.nn.functional.conv2d

Consistent

torch.nn.functional.conv3d

mindspore.mint.nn.functional.conv3d

Consistent

torch.nn.functional.conv_transpose2d

mindspore.mint.nn.functional.conv_transpose2d

Consistent

torch.nn.functional.dropout

mindspore.mint.nn.functional.dropout

Consistent

torch.nn.functional.dropout2d

mindspore.mint.nn.functional.dropout2d

Consistent functions, MindSpore does not contain the parameter inplace.

torch.nn.functional.elu

mindspore.mint.nn.functional.elu

Consistent functions, MindSpore does not contain the parameter inplace.

torch.nn.functional.embedding

mindspore.mint.nn.functional.embedding

Consistent functions, MindSpore does not contain the parameter sparse.

torch.nn.functional.fold

mindspore.mint.nn.functional.fold

Consistent

torch.nn.functional.gelu

mindspore.mint.nn.functional.gelu

Consistent

torch.nn.functional.grid_sample

mindspore.mint.nn.functional.grid_sample

Consistent functions, but the default value of align_corners is different.

torch.nn.functional.hardshrink

mindspore.mint.nn.functional.hardshrink

Consistent

torch.nn.functional.hardsigmoid

mindspore.mint.nn.functional.hardsigmoid

Consistent functions, MindSpore has no parameter inplace.

torch.nn.functional.hardswish

mindspore.mint.nn.functional.hardswish

Consistent functions, MindSpore has no parameter inplace.

torch.nn.functional.interpolate

mindspore.mint.nn.functional.interpolate

Consistent functions, MindSpore has no parameter antialias.

torch.nn.functional.l1_loss

mindspore.mint.nn.functional.l1_loss

Consistent](https://www.mindspore.cn/docs/en/master/note/api_mapping/pytorch_api_mapping.html#api-mapping-consistency-criteria-and-exceptions)

torch.nn.functional.leaky_relu

mindspore.mint.nn.functional.leaky_relu

Consistent functions, MindSpore has no parameter inplace.

torch.nn.functional.linear

mindspore.mint.nn.functional.linear

Consistent

torch.nn.functional.log_softmax

mindspore.mint.nn.functional.log_softmax

Consistent

torch.nn.functional.logsigmoid

mindspore.mint.nn.functional.logsigmoid

Consistent

torch.nn.functional.max_pool2d

mindspore.mint.nn.functional.max_pool2d

Consistent

torch.nn.functional.max_unpool2d

mindspore.mint.nn.functional.max_unpool2d

Consistent

torch.nn.functional.mish

mindspore.mint.nn.functional.mish

Consistent functions, MindSpore has no parameter inplace.

torch.nn.functional.mse_loss

mindspore.mint.nn.functional.mse_loss

Consistent

torch.nn.functional.nll_loss

mindspore.mint.nn.functional.nll_loss

Consistent

torch.nn.functional.normalize

mindspore.mint.nn.functional.normalize

Consistent

torch.nn.functional.one_hot

mindspore.mint.nn.functional.one_hot

Consistent

torch.nn.functional.pad

mindspore.mint.nn.functional.pad

Consistent

torch.nn.functional.prelu

mindspore.mint.nn.functional.prelu

Consistent

torch.nn.functional.relu

mindspore.mint.nn.functional.relu

Consistent

torch.nn.functional.relu6

mindspore.mint.nn.functional.relu6

Consistent

torch.nn.functional.relu_

mindspore.mint.nn.functional.relu_

Consistent

torch.nn.functional.selu

mindspore.mint.nn.functional.selu

Consistent functions, MindSpore does not contain parameter inplace.

torch.nn.functional.sigmoid

mindspore.mint.nn.functional.sigmoid

Consistent

torch.nn.functional.silu

mindspore.mint.nn.functional.silu

Consistent functions, MindSpore does not contain parameter inplace.

torch.nn.functional.smooth_l1_loss

mindspore.mint.nn.functional.smooth_l1_loss

Consistent

torch.nn.functional.softmax

mindspore.mint.nn.functional.softmax

Consistent

torch.nn.functional.softplus

mindspore.mint.nn.functional.softplus

Consistent

torch.nn.functional.softshrink

mindspore.mint.nn.functional.softshrink

Consistent

torch.nn.functional.tanh

mindspore.mint.nn.functional.tanh

Consistent

torch.nn.functional.unfold

mindspore.mint.nn.functional.unfold

Consistent

torch.special

PyTorch 2.1 APIs

MindSpore APIs

说明

torch.special.erfc

mindspore.mint.special.erfc

Consistent

torch.special.exp2

mindspore.mint.special.exp2

Consistent

torch.special.expm1

mindspore.mint.special.expm1

Consistent

torch.special.log1p

mindspore.mint.special.log1p

Consistent

torch.special.log_softmax

mindspore.mint.special.log_softmax

Consistent

torch.special.round

mindspore.mint.special.round

Consistent

torch.special.sinc

mindspore.mint.special.sinc

Consistent

torch.Tensor

PyTorch 2.1 APIs

MindSpore APIs

Descriptions

torch.Tensor.abs

mindspore.Tensor.abs

Consistent

torch.Tensor.absolute

mindspore.Tensor.absolute

Consistent

torch.Tensor.add

mindspore.Tensor.add

Consistent

torch.Tensor.all

mindspore.Tensor.all

Consistent

torch.Tensor.any

mindspore.Tensor.any

Consistent

torch.Tensor.argmax

mindspore.Tensor.argmax

Consistent

torch.Tensor.arctan2

mindspore.Tensor.arctan2

Consistent

torch.Tensor.argmin

mindspore.Tensor.argmin

Consistent

torch.Tensor.atan2

mindspore.Tensor.atan2

Consistent

torch.Tensor.bool

mindspore.Tensor.bool

Consistent

torch.Tensor.ceil

mindspore.Tensor.ceil

Consistent

torch.Tensor.chunk

mindspore.Tensor.chunk

Consistent

torch.Tensor.clamp

mindspore.Tensor.clamp

Consistent

torch.Tensor.clamp_

mindspore.Tensor.clamp_

Consistent

torch.Tensor.clip

mindspore.Tensor.clip

Consistent

torch.Tensor.cos

mindspore.Tensor.cos

Consistent

torch.Tensor.cumsum

mindspore.Tensor.cumsum

Consistent

torch.Tensor.div

mindspore.Tensor.div

Consistent

torch.Tensor.divide

mindspore.Tensor.divide

Consistent

torch.Tensor.eq

mindspore.Tensor.eq

Consistent

torch.Tensor.erf

mindspore.Tensor.erf

Consistent

torch.Tensor.exp

mindspore.Tensor.exp

Consistent

torch.Tensor.expand_as

mindspore.Tensor.expand_as

Consistent

torch.Tensor.flatten

mindspore.Tensor.flatten

Consistent

torch.Tensor.float

mindspore.Tensor.float

Consistent

torch.Tensor.floor

mindspore.Tensor.floor

Consistent

torch.Tensor.gather

mindspore.Tensor.gather

Consistent

torch.Tensor.greater

mindspore.Tensor.greater

Consistent

torch.Tensor.gt

mindspore.Tensor.gt

Consistent

torch.Tensor.half

mindspore.Tensor.half

Consistent

torch.Tensor.index_select

mindspore.Tensor.index_select

Consistent

torch.Tensor.int

mindspore.Tensor.int

Consistent

torch.Tensor.isfinite

mindspore.Tensor.isfinite

Consistent

torch.Tensor.isnan

mindspore.Tensor.isnan

Consistent

torch.Tensor.item

mindspore.Tensor.item

Consistent

torch.Tensor.le

mindspore.Tensor.le

Consistent

torch.Tensor.less

mindspore.Tensor.less

Consistent

torch.Tensor.less_equal

mindspore.Tensor.less_equal

Consistent

torch.Tensor.log

mindspore.Tensor.log

Consistent

torch.Tensor.logical_and

mindspore.Tensor.logical_and

Consistent

torch.Tensor.logical_not

mindspore.Tensor.logical_not

Consistent

torch.Tensor.logical_or

mindspore.Tensor.logical_or

Consistent

torch.Tensor.long

mindspore.Tensor.long

Consistent

torch.Tensor.lt

mindspore.Tensor.lt

Consistent

torch.Tensor.masked_fill

mindspore.Tensor.masked_fill

Consistent

torch.Tensor.masked_select

mindspore.Tensor.masked_select

Consistent

torch.Tensor.matmul

mindspore.Tensor.matmul

Consistent

torch.Tensor.max

mindspore.Tensor.max

Consistent

torch.Tensor.maximum

mindspore.Tensor.maximum

Consistent

torch.Tensor.mean

mindspore.Tensor.mean

Consistent

torch.Tensor.min

mindspore.Tensor.min

Consistent

torch.Tensor.minimum

mindspore.Tensor.minimum

Consistent

torch.Tensor.mul

mindspore.Tensor.mul

Consistent

torch.Tensor.nan_to_num

mindspore.Tensor.nan_to_num

Consistent

torch.Tensor.ne

mindspore.Tensor.ne

Consistent

torch.Tensor.neg

mindspore.Tensor.neg

Consistent

torch.Tensor.negative

mindspore.Tensor.negative

Consistent

torch.Tensor.not_equal

mindspore.Tensor.not_equal

Consistent

torch.Tensor.pow

mindspore.Tensor.pow

Consistent

torch.Tensor.prod

mindspore.Tensor.prod

Consistent

torch.Tensor.reciprocal

mindspore.Tensor.reciprocal

Consistent

torch.Tensor.remainder

mindspore.Tensor.remainder

Consistent

torch.Tensor.repeat_interleave

mindspore.Tensor.repeat_interleave

Consistent

torch.Tensor.reshape

mindspore.Tensor.reshape

Consistent

torch.Tensor.round

mindspore.Tensor.round

Consistent

torch.Tensor.rsqrt

mindspore.Tensor.rsqrt

Consistent

torch.Tensor.scatter

mindspore.Tensor.scatter

Consistent

torch.Tensor.scatter_add

mindspore.Tensor.scatter_add

Consistent

torch.Tensor.sigmoid

mindspore.Tensor.sigmoid

Consistent

torch.Tensor.sin

mindspore.Tensor.sin

Consistent

torch.Tensor.sort

mindspore.Tensor.sort

Consistent

torch.Tensor.split

mindspore.Tensor.split

Consistent

torch.Tensor.sqrt

mindspore.Tensor.sqrt

Consistent

torch.Tensor.square

mindspore.Tensor.square

Consistent

torch.Tensor.sub

mindspore.Tensor.sub

Consistent

torch.Tensor.sum

mindspore.Tensor.sum

Consistent

torch.Tensor.t

mindspore.Tensor.t

Consistent

torch.Tensor.tanh

mindspore.Tensor.tanh

Consistent

torch.Tensor.tile

mindspore.Tensor.tile

Consistent

torch.Tensor.topk

mindspore.Tensor.topk

Consistent

torch.Tensor.tril

mindspore.Tensor.tril

Consistent

torch.Tensor.trunc

mindspore.Tensor.trunc

Consistent

torch.Tensor.view_as

mindspore.Tensor.view_as

Consistent

torch.Tensor.where

mindspore.Tensor.where

Consistent

torch.optim

PyTorch 2.1 APIs

MindSpore APIs

Descriptions

torch.optim.Adam

mindspore.mint.optim.Adam

The functions are consistent, but PyTorch has some optimization parameters

torch.optim.AdamW

mindspore.mint.optim.AdamW

The functions are consistent, but PyTorch has some optimization parameters

torch.utils

PyTorch 1.8.1 APIs

MindSpore APIs

Descriptions

torch.utils.data.DataLoader

mindspore.dataset.GeneratorDataset

diff

torch.utils.data.distributed.DistributedSampler

mindspore.dataset.DistributedSampler

diff

torch.utils.data.RandomSampler

mindspore.dataset.RandomSampler

diff

torch.utils.data.SequentialSampler

mindspore.dataset.SequentialSampler

diff

torch.utils.data.SubsetRandomSampler

mindspore.dataset.SubsetRandomSampler

diff

torch.utils.data.WeightedRandomSampler

mindspore.dataset.WeightedRandomSampler

diff

torch.utils.checkpoint.checkpoint

mindspore.nn.Cell.recompute

diff

torchaudio

The current API mapping table corresponds to PyTorch version 1.8.1, and Python version is no higher than Python 3.9.

TorchAudio 0.8.1 APIs

MindSpore APIs

Descriptions

torchaudio.datasets.CMUARCTIC

mindspore.dataset.CMUArcticDataset

diff

torchaudio.datasets.GTZAN

mindspore.dataset.GTZANDataset

diff

torchaudio.datasets.LIBRITTS

mindspore.dataset.LibriTTSDataset

diff

torchaudio.datasets.LJSPEECH

mindspore.dataset.LJSpeechDataset

diff

torchaudio.datasets.SPEECHCOMMANDS

mindspore.dataset.SpeechCommandsDataset

diff

torchaudio.datasets.TEDLIUM

mindspore.dataset.TedliumDataset

diff

torchaudio.datasets.YESNO

mindspore.dataset.YesNoDataset

diff

torchaudio.transforms.AmplitudeToDB

mindspore.dataset.audio.AmplitudeToDB

diff

torchaudio.transforms.ComplexNorm

mindspore.dataset.audio.ComplexNorm

Consistent

torchaudio.transforms.ComputeDeltas

mindspore.dataset.audio.ComputeDeltas

The functions are consistent, but the parameter names are inconsistent.

torchaudio.transforms.Fade

mindspore.dataset.audio.Fade

Consistent

torchaudio.transforms.FrequencyMasking

mindspore.dataset.audio.FrequencyMasking

diff

torchaudio.transforms.GriffinLim

mindspore.dataset.audio.GriffinLim

diff

torchaudio.transforms.InverseMelScale

mindspore.dataset.audio.InverseMelScale

diff

torchaudio.transforms.MelScale

mindspore.dataset.audio.MelScale

diff

torchaudio.transforms.MelSpectrogram

mindspore.dataset.audio.MelSpectrogram

diff

torchaudio.transforms.MFCC

mindspore.dataset.audio.MFCC

Consistent

torchaudio.transforms.MuLawEncoding

mindspore.dataset.audio.MuLawEncoding

Consistent

torchaudio.transforms.MuLawDecoding

mindspore.dataset.audio.MuLawDecoding

Consistent

torchaudio.transforms.Resample

mindspore.dataset.audio.Resample

diff

torchaudio.transforms.SlidingWindowCmn

mindspore.dataset.audio.SlidingWindowCmn

Consistent

torchaudio.transforms.SpectralCentroid

mindspore.dataset.audio.SpectralCentroid

diff

torchaudio.transforms.Spectrogram

mindspore.dataset.audio.Spectrogram

diff

torchaudio.transforms.TimeMasking

mindspore.dataset.audio.TimeMasking

diff

torchaudio.transforms.TimeStretch

mindspore.dataset.audio.TimeStretch

Consistent

torchaudio.transforms.Vad

mindspore.dataset.audio.Vad

Consistent

torchaudio.transforms.Vol

mindspore.dataset.audio.Vol

Consistent

torchtext

The current API mapping table corresponds to PyTorch version 1.8.1, and Python version is no higher than Python 3.9.

TorchText 0.9.1 APIs

MindSpore APIs

Descriptions

torchtext.data.functional.custom_replace

mindspore.dataset.text.RegexReplace

diff

torchtext.data.functional.load_sp_model

mindspore.dataset.text.SentencePieceTokenizer

diff

torchtext.data.functional.numericalize_tokens_from_iterator

mindspore.dataset.text.Lookup

diff

torchtext.data.functional.sentencepiece_numericalizer

mindspore.dataset.text.SentencePieceTokenizer

diff

torchtext.data.functional.sentencepiece_tokenizer

mindspore.dataset.text.SentencePieceTokenizer

diff

torchtext.data.functional.simple_space_split

mindspore.dataset.text.WhitespaceTokenizer

diff

torchtext.data.utils.ngrams_iterator

mindspore.dataset.text.Ngram

diff

torchtext.datasets.AG_NEWS

mindspore.dataset.AGNewsDataset

diff

torchtext.datasets.AmazonReviewFull

mindspore.dataset.AmazonReviewDataset

diff

torchtext.datasets.AmazonReviewPolarity

mindspore.dataset.AmazonReviewDataset

diff

torchtext.datasets.CoNLL2000Chunking

mindspore.dataset.CoNLL2000Dataset

diff

torchtext.datasets.DBpedia

mindspore.dataset.DBpediaDataset

diff

torchtext.datasets.IMDB

mindspore.dataset.IMDBDataset

diff

torchtext.datasets.IWSLT2016

mindspore.dataset.IWSLT2016Dataset

diff

torchtext.datasets.IWSLT2017

mindspore.dataset.IWSLT2017Dataset

diff

torchtext.datasets.PennTreebank

mindspore.dataset.PennTreebankDataset

diff

torchtext.datasets.SogouNews

mindspore.dataset.SogouNewsDataset

diff

torchtext.datasets.SQuAD1

mindspore.dataset.SQuADDataset

diff

torchtext.datasets.SQuAD2

mindspore.dataset.SQuADDataset

diff

torchtext.datasets.UDPOS

mindspore.dataset.UDPOSDataset

diff

torchtext.datasets.WikiText103

mindspore.dataset.WikiTextDataset

diff

torchtext.datasets.WikiText2

mindspore.dataset.WikiTextDataset

diff

torchtext.datasets.YahooAnswers

mindspore.dataset.YahooAnswersDataset

diff

torchtext.datasets.YelpReviewFull

mindspore.dataset.YelpReviewDataset

diff

torchtext.datasets.YelpReviewPolarity

mindspore.dataset.YelpReviewDataset

diff

torchvision

The current API mapping table corresponds to PyTorch version 1.8.1, and Python version is no higher than Python 3.9.

TorchVision 0.9.1 APIs

MindSpore APIs

Descriptions

torchvision.datasets.CelebA

mindspore.dataset.CelebADataset

diff

torchvision.datasets.Cityscapes

mindspore.dataset.CityscapesDataset

diff

torchvision.datasets.CIFAR10

mindspore.dataset.Cifar10Dataset

diff

torchvision.datasets.CIFAR100

mindspore.dataset.Cifar100Dataset

diff

torchvision.datasets.CocoDetection

mindspore.dataset.CocoDataset

diff

torchvision.datasets.ImageFolder

mindspore.dataset.ImageFolderDataset

diff

torchvision.datasets.MNIST

mindspore.dataset.MnistDataset

diff

torchvision.datasets.VOCDetection

mindspore.dataset.VOCDataset

diff

torchvision.datasets.VOCSegmentation

mindspore.dataset.VOCDataset

diff

torchvision.ops.nms

mindspore.ops.NMSWithMask

diff

torchvision.ops.roi_align

mindspore.ops.ROIAlign

diff

torchvision.transforms.CenterCrop

mindspore.dataset.vision.CenterCrop

Consistent

torchvision.transforms.ColorJitter

mindspore.dataset.vision.RandomColorAdjust

Consistent

torchvision.transforms.Compose

mindspore.dataset.transforms.Compose

Consistent

torchvision.transforms.ConvertImageDtype

mindspore.dataset.transforms.TypeCast

diff

torchvision.transforms.FiveCrop

mindspore.dataset.vision.FiveCrop

Consistent

torchvision.transforms.GaussianBlur

mindspore.dataset.vision.GaussianBlur

Consistent

torchvision.transforms.Grayscale

mindspore.dataset.vision.Grayscale

Consistent

torchvision.transforms.LinearTransformation

mindspore.dataset.vision.LinearTransformation

Consistent

torchvision.transforms.Normalize

mindspore.dataset.vision.Normalize

diff

torchvision.transforms.Pad

mindspore.dataset.vision.Pad

The functions are consistent, but the parameter names are inconsistent.

torchvision.transforms.RandomAffine

mindspore.dataset.vision.RandomAffine

diff

torchvision.transforms.RandomApply

mindspore.dataset.transforms.RandomApply

The functions are consistent, but the parameter names are inconsistent.

torchvision.transforms.RandomChoice

mindspore.dataset.transforms.RandomChoice

Consistent

torchvision.transforms.RandomCrop

mindspore.dataset.vision.RandomCrop

The functions are consistent, but the parameter names are inconsistent.

torchvision.transforms.RandomGrayscale

mindspore.dataset.vision.RandomGrayscale

The functions are consistent, but the parameter names are inconsistent.

torchvision.transforms.RandomHorizontalFlip

mindspore.dataset.vision.RandomHorizontalFlip

The functions are consistent, but the parameter names are inconsistent.

torchvision.transforms.RandomOrder

mindspore.dataset.transforms.RandomOrder

Consistent

torchvision.transforms.RandomPerspective

mindspore.dataset.vision.RandomPerspective

diff

torchvision.transforms.RandomResizedCrop

mindspore.dataset.vision.RandomResizedCrop

diff

torchvision.transforms.RandomRotation

mindspore.dataset.vision.RandomRotation

diff

torchvision.transforms.RandomVerticalFlip

mindspore.dataset.vision.RandomVerticalFlip

The functions are consistent, but the parameter names are inconsistent.

torchvision.transforms.Resize

mindspore.dataset.vision.Resize

Consistent

torchvision.transforms.TenCrop

mindspore.dataset.vision.TenCrop

The functions are consistent, but the parameter names are inconsistent.

torchvision.transforms.ToPILImage

mindspore.dataset.vision.ToPIL

diff

torchvision.transforms.ToTensor

mindspore.dataset.vision.ToTensor

diff

torchvision.ops.deform_conv2d

mindspore.ops.deformable_conv2d

diff