diff --git a/python/paddle/fluid/layers/tensor.py b/python/paddle/fluid/layers/tensor.py index 81a60bf51752281ec907c4281896130d6c28b328..b47ddd0dc9fc30484449a270efc3866dd6896a91 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