未验证 提交 b2483d78 编写于 作者: L liym27 提交者: GitHub

Fix test_slice: avoid unnecessary copying of TensorArray from subblock to parent block(#30168)

In control flow, don't copy TensorArray from subblock to parent block when TensorArray is created in parent block.
上级 528e03fc
...@@ -2278,6 +2278,10 @@ def copy_var_to_parent_block(var, layer_helper): ...@@ -2278,6 +2278,10 @@ def copy_var_to_parent_block(var, layer_helper):
assert parent_idx >= 0, "Got wrong parent block index when assigning var to parent scope in control_flow" assert parent_idx >= 0, "Got wrong parent block index when assigning var to parent scope in control_flow"
parent_block = prog.block(parent_idx) parent_block = prog.block(parent_idx)
if var.type == core.VarDesc.VarType.LOD_TENSOR_ARRAY \
and parent_block._find_var_recursive(var.name):
parent_block_var = var
else:
parent_block_var = parent_block.create_var( parent_block_var = parent_block.create_var(
dtype=var.dtype, shape=var.shape, type=var.type) dtype=var.dtype, shape=var.shape, type=var.type)
assign(var, parent_block_var) assign(var, parent_block_var)
......
...@@ -40,9 +40,12 @@ def test_slice_in_if(x): ...@@ -40,9 +40,12 @@ def test_slice_in_if(x):
if x.numpy()[0] > 0: if x.numpy()[0] > 0:
a.append(x) a.append(x)
else: else:
a.append(paddle.full(shape=[1, 2], fill_value=9, dtype="int64")) a.append(paddle.full(shape=[1, 2], fill_value=9, dtype="int32"))
if x.numpy()[0] > 0: if x.numpy()[0] > 0:
a[0] = x a[0] = x
a[0] = x + 1
out = a[0] out = a[0]
return out return out
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册