From 1ae0730f3800c5975e9c6287c0a7c3fd6521d187 Mon Sep 17 00:00:00 2001 From: zyfncg Date: Sun, 3 Apr 2022 23:04:31 +0800 Subject: [PATCH] fix bug caused by arange (#41372) --- python/paddle/fluid/layers/tensor.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/python/paddle/fluid/layers/tensor.py b/python/paddle/fluid/layers/tensor.py index 81a60bf517..b47ddd0dc9 100644 --- a/python/paddle/fluid/layers/tensor.py +++ b/python/paddle/fluid/layers/tensor.py @@ -1433,10 +1433,6 @@ def range(start, end, step, dtype, name=None): if not isinstance(dtype, core.VarDesc.VarType): dtype = convert_np_dtype_to_dtype_(dtype) - if in_dygraph_mode(): - return _C_ops.final_state_arange(start, end, step, dtype, - _current_expected_place()) - if not isinstance(start, Variable): with device_guard("cpu"): start = fill_constant([1], dtype, start, force_cpu=True) @@ -1455,6 +1451,10 @@ def range(start, end, step, dtype, name=None): elif step.dtype != dtype: step = cast(step, dtype) + if in_dygraph_mode(): + return _C_ops.final_state_arange(start, end, step, dtype, + _current_expected_place()) + if _in_legacy_dygraph(): out = _C_ops.range(start, end, step) out.stop_gradient = True -- GitLab