Skip to content

Commit

Permalink
fix bugs of paddle.multiplex API (PaddlePaddle#49368)
Browse files Browse the repository at this point in the history
  • Loading branch information
haohongxiang committed Jan 9, 2023
1 parent 1d25c66 commit dbbd339
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions paddle/phi/infermeta/multiary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2190,6 +2190,14 @@ void MultiplexInferMeta(const std::vector<const MetaTensor*>& ins,
phi::errors::PreconditionNotMet(
"All the candidate tensors must have the same size."));
}

PADDLE_ENFORCE_GE(
in_dim[0],
ids_dim[0],
phi::errors::InvalidArgument("The 2nd-dim of input cannot be smaller "
"than batchSize of the index tensor."));

in_dim[0] = ids_dim[0];
out->set_dims(in_dim);
out->set_dtype(ins[0]->dtype());
}
Expand Down
2 changes: 1 addition & 1 deletion paddle/phi/kernels/cpu/multiplex_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void MultiplexKernel(const Context& ctx,
auto rows = ins[0]->dims()[0];
auto cols = ins[0]->numel() / rows;
auto index = ids.data<int32_t>();
for (auto i = 0; i < rows; i++) {
for (auto i = 0; i < ids.dims()[0]; i++) {
int32_t k = index[i];
PADDLE_ENFORCE_GE(
k, 0, errors::PreconditionNotMet("index must be nonnegative."));
Expand Down
2 changes: 1 addition & 1 deletion paddle/phi/kernels/gpu/multiplex_kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void MultiplexKernel(const Context& ctx,
paddle::framework::TensorCopySync(ids, phi::CPUPlace(), &index_t_cpu);
auto* index = index_t_cpu.data<int32_t>();
auto stream = ctx.stream();
for (auto i = 0; i < rows; i++) {
for (auto i = 0; i < ids.dims()[0]; i++) {
int32_t k = index[i];
PADDLE_ENFORCE_GE(
k, 0, errors::PreconditionNotMet("index must be nonnegative."));
Expand Down

0 comments on commit dbbd339

Please sign in to comment.