From 2dffe32b331cd424517f5766560823db80fdbfb2 Mon Sep 17 00:00:00 2001 From: jiangcheng Date: Thu, 29 Jul 2021 14:45:02 +0800 Subject: [PATCH] [Cherry-pick] solve slice inplace illegal memory address bug (#34265) #34473 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SliceGradKernel的need_pad_num == 0判断有问题,直接跳过导致没有分配合适的空间,删去该判断逻辑后运行就正常了。 --- paddle/fluid/operators/slice_op.h | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/paddle/fluid/operators/slice_op.h b/paddle/fluid/operators/slice_op.h index 22f6fa9e3e..faa1d1237d 100644 --- a/paddle/fluid/operators/slice_op.h +++ b/paddle/fluid/operators/slice_op.h @@ -468,17 +468,7 @@ class SliceGradKernel : public framework::OpKernel { } } - if (need_pad_num == 0) { - // do not need padding, pass if data address same, else copy - if (d_input->mutable_data(context.GetPlace()) == d_out->data()) { - // inplace, do not any operator, pass - } else { - framework::TensorCopy( - *d_out, context.GetPlace(), - context.template device_context(), - d_input); - } - } else if (need_pad_num == 1) { + if (need_pad_num == 1) { // only need padding one dimension, we can reduce dimension. // only the padding dimension is available for us. // How to reduce dimension(5 to 3 for example): -- GitLab