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

转换规则No65 torch.nn.functional.threshold #121

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 14 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
17 changes: 17 additions & 0 deletions paconvert/api_mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -7905,6 +7905,23 @@
"input": "x"
}
},
"torch.nn.functional.threshold": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.nn.functional.thresholded_relu",
"args_list": [
"input",
"threshold",
"value",
"inplace"
],
"kwargs_change": {
"input": "x"
Liyulingyue marked this conversation as resolved.
Show resolved Hide resolved
},
"unsupport_args": [
"value",
"inplace"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个inplace可以改写到kwargs_change里去直接删除:

"kwargs_change": {
    "inplace": ""
}

Liyulingyue marked this conversation as resolved.
Show resolved Hide resolved
]
},
"torch.nn.functional.triplet_margin_with_distance_loss": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.nn.functional.triplet_margin_with_distance_loss",
Expand Down
71 changes: 71 additions & 0 deletions tests/test_nn_functional_threshold.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import textwrap

from apibase import APIBase

obj = APIBase("torch.nn.functional.threshold")


def test_case_1():
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn.functional as F
x = torch.tensor([[[-1.3020, -0.1005, 0.5766, 0.6351, -0.8893, 0.0253, -0.1756, 1.2913],
[-0.8833, -0.1369, -0.0168, -0.5409, -0.1511, -0.1240, -1.1870, -1.8816]]])
result = F.threshold(x, 0, 0, inplace=False)
Liyulingyue marked this conversation as resolved.
Show resolved Hide resolved
"""
)
obj.run(pytorch_code, ["result"])
Liyulingyue marked this conversation as resolved.
Show resolved Hide resolved


def test_case_2():
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn.functional as F
x = torch.tensor([[[-1.3020, -0.1005, 0.5766, 0.6351, -0.8893, 0.0253, -0.1756, 1.2913],
[-0.8833, -0.1369, -0.0168, -0.5409, -0.1511, -0.1240, -1.1870, -1.8816]]])
result = F.threshold(x, 1, 0, inplace=False)
Liyulingyue marked this conversation as resolved.
Show resolved Hide resolved
"""
)
obj.run(pytorch_code, ["result"])


def test_case_3():
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn.functional as F
x = torch.tensor([[[-1.3020, -0.1005, 0.5766, 0.6351, -0.8893, 0.0253, -0.1756, 1.2913],
[-0.8833, -0.1369, -0.0168, -0.5409, -0.1511, -0.1240, -1.1870, -1.8816]]])
result = F.threshold(x, 0, 1, inplace=False)
Liyulingyue marked this conversation as resolved.
Show resolved Hide resolved
"""
)
obj.run(pytorch_code, ["result"])


def test_case_4():
pytorch_code = textwrap.dedent(
"""
import torch
import torch.nn.functional as F
x = torch.tensor([[[-1.3020, -0.1005, 0.5766, 0.6351, -0.8893, 0.0253, -0.1756, 1.2913],
[-0.8833, -0.1369, -0.0168, -0.5409, -0.1511, -0.1240, -1.1870, -1.8816]]])
result = F.threshold(x, 0, 0, inplace=True)
"""
)
obj.run(pytorch_code, ["result"])
Liyulingyue marked this conversation as resolved.
Show resolved Hide resolved