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. 126/128 #192

Merged
merged 4 commits into from
Jul 26, 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
14 changes: 14 additions & 0 deletions paconvert/api_mapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -3568,6 +3568,10 @@
"device": "device"
}
},
"torch.cuda.get_rng_state_all": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.get_rng_state"
},
"torch.cuda.is_available": {
"Matcher": "CudaIsAvailableMatcher",
"paddle_api": "paddle.device.cuda.device_count"
Expand Down Expand Up @@ -3629,6 +3633,16 @@
"device": "device"
}
},
"torch.cuda.set_rng_state_all": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.set_rng_state",
"args_list": [
"new_states"
],
"kwargs_change": {
"new_states": "state_list"
}
},
"torch.cuda.synchronize": {
"Matcher": "GenericMatcher",
"paddle_api": "paddle.device.cuda.synchronize",
Expand Down
46 changes: 46 additions & 0 deletions tests/test_cuda_get_rng_state_all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# 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

import paddle
from apibase import APIBase


class GetRngStateAllAPIBase(APIBase):
Copy link
Collaborator

Choose a reason for hiding this comment

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

这个有点奇特,因为返回的是Generator的list,paddle_result应该是一个list,不过为啥没有报错呢

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已修改使用 assert验证

def compare(
self,
name,
pytorch_result,
paddle_result,
check_value=True,
check_dtype=True,
check_stop_gradient=True,
):
if len(paddle_result) == 0:
return True

assert isinstance(paddle_result[0], paddle.fluid.libpaddle.GeneratorState)


obj = GetRngStateAllAPIBase("torch.cuda.get_rng_state_all")


def test_case_1():
pytorch_code = textwrap.dedent(
"""
import torch
result = torch.cuda.get_rng_state_all()
"""
)
obj.run(pytorch_code, ["result"])
31 changes: 31 additions & 0 deletions tests/test_cuda_set_rng_state_all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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.cuda.set_rng_state_all")


def test_case_1():
pytorch_code = textwrap.dedent(
"""
import torch
state_list = torch.cuda.get_rng_state_all()
torch.cuda.set_rng_state_all(state_list)
result = None
"""
)
obj.run(pytorch_code, ["result"])