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

转换规则 No. 304/306/308/327-329/332/351/363/365/369/371 #241

Merged
merged 2 commits into from
Aug 28, 2023
Merged
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
71 changes: 71 additions & 0 deletions tests/test_Tensor_bitwise_left_shift_.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.Tensor.bitwise_left_shift_")


def test_case_1():
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.tensor([-2, -7, 31], dtype=torch.int8)
other = torch.tensor([1, 0, 3], dtype=torch.int8)
result = input.bitwise_left_shift_(other)
"""
)
obj.run(
pytorch_code,
["result"],
unsupport=True,
reason="paddle does not support this function temporarily",
)


def test_case_2():
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.tensor([-2, -7, 31], dtype=torch.int8)
other = torch.tensor([1, 0, 3], dtype=torch.int8)
result = input.bitwise_left_shift_(other=other)
"""
)
obj.run(
pytorch_code,
["result"],
unsupport=True,
reason="paddle does not support this function temporarily",
)


def test_case_3():
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.tensor([-2, -7, 31], dtype=torch.int32)
other = torch.tensor([1, 0, 3], dtype=torch.int32)
result = input.bitwise_left_shift_(other=other)
"""
)
obj.run(
pytorch_code,
["result"],
unsupport=True,
reason="paddle does not support this function temporarily",
)
71 changes: 71 additions & 0 deletions tests/test_Tensor_bitwise_right_shift_.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.Tensor.bitwise_right_shift_")


def test_case_1():
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.tensor([-2, -7, 31], dtype=torch.int8)
other = torch.tensor([1, 0, 3], dtype=torch.int8)
result = input.bitwise_right_shift_(other)
"""
)
obj.run(
pytorch_code,
["result"],
unsupport=True,
reason="paddle does not support this function temporarily",
)


def test_case_2():
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.tensor([-2, -7, 31], dtype=torch.int8)
other = torch.tensor([1, 0, 3], dtype=torch.int8)
result = input.bitwise_right_shift_(other=other)
"""
)
obj.run(
pytorch_code,
["result"],
unsupport=True,
reason="paddle does not support this function temporarily",
)


def test_case_3():
pytorch_code = textwrap.dedent(
"""
import torch
input = torch.tensor([-2, -7, 31], dtype=torch.int32)
other = torch.tensor([1, 0, 3], dtype=torch.int32)
result = input.bitwise_right_shift_(other=other)
"""
)
obj.run(
pytorch_code,
["result"],
unsupport=True,
reason="paddle does not support this function temporarily",
)
35 changes: 35 additions & 0 deletions tests/test_Tensor_retains_grad.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 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.Tensor.retains_grad")
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个需要把属性调用形式转写成 函数调用形式,看一下 Attribute2Func 这个Matcher

Copy link
Contributor Author

Choose a reason for hiding this comment

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

paddle中不获取返回值
图片

Copy link
Collaborator

Choose a reason for hiding this comment

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

torch.Tensor.retains_grad这个是功能缺失,torch.Tensor.retain_grad 也一起弄下吧,torch.Tensor.retain_grad 可以和paddle对应上

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已有retain_grad单测 tests/test_Tensor_retain_grad.py,转换为 paddle.Tensor.retain_grads



def test_case_1():
pytorch_code = textwrap.dedent(
"""
import torch
y = torch.Tensor([[1.,2.], [3.,4.]])
result = y.retains_grad()
"""
)
obj.run(
pytorch_code,
["result"],
unsupport=True,
reason="paddle does not support this function temporarily",
)
51 changes: 51 additions & 0 deletions tests/test_autograd_Function_jvp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# 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.autograd.Function.jvp")


def test_case_1():
pytorch_code = textwrap.dedent(
"""
import torch
from torch.autograd import Function

# Inherit from Function
class cus_tanh(Function):
@staticmethod
def forward(ctx, x):
y = torch.autograd.Function.jvp(ctx, x)
return y

@staticmethod
def backward(ctx, dy):
grad = dy + 1
return grad

data = torch.ones([2, 3], dtype=torch.float64)
data.requires_grad = True
result = cus_tanh.apply(data)
"""
)
obj.run(
pytorch_code,
["result"],
unsupport=True,
reason="paddle does not support this function temporarily",
)
51 changes: 51 additions & 0 deletions tests/test_distributed_monitored_barrier.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# 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.distributed.monitored_barrier")


def test_case_1():
pytorch_code = textwrap.dedent(
"""
import torch
torch.distributed.monitored_barrier()
result=True
"""
)
obj.run(
pytorch_code,
["result"],
unsupport=True,
reason="paddle does not support this function temporarily",
)


def test_case_2():
pytorch_code = textwrap.dedent(
"""
import torch
torch.distributed.monitored_barrier(group=None, timeout=None, wait_all_ranks=False)
result=True
"""
)
obj.run(
pytorch_code,
["result"],
unsupport=True,
reason="paddle does not support this function temporarily",
)
35 changes: 35 additions & 0 deletions tests/test_layout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# 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.layout")


def test_case_1():
pytorch_code = textwrap.dedent(
"""
import torch
a = torch.tensor([[4, 9], [23, 2]])
result = torch.layout(a)
"""
)
obj.run(
pytorch_code,
["result"],
unsupport=True,
reason="paddle does not support this function temporarily",
)
55 changes: 55 additions & 0 deletions tests/test_nn_utils_stateless_functional_call.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# 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.utils.stateless.functional_call")


def test_case_1():
pytorch_code = textwrap.dedent(
"""
import torch
a = {'foo': torch.zeros(())}
mod = torch.nn.Module()
m = torch.nn.utils.stateless.functional_call(mod, a, torch.ones(()))
result = a['foo']
"""
)
obj.run(
pytorch_code,
["result"],
unsupport=True,
reason="paddle does not support this function temporarily",
)


def test_case_2():
pytorch_code = textwrap.dedent(
"""
import torch
a = {'foo': torch.zeros(())}
mod = torch.nn.Module()
m = torch.nn.utils.stateless.functional_call(mod, a, torch.ones(()), tie_weights=True, strict=False)
result = a['foo']
"""
)
obj.run(
pytorch_code,
["result"],
unsupport=True,
reason="paddle does not support this function temporarily",
)
Loading