Skip to content

Commit 6d2d8e5

Browse files
authored
fix bugs of paddle.multiplex API (#49368) (#49642)
1 parent 1d25c66 commit 6d2d8e5

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

paddle/phi/infermeta/multiary.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2190,6 +2190,14 @@ void MultiplexInferMeta(const std::vector<const MetaTensor*>& ins,
21902190
phi::errors::PreconditionNotMet(
21912191
"All the candidate tensors must have the same size."));
21922192
}
2193+
2194+
PADDLE_ENFORCE_GE(
2195+
in_dim[0],
2196+
ids_dim[0],
2197+
phi::errors::InvalidArgument("The 2nd-dim of input cannot be smaller "
2198+
"than batchSize of the index tensor."));
2199+
2200+
in_dim[0] = ids_dim[0];
21932201
out->set_dims(in_dim);
21942202
out->set_dtype(ins[0]->dtype());
21952203
}

paddle/phi/kernels/cpu/multiplex_kernel.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void MultiplexKernel(const Context& ctx,
3737
auto rows = ins[0]->dims()[0];
3838
auto cols = ins[0]->numel() / rows;
3939
auto index = ids.data<int32_t>();
40-
for (auto i = 0; i < rows; i++) {
40+
for (auto i = 0; i < ids.dims()[0]; i++) {
4141
int32_t k = index[i];
4242
PADDLE_ENFORCE_GE(
4343
k, 0, errors::PreconditionNotMet("index must be nonnegative."));

paddle/phi/kernels/gpu/multiplex_kernel.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void MultiplexKernel(const Context& ctx,
4141
paddle::framework::TensorCopySync(ids, phi::CPUPlace(), &index_t_cpu);
4242
auto* index = index_t_cpu.data<int32_t>();
4343
auto stream = ctx.stream();
44-
for (auto i = 0; i < rows; i++) {
44+
for (auto i = 0; i < ids.dims()[0]; i++) {
4545
int32_t k = index[i];
4646
PADDLE_ENFORCE_GE(
4747
k, 0, errors::PreconditionNotMet("index must be nonnegative."));

0 commit comments

Comments
 (0)