Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions paddle/phi/kernels/gpu/flip_kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ void FlipKernel(const Context& dev_ctx,
DenseTensor* out) {
const size_t total_dims = x.dims().size();
switch (total_dims) {
case 0:
LaunchFlipCudaKernel<T, Context, 0>(dev_ctx, x, axis, out);
break;
case 1:
LaunchFlipCudaKernel<T, Context, 1>(dev_ctx, x, axis, out);
break;
Expand Down
21 changes: 21 additions & 0 deletions python/paddle/fluid/tests/unittests/test_zero_dim_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,15 @@ def setUp(self):
paddle.disable_static()
self.x = paddle.rand([])

def test_flip(self):
x = paddle.rand([])
x.stop_gradient = False
out = paddle.flip(x, axis=[])
out.backward()
self.assertEqual(x.shape, [])
self.assertEqual(out.shape, [])
self.assertEqual(out.grad.shape, [])

def test_linear(self):
x = paddle.randn([3, 2])
w = paddle.full(shape=[2, 4], fill_value=0.5)
Expand Down Expand Up @@ -753,6 +762,18 @@ def setUp(self):
paddle.enable_static()
self.exe = paddle.static.Executor()

@prog_scope()
def test_flip(self):
x = paddle.rand([])
x.stop_gradient = False
out = paddle.flip(x, axis=[])
paddle.static.append_backward(out)

program = paddle.static.default_main_program()
res1, res2 = self.exe.run(program, fetch_list=[x, out])
self.assertEqual(res1.shape, ())
self.assertEqual(res2.shape, ())

@prog_scope()
def test_pow_factor(self):
x = paddle.rand([])
Expand Down