Skip to content

Commit

Permalink
单测case覆盖3 (#457)
Browse files Browse the repository at this point in the history
* CaseAdd3

* CaseAdd3

* CaseAdd3

* CaseAdd3
  • Loading branch information
Xuxuanang authored Sep 3, 2024
1 parent 1d762c0 commit 78fd805
Show file tree
Hide file tree
Showing 19 changed files with 728 additions and 19 deletions.
9 changes: 6 additions & 3 deletions paconvert/api_mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -10121,6 +10121,9 @@
],
"kwargs_change": {
"dim": "axis"
},
"paddle_default_kwargs": {
"axis": 0
}
},
"torch.nn.MSELoss": {
Expand Down Expand Up @@ -10771,9 +10774,6 @@
"bias_hh_attr"
]
},
"unsupport_args": [
"proj_size"
],
"min_input_args": 3
},
"torch.nn.RNNCell": {
Expand Down Expand Up @@ -10952,6 +10952,9 @@
],
"kwargs_change": {
"dim": "axis"
},
"paddle_default_kwargs": {
"axis": 0
}
},
"torch.nn.Softmax2d": {
Expand Down
6 changes: 3 additions & 3 deletions paconvert/api_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ def get_paddle_class_attribute_nodes(self, node):
def get_paddle_nodes(self, args, kwargs):
new_args = self.parse_args(args)
new_kwargs = self.parse_kwargs(kwargs)
if new_kwargs is not None and new_args is not None:
if new_kwargs is not None:
code = "{}({})".format(
self.get_paddle_api(), self.args_and_kwargs_to_str(new_args, new_kwargs)
)
Expand Down Expand Up @@ -3829,8 +3829,8 @@ def generate_code(self, kwargs):
class SoftmaxMatcher(BaseMatcher):
def generate_code(self, kwargs):
if "dim" not in kwargs or "None" in kwargs["dim"]:
return None

kwargs.pop("dim", "None")
kwargs["axis"] = 0
return GenericMatcher.generate_code(self, kwargs)


Expand Down
57 changes: 57 additions & 0 deletions tests/test_max_pool2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,60 @@ def test_case_5():
"""
)
obj.run(pytorch_code, ["result"])


def test_case_6():
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.tensor([[[[ 1.1524, 0.4714, 0.2857],
[-1.2533, -0.9829, -1.0981],
[ 0.1507, -1.1431, -2.0361]],
[[ 0.1024, -0.4482, 0.4137],
[ 0.9385, 0.4565, 0.7702],
[ 0.4135, -0.2587, 0.0482]]]])
result = torch.max_pool2d(input=input, kernel_size=3, stride=(2, 1), padding=1, dilation=1, ceil_mode=True)
"""
)
obj.run(
pytorch_code, ["result"], unsupport=True, reason="dilation is not supported now"
)


def test_case_7():
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.tensor([[[[ 1.1524, 0.4714, 0.2857],
[-1.2533, -0.9829, -1.0981],
[ 0.1507, -1.1431, -2.0361]],
[[ 0.1024, -0.4482, 0.4137],
[ 0.9385, 0.4565, 0.7702],
[ 0.4135, -0.2587, 0.0482]]]])
result = torch.max_pool2d(input=input, stride=(2, 1), kernel_size=3, dilation=1, padding=1, ceil_mode=True)
"""
)
obj.run(
pytorch_code, ["result"], unsupport=True, reason="dilation is not supported now"
)


def test_case_8():
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.tensor([[[[ 1.1524, 0.4714, 0.2857],
[-1.2533, -0.9829, -1.0981],
[ 0.1507, -1.1431, -2.0361]],
[[ 0.1024, -0.4482, 0.4137],
[ 0.9385, 0.4565, 0.7702],
[ 0.4135, -0.2587, 0.0482]]]])
result = torch.max_pool2d(input, 3, (2, 1), 1, 1, True)
"""
)
obj.run(
pytorch_code, ["result"], unsupport=True, reason="dilation is not supported now"
)
26 changes: 26 additions & 0 deletions tests/test_max_pool3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,29 @@ def test_case_5():
check_dtype=False,
reason="torch indices dtype is int64, while paddle is int32",
)


def test_case_6():
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.arange(4800, dtype=torch.float32).reshape(2, 3, 8, 10, 10)
result = torch.max_pool3d(input=input, kernel_size=(2, 2, 2), stride=(2, 1, 1), padding=1, dilation=1, ceil_mode=True)
"""
)
obj.run(
pytorch_code, ["result"], unsupport=True, reason="dilation is not suppored now"
)


def test_case_7():
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.arange(4800, dtype=torch.float32).reshape(2, 3, 8, 10, 10)
result = torch.max_pool3d(input=input, dilation=1, kernel_size=(2, 2, 2), padding=1, stride=(2, 1, 1), ceil_mode=True)
"""
)
obj.run(
pytorch_code, ["result"], unsupport=True, reason="dilation is not suppored now"
)
24 changes: 24 additions & 0 deletions tests/test_mean.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,27 @@ def test_case_6():
"""
)
obj.run(pytorch_code, ["result"])


def test_case_7():
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.tensor([[1.4907, 1.0593, 1.5696], [1.4907, 1.0593, 1.5696]])
out = torch.tensor([[1.4907, 1.0593, 1.5696], [1.4907, 1.0593, 1.5696]], dtype=torch.float64)
result = torch.mean(input=input, dim=1, keepdim=True, dtype=torch.float64, out=out)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_8():
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.tensor([[1.4907, 1.0593, 1.5696], [1.4907, 1.0593, 1.5696]])
out = torch.tensor([[1.4907, 1.0593, 1.5696], [1.4907, 1.0593, 1.5696]], dtype=torch.float64)
result = torch.mean(input=input, keepdim=True, dim=1, out=out, dtype=torch.float64)
"""
)
obj.run(pytorch_code, ["result"])
24 changes: 24 additions & 0 deletions tests/test_min.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,27 @@ def test_case_12():
"""
)
obj.run(pytorch_code, ["result", "out"])


def test_case_13():
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.tensor([[1, 2, 1], [3, 4, 6]])
out = [torch.tensor(0), torch.tensor(1)]
result = torch.min(input=x, dim=1, keepdim=False, out=out)
"""
)
obj.run(pytorch_code, ["result", "out"])


def test_case_14():
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.tensor([[1, 2, 1], [3, 4, 6]])
out = [torch.tensor(0), torch.tensor(1)]
result = torch.min(input=x, keepdim=False, dim=1, out=out)
"""
)
obj.run(pytorch_code, ["result", "out"])
57 changes: 56 additions & 1 deletion tests/test_nn_ConvTranspose1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,30 @@ def test_case_5():
"""
import torch
import torch.nn as nn
x = torch.randn(5, 16, 50)
model = nn.ConvTranspose1d(in_channels=16, out_channels=33, kernel_size=5, stride=1, padding=4, output_padding=0, groups=1, bias=True, dilation=3,
padding_mode='zeros', device=None, dtype=None)
result = model(x)
"""
)
obj.run(
pytorch_code,
["result"],
unsupport=True,
reason="Paddle does not support parameter of padding_mode",
)


def test_case_6():
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn as nn
x = torch.randn(5, 16, 50)
model = nn.ConvTranspose1d(16, 33, 5, stride=1, padding=4, dilation=3, bias=True, padding_mode='zeros')
model = nn.ConvTranspose1d(in_channels=16, kernel_size=5, out_channels=33, stride=1, padding=4, device=None, groups=1, bias=True, output_padding=0, dilation=3,
padding_mode='zeros', dtype=None)
result = model(x)
"""
)
Expand All @@ -87,3 +109,36 @@ def test_case_5():
unsupport=True,
reason="Paddle does not support parameter of padding_mode",
)


def test_case_7():
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn as nn
x = torch.randn(5, 16, 50)
model = nn.ConvTranspose1d(16, 33, 5, 1, 4, 0, 1, True, 3, 'zeros', None, None)
result = model(x)
"""
)
obj.run(
pytorch_code,
["result"],
unsupport=True,
reason="Paddle does not support parameter of padding_mode",
)


def test_case_8():
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn as nn
x = torch.randn(5, 16, 50)
model = nn.ConvTranspose1d(16, 33, 5)
result = model(x)
"""
)
obj.run(pytorch_code, ["result"], check_value=False)
85 changes: 85 additions & 0 deletions tests/test_nn_ConvTranspose2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,88 @@ def test_case_5():
unsupport=True,
reason="Paddle does not support parameter of padding_mode",
)


def test_case_6():
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn as nn
x = torch.randn(5, 16, 50, 100)
model = nn.ConvTranspose2d(16, 33, (3, 5), stride=(2, 1), padding=(4, 2), dilation=(3, 1), bias=True, padding_mode='zeros')
result = model(x)
"""
)
obj.run(
pytorch_code,
["result"],
unsupport=True,
reason="Paddle does not support parameter of padding_mode",
)


def test_case_7():
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn as nn
x = torch.randn(5, 16, 50, 100)
model = nn.ConvTranspose2d(in_channels=16, out_channels=33, kernel_size=(3, 5), stride=(2, 1), padding=(4, 2), output_padding=0, groups=1, bias=True, dilation=(3, 1), padding_mode='zeros', device=None, dtype=None)
result = model(x)
"""
)
obj.run(
pytorch_code,
["result"],
unsupport=True,
reason="Paddle does not support parameter of padding_mode",
)


def test_case_8():
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn as nn
x = torch.randn(5, 16, 50, 100)
model = nn.ConvTranspose2d(in_channels=16, output_padding=0, kernel_size=(3, 5), stride=(2, 1), padding=(4, 2), groups=1, bias=True, out_channels=33, dilation=(3, 1), padding_mode='zeros', device=None, dtype=None)
result = model(x)
"""
)
obj.run(
pytorch_code,
["result"],
unsupport=True,
reason="Paddle does not support parameter of padding_mode",
)


def test_case_9():
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn as nn
x = torch.randn(5, 16, 50, 100)
model = nn.ConvTranspose2d(16, 33, (3, 5), (2, 1), (4, 2), 0, 1, True, (3, 1), 'zeros', None, None)
result = model(x)
"""
)
obj.run(
pytorch_code,
["result"],
unsupport=True,
reason="Paddle does not support parameter of padding_mode",
)


def test_case_10():
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn as nn
x = torch.randn(5, 16, 50, 100)
model = nn.ConvTranspose2d(16, 33, (3, 5))
result = model(x)
"""
)
obj.run(pytorch_code, ["result"], check_value=False)
Loading

0 comments on commit 78fd805

Please sign in to comment.