Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions paddle/phi/kernels/xpu/masked_select_grad_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "paddle/phi/backends/xpu/enforce_xpu.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/phi/kernels/full_kernel.h"

namespace phi {

Expand All @@ -25,6 +26,12 @@ void MaskedSelectGradKernel(const Context& dev_ctx,
const DenseTensor& mask,
const DenseTensor& out_grad,
DenseTensor* x_grad) {
if (out_grad.numel() == 0 && x_grad) {
// x = [1, 2], mask = [False, False], out = [], x_grad = [0, 0]
phi::Full<T, Context>(
dev_ctx, phi::IntArray(common::vectorize(x_grad->dims())), 0, x_grad);
return;
}
using XPUType = typename XPUTypeTrait<T>::Type;
auto* mask_data = mask.data<bool>();
auto* input_data = reinterpret_cast<const XPUType*>(out_grad.data<T>());
Expand Down
Loading