From 34bf8dfc4052943610298a1e270dc41ca7a8fa53 Mon Sep 17 00:00:00 2001 From: Zhang Ting Date: Mon, 18 Jan 2021 20:24:03 +0800 Subject: [PATCH] avoid calling cast twice (#30527) --- python/paddle/fluid/layers/tensor.py | 1 + 1 file changed, 1 insertion(+) diff --git a/python/paddle/fluid/layers/tensor.py b/python/paddle/fluid/layers/tensor.py index dcd5495dc1a..cd0d652af84 100644 --- a/python/paddle/fluid/layers/tensor.py +++ b/python/paddle/fluid/layers/tensor.py @@ -228,6 +228,7 @@ def cast(x, dtype): if not isinstance(dtype, core.VarDesc.VarType): dtype = convert_np_dtype_to_dtype_(dtype) out = core.ops.cast(x, 'in_dtype', x.dtype, 'out_dtype', dtype) + return out check_variable_and_dtype( x, 'x', -- GitLab