From 3903baded4fc0beaad91382a7a5c4910e74a1e05 Mon Sep 17 00:00:00 2001 From: Yasin <61509470+aiyasin@users.noreply.github.com> Date: Tue, 18 May 2021 20:51:06 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E8=AE=BA=E6=96=87=E5=A4=8D=E7=8E=B0?= =?UTF-8?q?=E8=90=A5=E3=80=91torch.as=5Ftensor(data,=20dtype=3DNone,=20dev?= =?UTF-8?q?ice=3DNone)=20->=20=20paddle.to=5Ftensor(d=E2=80=A6=20(#586)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * torch.as_tensor(data, dtype=None, device=None) -> paddle.to_tensor(data,dtype=None, place=None, stop_gradient=True) * update * ToTensorMapper --- .../project_convertor/pytorch/api_mapper/ops.py | 17 +++++++++++++++++ x2paddle/project_convertor/pytorch/mapper.py | 2 ++ 2 files changed, 19 insertions(+) diff --git a/x2paddle/project_convertor/pytorch/api_mapper/ops.py b/x2paddle/project_convertor/pytorch/api_mapper/ops.py index 6d52812..619c786 100644 --- a/x2paddle/project_convertor/pytorch/api_mapper/ops.py +++ b/x2paddle/project_convertor/pytorch/api_mapper/ops.py @@ -538,3 +538,20 @@ class LinspaceMapper(Mapper): out2 = "{}.requires_grad_({})".format( out2, self.useful_attrs["requires_grad"]) return out1, out2, out3 + +class ToTensorMapper(Mapper): + def __init__(self, + func_name, + pytorch_api_name, + args, kwargs, + target_name=None): + super().__init__(func_name, pytorch_api_name, args, kwargs, target_name) + + def process_attrs(self): + rename_key(self.kwargs, "device", "place") + def run(self): + if self.rename_func_name("paddle.to_tensor"): + return [], generate_api_code(self.func_name, self.args, self.kwargs), [] + else: + self.convert_args2kwargs() + return self.convert_to_paddle() \ No newline at end of file diff --git a/x2paddle/project_convertor/pytorch/mapper.py b/x2paddle/project_convertor/pytorch/mapper.py index c139a2e..452e023 100644 --- a/x2paddle/project_convertor/pytorch/mapper.py +++ b/x2paddle/project_convertor/pytorch/mapper.py @@ -25,6 +25,7 @@ OPTIMIZER_MAPPER = { ["paddle.optimizer.lr.MultiStepDecay", LRScheculerMapper], "torch.optim.Adam": ["x2paddle.torch2paddle.Adam", None], "torch.optim.SGD": ["x2paddle.torch2paddle.Momentum", None] + } NN_MAPPER = { @@ -292,6 +293,7 @@ API_MAPPER = { "torch.mul": ["paddle.multiply", TwoMathMapper], "torch.einsum": ["paddlenlp.ops.einsum ", None], "torch.linspace": ["paddle.linspace", LinspaceMapper], + "torch.as_tensor": ["paddle.to_tensor", ToTensorMapper], } INVALID_API = { "torch.channels_last": ["None", None], -- GitLab