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
20 changes: 2 additions & 18 deletions paconvert/api_mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -431,14 +431,7 @@
]
},
"torch.Tensor.addcmul": {
"Matcher": "AddCMulMatcher",
"min_input_args": 2,
"args_list": [
"tensor1",
"tensor2",
"*",
"value"
]
"Matcher": "ChangePrefixMatcher"
},
"torch.Tensor.addcmul_": {
"Matcher": "AddCMul_Matcher",
Expand Down Expand Up @@ -3681,16 +3674,7 @@
]
},
"torch.addcmul": {
"Matcher": "AddCMulMatcher",
"min_input_args": 3,
"args_list": [
"input",
"tensor1",
"tensor2",
"*",
"value",
"out"
]
"Matcher": "ChangePrefixMatcher"
},
"torch.addmm": {
"Matcher": "GenericMatcher",
Expand Down
72 changes: 72 additions & 0 deletions tests/test_Tensor_addcmul.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,75 @@ def test_case_6():
"""
)
obj.run(pytorch_code, ["result"])


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


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


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


def test_case_10():
"""gradient computation test"""
pytorch_code = textwrap.dedent(
"""
import torch
tensor1 = torch.tensor([1., 2., 3.], requires_grad=True)
tensor2 = torch.tensor([4., 5., 6.], requires_grad=True)
input = torch.tensor([7., 8., 9.], requires_grad=True)
result = input.addcmul(tensor1, tensor2, value=2.0)
result.sum().backward()
input_grad = input.grad
"""
)
obj.run(pytorch_code, ["result", "input_grad"], check_stop_gradient=False)


def test_case_11():
"""expression argument test"""
pytorch_code = textwrap.dedent(
"""
import torch
tensor1 = torch.tensor([1., 2., 3.])
tensor2 = torch.tensor([4., 5., 6.])
input = torch.tensor([7., 8., 9.])
result = input.addcmul(tensor1, tensor2, value=1 + 1)
"""
)
obj.run(pytorch_code, ["result"])
72 changes: 72 additions & 0 deletions tests/test_addcmul.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,75 @@ def test_case_7():
"""
)
obj.run(pytorch_code, ["result"])


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


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


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


def test_case_11():
"""gradient computation test"""
pytorch_code = textwrap.dedent(
"""
import torch
tensor1 = torch.tensor([1., 2., 3.], requires_grad=True)
tensor2 = torch.tensor([4., 5., 6.], requires_grad=True)
input = torch.tensor([7., 8., 9.], requires_grad=True)
result = torch.addcmul(input, tensor1, tensor2, value=2.0)
result.sum().backward()
input_grad = input.grad
"""
)
obj.run(pytorch_code, ["result", "input_grad"], check_stop_gradient=False)


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