PyTorch and MindSpore API Mapping Table
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 following exceptions are also considered to be consistent the API mapping:
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.
(3) MindSpore API does not support passing parameters of 8D and above.
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 1.8.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.ops.argmax has only one API form, namely mindspore.ops.argmax(input, dim=None, keepdim=False), but mindspore.ops.argmax(input) and torch.argmax(input) have the same function. mindspore.ops.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 |
generator |
Indicates a generator for pseudorandom number |
In MindSpore, replaced with the parameter |
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. |
inplace |
Indicates that the value of a variable is modified directly without changing the memory address of the variable |
MindSpore currently provides some inplace APIs, such as |
sparse_grad |
Indicates whether to perform sparsification on the gradient |
Not supported in MindSpore. |
size_average |
The deprecated parameter in PyTorch |
The |
reduce |
The deprecated parameter in PyTorch |
The |
PyTorch 1.8.1
torch
PyTorch 1.8.1 APIs |
MindSpore APIs |
Descriptions |
---|---|---|
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the number or sequence of parameters is inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter data types are inconsistent |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter data types are inconsistent |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functiions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter data types are inconsistent |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter data types are inconsistent |
||
The functions are consistent, but the parameter data types are inconsistent |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter data types are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the number or sequence of parameters is inconsistent |
||
The functions are consistent, but the parameter data types are inconsistent. |
||
The functions are consistent, but the parameter data types are inconsistent. |
||
The functions are consistent, but the parameter data types are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter default values are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter data types are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the number or sequence of parameters is inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter data types are inconsistent. |
||
The functions are consistent, but the parameter data types are inconsistent. |
||
The functions are consistent, but the parameter default values are inconsistent. |
||
The functions are consistent, but the parameter default values are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the number or sequence of parameters is inconsistent |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
torch.distributions
PyTorch 1.8.1 APIs |
MindSpore APIs |
Descriptions |
---|---|---|
torch.distributed
PyTorch 1.8.1 APIs |
MindSpore APIs |
Descriptions |
---|---|---|
torch.nn
PyTorch 1.8.1 APIs |
MindSpore APIs |
Descriptions |
---|---|---|
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the number or sequence of parameters is inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
torch.nn.functional
PyTorch 1.8.1 APIs |
MindSpore APIs |
Descriptions |
---|---|---|
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent |
||
The functions are consistent, but the parameter data types are inconsistent. |
||
The functions are consistent, but the parameter data types are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the number or sequence of parameters is inconsistent. |
||
Consistent |
||
torch.nn.Module
PyTorch 1.8.1 APIs |
MindSpore APIs |
Descriptions |
---|---|---|
Consistent |
torch.nn.utils
PyTorch 1.8.1 APIs |
MindSpore APIs |
Descriptions |
---|---|---|
torch.Tensor
PyTorch 1.8.1 APIs |
MindSpore APIs |
Descriptions |
---|---|---|
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the number or sequence of parameters is inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but parameter names are different. |
||
The functions are consistent, but parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but parameter names are inconsistent. |
||
The functions are consistent, but the parameter default values are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
torch.Tensor.norm is about to be deprecated, mindspore.Tensor.norm is completely consistent with torch.linalg.norm |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter data types are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. The split_size parameter is split_size_or_sections in MindSpore. |
||
The functions are consistent, but the number or sequence of parameters is inconsistent |
||
the functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent |
||
The functions are consistent, but the parameter names are inconsistent. |
torch.optim
PyTorch 1.8.1 APIs |
MindSpore APIs |
Descriptions |
---|---|---|
Consistent |
||
Consistent |
||
Consistent |
||
torch.optim
PyTorch 1.8.1 APIs |
MindSpore APIs |
Descriptions |
---|---|---|
Consistent |
||
Consistent |
||
Consistent |
torch.optim.lr_scheduler
PyTorch 1.8.1 APIs |
MindSpore APIs |
Descriptions |
---|---|---|
No |
||
No |
||
No |
||
No |
||
mindspore.experimental.optim.lr_scheduler.CosineAnnealingWarmRestarts |
No |
|
No |
||
No |
||
No |
||
No |
||
No |
||
No |
||
No |
||
No |
||
No |
||
No |
torch.utils
PyTorch 1.8.1 APIs |
MindSpore APIs |
Descriptions |
---|---|---|
torchaudio
TorchAudio 0.8.1 APIs |
MindSpore APIs |
Descriptions |
---|---|---|
Consistent |
||
The functions are consistent, but the parameter names are inconsistent. |
||
Consistent |
||
Consistent |
||
Consistent |
||
Consistent |
||
Consistent |
||
Consistent |
||
Consistent |
||
Consistent |
torchtext
TorchText 0.9.1 APIs |
MindSpore APIs |
Descriptions |
---|---|---|
torchvision
TorchVision 0.9.1 APIs |
MindSpore APIs |
Descriptions |
---|---|---|
Consistent |
||
Consistent |
||
Consistent |
||
Consistent |
||
Consistent |
||
Consistent |
||
Consistent |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
Consistent |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
The functions are consistent, but the parameter names are inconsistent. |
||
Consistent |
||
The functions are consistent, but the parameter names are inconsistent. |
||
Consistent |
||
The functions are consistent, but the parameter names are inconsistent. |
||