Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加单测调用多样性检测工具 Validate Unittest #328

Merged
merged 14 commits into from
Nov 14, 2023
20 changes: 17 additions & 3 deletions paconvert/api_mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@
"torch.Tensor.apply_": {},
"torch.Tensor.arccos": {
"Matcher": "GenericMatcher",
"min_input_args": 0,
"paddle_api": "paddle.Tensor.acos"
},
"torch.Tensor.arccos_": {
Expand All @@ -263,6 +264,7 @@
},
"torch.Tensor.arccosh": {
"Matcher": "GenericMatcher",
"min_input_args": 0,
"paddle_api": "paddle.Tensor.acosh"
},
"torch.Tensor.arccosh_": {
Expand All @@ -271,7 +273,8 @@
"paddle_api": "paddle.Tensor.acosh_"
},
"torch.Tensor.arcsin": {
"Matcher": "UnchangeMatcher"
"Matcher": "UnchangeMatcher",
"min_input_args": 0
},
"torch.Tensor.arcsin_": {
"Matcher": "GenericMatcher",
Expand Down Expand Up @@ -354,7 +357,8 @@
},
"torch.Tensor.argwhere": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.Tensor.nonzero"
"paddle_api": "paddle.Tensor.nonzero",
"min_input_args": 0
},
"torch.Tensor.as_strided": {
"Matcher": "GenericMatcher",
Expand Down Expand Up @@ -420,6 +424,7 @@
"Matcher": "TensorBF16Matcher",
"min_input_args": 0,
"args_list": [
"*",
"memory_format"
]
},
Expand Down Expand Up @@ -527,6 +532,7 @@
"Matcher": "TensorBoolMatcher",
"min_input_args": 0,
"args_list": [
"*",
"memory_format"
]
},
Expand All @@ -545,6 +551,7 @@
"Matcher": "TensorByteMatcher",
"min_input_args": 0,
"args_list": [
"*",
"memory_format"
]
},
Expand All @@ -553,6 +560,7 @@
"Matcher": "TensorCdoubleMatcher",
"min_input_args": 0,
"args_list": [
"*",
"memory_format"
]
},
Expand All @@ -567,6 +575,7 @@
"Matcher": "TensorCfloatMatcher",
"min_input_args": 0,
"args_list": [
"*",
"memory_format"
]
},
Expand All @@ -575,6 +584,7 @@
"Matcher": "TensorCharMatcher",
"min_input_args": 0,
"args_list": [
"*",
"memory_format"
]
},
Expand Down Expand Up @@ -791,6 +801,7 @@
"min_input_args": 1,
"args_list": [
"dim",
"*",
"dtype"
],
"kwargs_change": {
Expand Down Expand Up @@ -948,6 +959,7 @@
"Matcher": "TensorDoubleMatcher",
"min_input_args": 0,
"args_list": [
"*",
"memory_format"
]
},
Expand Down Expand Up @@ -2533,7 +2545,7 @@
"torch.Tensor.roll": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.Tensor.roll",
"min_input_args": 2,
"min_input_args": 1,
"args_list": [
"shifts",
"dims"
Expand Down Expand Up @@ -8741,6 +8753,7 @@
"torch.nn.NLLLoss": {
"Matcher": "SizeAverageMatcher",
"paddle_api": "paddle.nn.NLLLoss",
"min_input_args": 0,
"args_list": [
"weight",
"size_average",
Expand Down Expand Up @@ -11744,6 +11757,7 @@
"torch.roll": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.roll",
"min_input_args": 2,
"args_list": [
"input",
"shifts",
Expand Down
4 changes: 2 additions & 2 deletions tests/test_Tensor_absolute.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_case_3():
"""
import torch
try:
a = torch.tensor([[-4, 9], [-23, 2]])
a = torch.tensor([[-4, 9], [-23, 2]]).absolute()
assert 0, "Raise AssertionError"
except Exception as e:
error_msg = str(e)
Expand All @@ -60,7 +60,7 @@ def test_case_4():
"""
import torch
try:
a = torch.tensor([[-4, 9], [-23, 2]])
a = torch.tensor([[-4, 9], [-23, 2]]).absolute()
assert 0, "Raise AssertionError"
except Exception as e:
error_msg = str(e)
Expand Down
13 changes: 12 additions & 1 deletion tests/test_Tensor_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,19 @@ def test_case_5():
obj.run(pytorch_code, ["result"])


def test_case_6():
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.tensor([1., 2, 3])
result = x.add(alpha=0.8, other=torch.tensor([1., 4, 6]))
"""
)
obj.run(pytorch_code, ["result"])


# paddle not support type promote and x/y must have same dtype
def _test_case_6():
def _test_case_7():
pytorch_code = textwrap.dedent(
"""
import torch
Expand Down
15 changes: 13 additions & 2 deletions tests/test_Tensor_add_.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,19 @@ def test_case_4():
obj.run(pytorch_code, ["x"])


def test_case_5():
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.tensor([1., 2, 3])
x.add_(alpha=0.8, other=torch.tensor([1., 4, 6]))
"""
)
obj.run(pytorch_code, ["x"])


# paddle not support type promote and x/y must have same dtype
def _test_case_5():
def _test_case_6():
pytorch_code = textwrap.dedent(
"""
import torch
Expand All @@ -77,7 +88,7 @@ def _test_case_5():


# paddle not support type promote and x/y must have same dtype
def _test_case_6():
def _test_case_7():
pytorch_code = textwrap.dedent(
"""
import torch
Expand Down
13 changes: 13 additions & 0 deletions tests/test_Tensor_addbmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,16 @@ def test_case_4():
"""
)
obj.run(pytorch_code, ["result"])


def test_case_5():
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([[[4., 5., 6.], [1., 2., 3.]]])
b = torch.tensor([[[1., 2., 3.], [4., 5., 6.], [7., 8., 9.]]])
input = torch.tensor([[1., 2., 3.], [4., 5., 6.]])
result = input.addbmm(beta=3, alpha=3, batch2=b, batch1=a)
"""
)
obj.run(pytorch_code, ["result"])
28 changes: 28 additions & 0 deletions tests/test_Tensor_addcdiv.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,31 @@ def test_case_4():
"""
)
obj.run(pytorch_code, ["result"])


def test_case_5():
pytorch_code = textwrap.dedent(
"""
import torch
tensor1 = torch.tensor([1., 2., 3.])
tensor2 = torch.tensor([4., 5., 6.])
input = torch.tensor([7., 8., 9.])
value = 5
result = input.addcdiv(tensor1=tensor1, tensor2=tensor2, value=value)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_6():
pytorch_code = textwrap.dedent(
"""
import torch
tensor1 = torch.tensor([1., 2., 3.])
tensor2 = torch.tensor([4., 5., 6.])
input = torch.tensor([7., 8., 9.])
value = 5
result = input.addcdiv(value=value, tensor2=tensor2, tensor1=tensor1)
"""
)
obj.run(pytorch_code, ["result"])
28 changes: 28 additions & 0 deletions tests/test_Tensor_addcmul.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,31 @@ def test_case_4():
"""
)
obj.run(pytorch_code, ["result"])


def test_case_5():
pytorch_code = textwrap.dedent(
"""
import torch
tensor1 = torch.tensor([1., 2., 3.])
tensor2 = torch.tensor([4., 5., 6.])
input = torch.tensor([7., 8., 9.])
value = 5
result = input.addcmul(tensor1=tensor1, tensor2=tensor2, value=value)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_6():
pytorch_code = textwrap.dedent(
"""
import torch
tensor1 = torch.tensor([1., 2., 3.])
tensor2 = torch.tensor([4., 5., 6.])
input = torch.tensor([7., 8., 9.])
value = 5
result = input.addcmul(tensor1=tensor1, value=value, tensor2=tensor2)
"""
)
obj.run(pytorch_code, ["result"])
13 changes: 13 additions & 0 deletions tests/test_Tensor_addmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,16 @@ def test_case_5():
"""
)
obj.run(pytorch_code, ["result"])


def test_case_6():
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.tensor([[1., 2], [4, 5]])
mat1 = torch.tensor([[1., 2], [4, 5]])
mat2 = torch.tensor([[1., 2], [4, 5]])
result = x.addmm(beta=0.6, alpha=0.7, mat1=mat1, mat2=mat2)
"""
)
obj.run(pytorch_code, ["result"])
13 changes: 13 additions & 0 deletions tests/test_Tensor_addmm_.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,16 @@ def test_case_6():
"""
)
obj.run(pytorch_code, ["x"])


def test_case_7():
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.tensor([[1., 2], [4, 5]])
mat1 = torch.tensor([[1., 2], [4, 5]])
mat2 = torch.tensor([[1., 2], [4, 5]])
x.addmm_(mat1=mat1, mat2=mat2, alpha=0.7, beta=0.6)
"""
)
obj.run(pytorch_code, ["x"])
13 changes: 13 additions & 0 deletions tests/test_Tensor_addmv.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,16 @@ def test_case_4():
"""
)
obj.run(pytorch_code, ["result"])


def test_case_5():
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([[1., 2., 3.], [4., 5., 6.]])
b = torch.tensor([1., 2., 3.])
input = torch.tensor([1., 2.])
result = input.addmv(alpha=3, mat=a, beta=3, vec=b)
"""
)
obj.run(pytorch_code, ["result"])
13 changes: 13 additions & 0 deletions tests/test_Tensor_addmr.py → tests/test_Tensor_addr.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,16 @@ def test_case_4():
"""
)
obj.run(pytorch_code, ["result"])


def test_case_5():
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([4., 5., 6.])
b = torch.tensor([1., 2., 3.])
input = torch.tensor([1., 2., 3.])
result = input.addr(vec1=a, alpha=3, vec2=b, beta=3)
"""
)
obj.run(pytorch_code, ["result"])
11 changes: 11 additions & 0 deletions tests/test_Tensor_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,14 @@ def test_case_5():
"""
)
obj.run(pytorch_code, ["result"])


def test_case_6():
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.rand(4, 3)
result = a.all(keepdim=False, dim=0)
"""
)
obj.run(pytorch_code, ["result"])
30 changes: 30 additions & 0 deletions tests/test_Tensor_allclose.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,33 @@ def test_case_5():
"""
)
obj.run(pytorch_code, ["result"])


def test_case_6():
pytorch_code = textwrap.dedent(
"""
import torch
result = torch.tensor([10000., 1e-07]).allclose(torch.tensor([10000.1, 1e-08]), 1e-5, 2., False)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_7():
pytorch_code = textwrap.dedent(
"""
import torch
result = torch.tensor([10000., 1e-07]).allclose(other=torch.tensor([10000.1, 1e-08]), rtol=1e-5, atol=2., equal_nan=False)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_8():
pytorch_code = textwrap.dedent(
"""
import torch
result = torch.tensor([10000., 1e-07]).allclose(rtol=1e-5, other=torch.tensor([10000.1, 1e-08]), atol=2., equal_nan=False)
"""
)
obj.run(pytorch_code, ["result"])
Loading