Document feedback

Question document fragment

When a question document fragment contains a formula, it is displayed as a space.

Submission type
issue

It's a little complicated...

I'd like to ask someone.

PR

Just a small problem.

I can fix it online!

Please select the submission type

Problem type
Specifications and Common Mistakes

- Specifications and Common Mistakes:

- Misspellings or punctuation mistakes,incorrect formulas, abnormal display.

- Incorrect links, empty cells, or wrong formats.

- Chinese characters in English context.

- Minor inconsistencies between the UI and descriptions.

- Low writing fluency that does not affect understanding.

- Incorrect version numbers, including software package names and version numbers on the UI.

Usability

- Usability:

- Incorrect or missing key steps.

- Missing main function descriptions, keyword explanation, necessary prerequisites, or precautions.

- Ambiguous descriptions, unclear reference, or contradictory context.

- Unclear logic, such as missing classifications, items, and steps.

Correctness

- Correctness:

- Technical principles, function descriptions, supported platforms, parameter types, or exceptions inconsistent with that of software implementation.

- Incorrect schematic or architecture diagrams.

- Incorrect commands or command parameters.

- Incorrect code.

- Commands inconsistent with the functions.

- Wrong screenshots.

- Sample code running error, or running results inconsistent with the expectation.

Risk Warnings

- Risk Warnings:

- Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

- Content Compliance:

- Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions.

- Copyright infringement.

Please select the type of question

Problem description

Describe the bug so that we can quickly locate the problem.

Function Differences with torch.nn.functional.elu

View Source On Gitee

torch.nn.functional.elu

torch.nn.functional.elu(input, alpha=1.0, inplace=False) -> Tensor

For more information, see torch.nn.functional.elu.

mindspore.ops.elu

mindspore.ops.elu(input_x, alpha=1.0) -> Tensor

For more information, see mindspore.ops.elu.

Differences

PyTorch: compute the exponential linear value of the input x. The result is elu(x)=max(0,x)+min(0,α(exp(x)1)), with the inplace parameter to choose whether to operate in-place or not, and the default is False.

MindSpore: MindSpore API implements the same functions as PyTorch, but α currently only supports 1.0.

Categories

Subcategories

PyTorch

MindSpore

Difference

Parameters

Parameter 1

input

input_x

Same function, different parameter names

Parameter 2

alpha

alpha

α factor. MindSpore currently only supports alpha equal to 1.0

Parameter 3

inplace

-

MindSpore does not have this parameter

Code Example 1

Both APIs implement the exponential linear unit function, but PyTorch can customize the α coefficient, and MindSpore only supports a coefficient of 1.0.

# PyTorch
import torch
from torch import tensor
from torch.nn.functional import elu
import numpy as np

x_ = np.array([[np.arange(-6,0).reshape(2, 3),np.arange(0,6).reshape(2, 3)]])
x = tensor(x_, dtype=torch.float32)
output = elu(x, alpha = 1).detach().numpy()
print(output)
# [[[[-0.9975212  -0.99326205 -0.9816844 ]
#   [-0.95021296 -0.86466473 -0.63212055]]
#
#  [[ 0.          1.          2.        ]
#   [ 3.          4.          5.        ]]]]

# MindSpore
import mindspore as ms
from mindspore import ops
import numpy as np

x_ = np.array([[np.arange(-6,0).reshape(2, 3),np.arange(0,6).reshape(2, 3)]])
x = ms.Tensor(x_, ms.float32)
output = ops.elu(x)
print(output)
# [[[[-0.9975212  -0.99326205 -0.9816844 ]
#    [-0.95021296 -0.86466473 -0.6321205 ]]
#
#   [[ 0.          1.          2.        ]
#    [ 3.          4.          5.        ]]]]