Skip to content

【BIT】square Tensor.square support 0-size #72385

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
4 changes: 4 additions & 0 deletions paddle/phi/kernels/selected_rows/activation_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ void SquareKernel(const Context& dev_ctx,
SelectedRows* out) {
out->set_rows(x.rows());
out->set_height(x.height());
if (x.value().numel() == 0) {
dev_ctx.template Alloc<T>(out->mutable_value());
return;
}
Comment on lines +31 to +34
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

当把常规的activation修改后,这里应该就不用修改了。因为下面调用了常规的activation Kernel。

phi::SquareKernel<T, Context>(dev_ctx, x.value(), out->mutable_value());
}

Expand Down
8 changes: 8 additions & 0 deletions test/legacy_test/test_activation_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -4511,6 +4511,14 @@ def init_shape(self):
self.shape = []


class TestSquare_ZeroSize(TestSquare):
def init_shape(self):
self.shape = [0, 1, 1]

def init_dtype(self):
self.dtype = np.float32


@unittest.skipIf(
not core.is_compiled_with_cuda() or core.is_compiled_with_rocm(),
"core is not compiled with CUDA",
Expand Down
Loading