Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions paconvert/api_mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -11006,15 +11006,7 @@
"Matcher": "ChangePrefixMatcher"
},
"torch.relu": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.nn.functional.relu",
"min_input_args": 1,
"args_list": [
"input"
],
"kwargs_change": {
"input": "x"
}
"Matcher": "ChangePrefixMatcher"
},
"torch.remainder": {
"Matcher": "ChangePrefixMatcher"
Expand Down
130 changes: 130 additions & 0 deletions tests/test_nn_functional_leaky_relu.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,133 @@ def test_case_8():
"""
)
obj.run(pytorch_code, ["result"])


def test_case_9():
"""1D tensor input"""
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn.functional as F
x = torch.tensor([-1.5, -0.5, 0.0, 0.5, 1.5])
result = F.leaky_relu(x)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_10():
"""2D tensor input"""
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn.functional as F
x = torch.tensor([[-1.0, 2.0], [3.0, -4.0]])
result = F.leaky_relu(x, 0.1)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_11():
"""float64 dtype"""
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn.functional as F
x = torch.tensor([-1.5, -0.5, 0.0, 0.5, 1.5], dtype=torch.float64)
result = F.leaky_relu(x, negative_slope=0.2)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_12():
"""4D tensor (batch, channel, height, width)"""
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn.functional as F
x = torch.tensor([[[[-1.0, 2.0], [3.0, -4.0]], [[0.5, -0.5], [-1.5, 1.5]]]])
result = F.leaky_relu(x, 0.1)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_13():
"""All negative values"""
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn.functional as F
x = torch.tensor([-1.0, -2.0, -3.0, -4.0])
result = F.leaky_relu(x, 0.2)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_14():
"""Default negative_slope (0.01)"""
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn.functional as F
x = torch.tensor([-10.0, -5.0, 0.0, 5.0, 10.0])
result = F.leaky_relu(x)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_15():
"""Small negative_slope"""
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn.functional as F
x = torch.tensor([-1.0, 0.0, 1.0, 2.0])
result = F.leaky_relu(x, 0.05)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_16():
"""Large negative_slope"""
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn.functional as F
x = torch.tensor([-2.0, -1.0, 0.0, 1.0, 2.0])
result = F.leaky_relu(x, negative_slope=0.5)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_17():
"""Expression as input"""
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn.functional as F
x = torch.tensor([1.0, 2.0, 3.0])
result = F.leaky_relu(x - 2.0, 0.1)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_18():
"""3D tensor"""
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn.functional as F
x = torch.tensor([[[-1.0, 0.5, 1.0], [2.0, -0.5, -1.5]]])
result = F.leaky_relu(x, negative_slope=0.15)
"""
)
obj.run(pytorch_code, ["result"])
91 changes: 91 additions & 0 deletions tests/test_nn_functional_leaky_relu_.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,94 @@ def test_case_6():
"""
)
obj.run(pytorch_code, ["x"])


def test_case_7():
"""1D tensor input"""
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn.functional as F
x = torch.tensor([-1.5, -0.5, 0.0, 0.5, 1.5])
F.leaky_relu_(x)
"""
)
obj.run(pytorch_code, ["x"])


def test_case_8():
"""2D tensor input"""
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn.functional as F
x = torch.tensor([[-1.0, 2.0], [3.0, -4.0]])
F.leaky_relu_(x, 0.1)
"""
)
obj.run(pytorch_code, ["x"])


def test_case_9():
"""float64 dtype"""
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn.functional as F
x = torch.tensor([-1.5, -0.5, 0.0, 0.5, 1.5], dtype=torch.float64)
F.leaky_relu_(x, negative_slope=0.2)
"""
)
obj.run(pytorch_code, ["x"])


def test_case_10():
"""4D tensor (batch, channel, height, width)"""
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn.functional as F
x = torch.tensor([[[[-1.0, 2.0], [3.0, -4.0]], [[0.5, -0.5], [-1.5, 1.5]]]])
F.leaky_relu_(x, 0.1)
"""
)
obj.run(pytorch_code, ["x"])


def test_case_11():
"""All negative values"""
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn.functional as F
x = torch.tensor([-1.0, -2.0, -3.0, -4.0])
F.leaky_relu_(x, 0.2)
"""
)
obj.run(pytorch_code, ["x"])


def test_case_12():
"""3D tensor"""
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn.functional as F
x = torch.tensor([[[-1.0, 0.5, 1.0], [2.0, -0.5, -1.5]]])
F.leaky_relu_(x, negative_slope=0.15)
"""
)
obj.run(pytorch_code, ["x"])


def test_case_13():
"""Large negative_slope"""
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn.functional as F
x = torch.tensor([-2.0, -1.0, 0.0, 1.0, 2.0])
F.leaky_relu_(x, negative_slope=0.5)
"""
)
obj.run(pytorch_code, ["x"])
130 changes: 130 additions & 0 deletions tests/test_nn_functional_relu.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,133 @@ def test_case_10():
"""
)
obj.run(pytorch_code, ["result"])


def test_case_11():
"""1D tensor input"""
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn.functional as F
x = torch.tensor([-1.5, -0.5, 0.0, 0.5, 1.5])
result = F.relu(x)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_12():
"""2D tensor input"""
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn.functional as F
x = torch.tensor([[-1.0, 2.0], [3.0, -4.0]])
result = F.relu(x)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_13():
"""float64 dtype"""
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn.functional as F
x = torch.tensor([-1.5, -0.5, 0.0, 0.5, 1.5], dtype=torch.float64)
result = F.relu(x)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_14():
"""4D tensor (batch, channel, height, width)"""
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn.functional as F
x = torch.tensor([[[[-1.0, 2.0], [3.0, -4.0]], [[0.5, -0.5], [-1.5, 1.5]]]])
result = F.relu(x)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_15():
"""All negative values"""
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn.functional as F
x = torch.tensor([-1.0, -2.0, -3.0, -4.0])
result = F.relu(x)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_16():
"""All positive values"""
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn.functional as F
x = torch.tensor([1.0, 2.0, 3.0, 4.0])
result = F.relu(x)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_17():
"""All zeros"""
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn.functional as F
x = torch.tensor([0.0, 0.0, 0.0])
result = F.relu(x)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_18():
"""Mixed positive and negative values"""
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn.functional as F
x = torch.tensor([-1.0, 0.0, 1.0, 2.0])
result = F.relu(x)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_19():
"""Variable as input"""
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn.functional as F
data = torch.tensor([-2.0, -1.0, 0.0, 1.0, 2.0])
result = F.relu(data)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_20():
"""Expression as input"""
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn.functional as F
x = torch.tensor([1.0, 2.0, 3.0])
result = F.relu(x - 2.0)
"""
)
obj.run(pytorch_code, ["result"])
Loading