diff --git a/paddle/fluid/operators/slice_op.h b/paddle/fluid/operators/slice_op.h index 15d52880ed9ca1162070d13e2ae787de2945013a..d9ef45343d83b141ae0cab7f445fae411818b3b5 100644 --- a/paddle/fluid/operators/slice_op.h +++ b/paddle/fluid/operators/slice_op.h @@ -43,6 +43,10 @@ inline void DealTensorArray(const framework::ExecutionContext& ctx, end = std::max(end, static_cast(0)); end = std::min(end, in_size); + if (starts[0] == -1 && end == 0) { + end = start + 1; + } + PADDLE_ENFORCE_GT(end, start, platform::errors::InvalidArgument( "Attr(ends) should be greater than attr(starts) in " @@ -330,7 +334,7 @@ class SliceGradKernel : public framework::OpKernel { auto decrease_axis = ctx.Attr>("decrease_axis"); auto decrease_size = decrease_axis.size(); if (decrease_size > 0) { - if (decrease_size == (size_t)in_dims.size()) { + if (decrease_size == static_cast(in_dims.size())) { // all dims decrease std::vector origin_out_shape(decrease_size, 1); out_dims = framework::make_ddim(std::vector(decrease_size, 1));