Skip to content

Commit 7159dbf

Browse files
authored
add PADDLE_ENFORCE_LE for unbind (#74224)
1 parent c42d567 commit 7159dbf

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

paddle/phi/kernels/impl/unbind_kernel_impl.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ void UnbindKernel(const Context& dev_ctx,
2424
const DenseTensor& x,
2525
int axis,
2626
std::vector<DenseTensor*> outs) {
27+
int64_t unbind_numel = x.numel();
28+
PADDLE_ENFORCE_LE(unbind_numel,
29+
std::numeric_limits<int>::max(),
30+
::common::errors::PreconditionNotMet(
31+
"The number of proposals in unbind should be less than "
32+
"2^31, but got %lld. Please check the input tensor. ",
33+
unbind_numel));
2734
auto x_dims = x.dims();
2835
axis = axis < 0 ? x_dims.size() + axis : axis;
2936

paddle/phi/kernels/stride/unbind_kernel.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ void UnbindStridedKernel(const Context& dev_ctx,
3232
"FLAGS_use_stride_kernel is closed. Strided kernel "
3333
"be called, something wrong has happened!"));
3434
}
35+
int64_t unbind_numel = x.numel();
36+
PADDLE_ENFORCE_LE(unbind_numel,
37+
std::numeric_limits<int>::max(),
38+
::common::errors::PreconditionNotMet(
39+
"The number of proposals in unbind should be less than "
40+
"2^31, but got %lld. Please check the input tensor. ",
41+
unbind_numel));
3542
int64_t num = static_cast<int64_t>(outs.size());
3643
int64_t start = 0;
3744

0 commit comments

Comments
 (0)