Skip to content

Commit 4e564e4

Browse files
authored
make WriteToArrayOp supporting empty tensor input (#6030)
1 parent a38c151 commit 4e564e4

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

paddle/operators/tensor_array_read_write_op.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,15 @@ class WriteToArrayOp : public ArrayOp {
3737
<< " to " << offset + 1;
3838
out->resize(offset + 1);
3939
}
40-
auto *out_tensor = &out->at(offset);
41-
CopyFrom(x_tensor, dev_ctx.GetPlace(), dev_ctx, out_tensor);
42-
out_tensor->set_lod(x_tensor.lod());
40+
if (x_tensor.memory_size() > 0) {
41+
auto *out_tensor = &out->at(offset);
42+
CopyFrom(x_tensor, dev_ctx.GetPlace(), dev_ctx, out_tensor);
43+
out_tensor->set_lod(x_tensor.lod());
44+
} else {
45+
VLOG(10) << "WARNING: The input tensor 'x_tensor' holds no memory, so "
46+
"nothing has been written to output array["
47+
<< offset << "].";
48+
}
4349
}
4450
};
4551

0 commit comments

Comments
 (0)