From 67a4de68bbd15e8e464f13fe5062e88cedd50d1a Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Wed, 16 Jun 2021 11:53:19 +0800 Subject: [PATCH] Add return when input is tensor (#33570) * add return when input is tensor * fix typo --- python/paddle/tensor/creation.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/python/paddle/tensor/creation.py b/python/paddle/tensor/creation.py index dba4cc1dd8c..b7c55ea424c 100644 --- a/python/paddle/tensor/creation.py +++ b/python/paddle/tensor/creation.py @@ -134,8 +134,9 @@ def to_tensor(data, dtype=None, place=None, stop_gradient=True): ) elif isinstance(data, paddle.Tensor): data = data._copy_to(place, False) - ata = _handle_dtype(data, dtype) + data = _handle_dtype(data, dtype) data.stop_gradient = stop_gradient + return data elif isinstance(data, (core.LoDTensor, core.Tensor)): # Note(zhouwei25): should't expose it to users, just for internal use. # convert core.Tensor/core.LoDTensor to VarBase first @@ -145,6 +146,7 @@ def to_tensor(data, dtype=None, place=None, stop_gradient=True): data = data._copy_to(place, False) data = _handle_dtype(data, dtype) data.stop_gradient = stop_gradient + return data else: raise TypeError( "Can't constructs a 'paddle.Tensor' with data type {}, data type must be scalar|list|tuple|numpy.ndarray|paddle.Tensor". -- GitLab