未验证 提交 3903bade 编写于 作者: Y Yasin 提交者: GitHub

【论文复现营】torch.as_tensor(data, dtype=None, device=None) -> paddle.to_tensor(d… (#586)

* torch.as_tensor(data, dtype=None, device=None) ->  paddle.to_tensor(data,dtype=None, place=None, stop_gradient=True)

* update

* ToTensorMapper
上级 30e35c98
......@@ -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
......@@ -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],
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册