未验证 提交 afa3f9b3 编写于 作者: A Aurelius84 提交者: GitHub

[Perf]Removed usless assign op in while_loop (#53452)

* [Perf]Removed usless assign op in while_loop

* refine assign
上级 ddf94ae4
......@@ -395,6 +395,10 @@ def assign_skip_lod_tensor_array(input, output):
input.shape, output.shape
)
)
# NOTE(dev): Avoid assign if input is output in Variable level which means
# input is not generated in While sub block and modified by in-place and only
# belong to inplace ops in constructing program process, because in-place pass
# is only available in Graph level.
paddle.assign(input, output)
......
......@@ -2029,6 +2029,10 @@ def assign(x, output=None):
result2 = paddle.assign(data) # result2 = [[2.5, 2.5], [2.5, 2.5], [2.5, 2.5]]
result3 = paddle.assign(np.array([[2.5, 2.5], [2.5, 2.5], [2.5, 2.5]], dtype='float32')) # result3 = [[2.5, 2.5], [2.5, 2.5], [2.5, 2.5]]
"""
# speed up
if x is output and isinstance(x, Variable):
return x
input = x
helper = LayerHelper('assign', **locals())
check_type(
......@@ -2037,7 +2041,6 @@ def assign(x, output=None):
(Variable, np.ndarray, list, tuple, float, int, bool),
'assign',
)
is_inplace = True if output is not None else False
if np.isscalar(input) and not isinstance(input, str):
input = np.array([input])
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册