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
13 changes: 1 addition & 12 deletions paconvert/api_mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -11791,18 +11791,7 @@
}
},
"torch.special.logit": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.logit",
"min_input_args": 1,
"args_list": [
"input",
"eps",
"*",
"out"
],
"kwargs_change": {
"input": "x"
}
"Matcher": "ChangePrefixMatcher"
},
"torch.special.logsumexp": {
"Matcher": "ChangePrefixMatcher"
Expand Down
61 changes: 61 additions & 0 deletions tests/test_Tensor_logit.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,64 @@ def test_case_4():
"""
)
obj.run(pytorch_code, ["result"])


def test_case_5():
"""2D input with eps"""
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.tensor([[0.2, 0.5, 0.8], [0.1, 0.9, 0.3]])
result = input.logit(eps=1e-6)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_6():
"""3D input, no eps"""
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.tensor([[[0.2, 0.8], [0.4, 0.6]], [[0.1, 0.9], [0.3, 0.7]]])
result = input.logit()
"""
)
obj.run(pytorch_code, ["result"])


def test_case_7():
"""float64 dtype"""
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.tensor([0.2796, 0.9331, 0.6486], dtype=torch.float64)
result = input.logit(eps=1e-6)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_8():
"""Gradient computation"""
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.tensor([0.2796, 0.9331, 0.6486], requires_grad=True)
y = x.logit(eps=1e-6)
y.sum().backward()
x_grad = x.grad
"""
)
obj.run(pytorch_code, ["y", "x_grad"], check_stop_gradient=False)


def test_case_9():
"""Chained call"""
pytorch_code = textwrap.dedent(
"""
import torch
result = torch.tensor([0.2, 0.5, 0.8]).logit(1e-6)
"""
)
obj.run(pytorch_code, ["result"])
124 changes: 124 additions & 0 deletions tests/test_logit.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,127 @@ def test_case_7():
"""
)
obj.run(pytorch_code, ["result", "out"])


def test_case_8():
"""No eps, keyword input="""
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.tensor([0.2796, 0.9331, 0.6486, 0.1523, 0.6516])
result = torch.logit(input=input)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_9():
"""No eps, positional only"""
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.tensor([0.2796, 0.9331, 0.6486, 0.1523, 0.6516])
result = torch.logit(input)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_10():
"""2D input with eps"""
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.tensor([[0.2, 0.5, 0.8], [0.1, 0.9, 0.3]])
result = torch.logit(input, eps=1e-6)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_11():
"""3D input, no eps"""
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.tensor([[[0.2, 0.8], [0.4, 0.6]], [[0.1, 0.9], [0.3, 0.7]]])
result = torch.logit(input)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_12():
"""float64 dtype"""
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.tensor([0.2796, 0.9331, 0.6486], dtype=torch.float64)
result = torch.logit(input, eps=1e-6)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_13():
"""out parameter without eps"""
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.tensor([0.2796, 0.9331, 0.6486, 0.1523, 0.6516])
out = torch.zeros(5)
result = torch.logit(input, out=out)
"""
)
obj.run(pytorch_code, ["result", "out"])


def test_case_14():
"""Reordered kwargs: out, input, eps"""
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.tensor([0.2796, 0.9331, 0.6486, 0.1523, 0.6516])
out = torch.zeros(5)
result = torch.logit(out=out, input=input, eps=1e-6)
"""
)
obj.run(pytorch_code, ["result", "out"])


def test_case_15():
"""Variable unpacking"""
pytorch_code = textwrap.dedent(
"""
import torch
args = (torch.tensor([0.2796, 0.9331, 0.6486, 0.1523, 0.6516]), 1e-6)
result = torch.logit(*args)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_16():
"""Expression as eps argument"""
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.tensor([0.2796, 0.9331, 0.6486, 0.1523, 0.6516])
result = torch.logit(input, 1e-3 * 1e-3)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_17():
"""Gradient computation"""
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.tensor([0.2796, 0.9331, 0.6486], requires_grad=True)
y = torch.logit(x, eps=1e-6)
y.sum().backward()
x_grad = x.grad
"""
)
obj.run(pytorch_code, ["y", "x_grad"], check_stop_gradient=False)
112 changes: 112 additions & 0 deletions tests/test_special_logit.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,115 @@ def test_case_6():
"""
)
obj.run(pytorch_code, ["result"])


def test_case_7():
"""No eps, keyword input="""
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.tensor([0.2796, 0.9331, 0.6486, 0.1523, 0.6516])
result = torch.special.logit(input=input)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_8():
"""2D input with eps"""
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.tensor([[0.2, 0.5, 0.8], [0.1, 0.9, 0.3]])
result = torch.special.logit(input, eps=1e-6)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_9():
"""3D input, no eps"""
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.tensor([[[0.2, 0.8], [0.4, 0.6]], [[0.1, 0.9], [0.3, 0.7]]])
result = torch.special.logit(input)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_10():
"""float64 dtype"""
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.tensor([0.2796, 0.9331, 0.6486], dtype=torch.float64)
result = torch.special.logit(input, eps=1e-6)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_11():
"""out parameter without eps"""
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.tensor([0.2796, 0.9331, 0.6486, 0.1523, 0.6516])
out = torch.zeros(5)
result = torch.special.logit(input, out=out)
"""
)
obj.run(pytorch_code, ["result", "out"])


def test_case_12():
"""Reordered kwargs: out, input, eps"""
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.tensor([0.2796, 0.9331, 0.6486, 0.1523, 0.6516])
out = torch.zeros(5)
result = torch.special.logit(out=out, input=input, eps=1e-6)
"""
)
obj.run(pytorch_code, ["result", "out"])


def test_case_13():
"""Variable unpacking"""
pytorch_code = textwrap.dedent(
"""
import torch
args = (torch.tensor([0.2796, 0.9331, 0.6486, 0.1523, 0.6516]), 1e-6)
result = torch.special.logit(*args)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_14():
"""Expression as eps argument"""
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.tensor([0.2796, 0.9331, 0.6486, 0.1523, 0.6516])
result = torch.special.logit(input, 1e-3 * 1e-3)
"""
)
obj.run(pytorch_code, ["result"])


def test_case_15():
"""Gradient computation"""
pytorch_code = textwrap.dedent(
"""
import torch
x = torch.tensor([0.2796, 0.9331, 0.6486], requires_grad=True)
y = torch.special.logit(x, eps=1e-6)
y.sum().backward()
x_grad = x.grad
"""
)
obj.run(pytorch_code, ["y", "x_grad"], check_stop_gradient=False)