未验证 提交 de4a7911 编写于 作者: W wanghuancoder 提交者: GitHub

fix predictor memory write overflow (#47485)

* fix predictor memory write overflow
上级 2953b708
......@@ -182,6 +182,11 @@ bool PaddleTensorToLoDTensor(const PaddleTensor &pt,
pt.data.data(),
paddle::platform::errors::InvalidArgument(
"The data contained in the input PaddleTensor is illegal."));
PADDLE_ENFORCE_EQ(
pt.data.length(),
t->numel() * paddle::experimental::SizeOf(t->dtype()),
paddle::platform::errors::InvalidArgument(
"The data contained in the input PaddleTensor had wrong length."));
}
if (platform::is_cpu_place(place)) {
......
......@@ -234,6 +234,12 @@ bool NativePaddlePredictor::SetFeed(const std::vector<PaddleTensor> &inputs,
inputs[i].data.data(),
platform::errors::InvalidArgument(
"The data of input tensor should not be null."));
PADDLE_ENFORCE_EQ(
inputs[i].data.length(),
input.numel() * paddle::experimental::SizeOf(input.dtype()),
paddle::platform::errors::InvalidArgument(
"The data contained in the input PaddleTensor had wrong length."));
if (platform::is_cpu_place(place_)) {
// TODO(panyx0718): Init LoDTensor from existing memcpy to save a copy.
std::memcpy(static_cast<void *>(input_ptr),
......
......@@ -154,7 +154,7 @@ void PrepareInputs(std::vector<PaddleTensor> *input_slots,
init_idx.name = "init_idx";
init_idx.shape.assign({batch_size});
init_idx.dtype = PaddleDType::INT32;
init_idx.dtype = PaddleDType::INT64;
TensorAssignData<int64_t>(&init_idx, one_batch.init_idx);
trg_src_attn_bias.name = "trg_src_attn_bias";
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册