diff --git a/paconvert/api_alias_mapping.json b/paconvert/api_alias_mapping.json index e52062a78..bc7845bb3 100644 --- a/paconvert/api_alias_mapping.json +++ b/paconvert/api_alias_mapping.json @@ -34,5 +34,6 @@ "torch.utils.data.sampler.BatchSampler": "torch.utils.data.BatchSampler", "torch.utils.data.sampler.RandomSampler": "torch.utils.data.RandomSampler", "torch.utils.data.sampler.Sampler": "torch.utils.data.Sampler", - "torch.utils.data.sampler.SequentialSampler": "torch.utils.data.SequentialSampler" + "torch.utils.data.sampler.SequentialSampler": "torch.utils.data.SequentialSampler", + "torch.utils.model_zoo.load_url": "torch.hub.load_state_dict_from_url" } diff --git a/paconvert/api_mapping.json b/paconvert/api_mapping.json index cf850121e..ad47fc2ab 100644 --- a/paconvert/api_mapping.json +++ b/paconvert/api_mapping.json @@ -5102,6 +5102,25 @@ "out" ] }, + "torch.hub.load_state_dict_from_url": { + "Matcher": "GenericMatcher", + "paddle_api": "paddle.utils.download.get_weights_path_from_url", + "args_list": [ + "url", + "model_dir", + "map_location", + "progress", + "check_hash", + "file_name" + ], + "unsupport_args": [ + "model_dir", + "map_location", + "progress", + "check_hash", + "file_name" + ] + }, "torch.hypot": { "Matcher": "HypotMatcher", "args_list": [ diff --git a/tests/test_hub_load_state_dict_from_url.py b/tests/test_hub_load_state_dict_from_url.py new file mode 100644 index 000000000..a9c307949 --- /dev/null +++ b/tests/test_hub_load_state_dict_from_url.py @@ -0,0 +1,66 @@ +# 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.hub.load_state_dict_from_url") + + +def test_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + state_dict = torch.hub.load_state_dict_from_url('https://s3.amazonaws.com/pytorch/models/resnet18-5c106cde.pth') + result = True + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + result = torch.hub.load_state_dict_from_url('https://s3.amazonaws.com/pytorch/models/resnet18-5c106cde.pth',model_dir="./tests") + """ + ) + obj.run( + pytorch_code, ["result"], unsupport=True, reason="paddle not support this arg" + ) + + +def _test_alias_case_1(): + pytorch_code = textwrap.dedent( + """ + import torch + state_dict = torch.utils.model_zoo.load_url('https://s3.amazonaws.com/pytorch/models/resnet18-5c106cde.pth') + result = True + """ + ) + obj.run(pytorch_code, ["result"]) + + +def test_alias_case_2(): + pytorch_code = textwrap.dedent( + """ + import torch + state_dict = torch.utils.model_zoo.load_url('https://s3.amazonaws.com/pytorch/models/resnet18-5c106cde.pth',model_dir="./tests") + result = True + """ + ) + obj.run( + pytorch_code, ["result"], unsupport=True, reason="paddle not support this arg" + )