diff --git a/paddle/phi/kernels/funcs/slice_utils.h b/paddle/phi/kernels/funcs/slice_utils.h index e26a6543789d7..bfe024f45a098 100644 --- a/paddle/phi/kernels/funcs/slice_utils.h +++ b/paddle/phi/kernels/funcs/slice_utils.h @@ -78,6 +78,9 @@ inline void CheckAndUpdateSliceAttrs(const DDim in_dims, // dim_value-1 // "end is -1" means contain the 0-th element of this axis. start = std::min(start, dim_value - 1); + if (end < -1) { + end += dim_value; + } end = std::max(end, static_cast(-1)); PADDLE_ENFORCE_GE( start,