diff --git a/paddle/phi/kernels/funcs/slice_utils.h b/paddle/phi/kernels/funcs/slice_utils.h index 0c956248fd9ef10e80f0e48f82e89ee5986a2b15..c42843f94914fbc6df5557d63fc482857b7a2c3b 100644 --- a/paddle/phi/kernels/funcs/slice_utils.h +++ b/paddle/phi/kernels/funcs/slice_utils.h @@ -77,6 +77,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,