#79628·Paddle

paddle.nn.functional.elu backward returns 0.0 for finite float64 gradient at x=-40

Author: ALinrunrunCreated Aug 6, 2026Updated Aug 6, 2026
Labelsstatus/new-issuetype/bug-report

bug描述 Describe the Bug

paddle.nn.functional.elu has an incorrect backward result for float64 input x = -40.0.

For ELU with the default alpha=1.0, when x < 0, the function is:

elu(x) = exp(x) - 1

Therefore its derivative is:

d/dx elu(x) = exp(x)

At x = -40.0, the correct derivative is:

exp(-40.0) = 4.248354255291589e-18

This is a finite, normal float64 value. However, Paddle autograd returns 0.0.

Environment

  • PaddlePaddle version: 3.3.1
  • NumPy version: 2.2.6
  • dtype: float64
  • Device: CPU

Minimal reproducible code

python
import numpy as np
import paddle
import paddle.nn.functional as F

paddle.set_device("cpu")

x = paddle.to_tensor(
    -40.0,
    dtype="float64",
    stop_gradient=False,
)

y = F.elu(x)
y.backward()

wrong = float(x.grad)
expected = float(np.exp(np.float64(-40.0)))

print("wrong:", wrong)
print("expected:", expected)

Actual behavior

bash
wrong: 0.0

Expected behavior

bash
expected: 4.248354255291589e-18

paddle.nn.functional.elu backward should return exp(x) for negative inputs when alpha=1.0.

For x = -40.0, the correct gradient is finite and representable in float64, but Paddle returns 0.0.

其他补充信息 Additional Supplementary Information

No response