Skip to content
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

repeat_interleave support bf16 dtype #61854

Merged
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
6 changes: 4 additions & 2 deletions paddle/phi/kernels/cpu/repeat_interleave_grad_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ PD_REGISTER_KERNEL(repeat_interleave_with_tensor_index_grad,
float,
double,
int,
int64_t) {}
int64_t,
phi::dtype::bfloat16) {}

PD_REGISTER_KERNEL(repeat_interleave_grad,
CPU,
Expand All @@ -113,4 +114,5 @@ PD_REGISTER_KERNEL(repeat_interleave_grad,
float,
double,
int,
int64_t) {}
int64_t,
phi::dtype::bfloat16) {}
6 changes: 4 additions & 2 deletions paddle/phi/kernels/cpu/repeat_interleave_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ PD_REGISTER_KERNEL(repeat_interleave,
float,
double,
int,
int64_t) {}
int64_t,
phi::dtype::bfloat16) {}

PD_REGISTER_KERNEL(repeat_interleave_with_tensor_index,
CPU,
Expand All @@ -34,4 +35,5 @@ PD_REGISTER_KERNEL(repeat_interleave_with_tensor_index,
float,
double,
int,
int64_t) {}
int64_t,
phi::dtype::bfloat16) {}
6 changes: 4 additions & 2 deletions paddle/phi/kernels/gpu/repeat_interleave_grad_kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ PD_REGISTER_KERNEL(repeat_interleave_with_tensor_index_grad,
float,
double,
int,
int64_t) {}
int64_t,
phi::dtype::bfloat16) {}
PD_REGISTER_KERNEL(repeat_interleave_grad,
GPU,
ALL_LAYOUT,
phi::RepeatInterleaveGradKernel,
float,
double,
int,
int64_t) {}
int64_t,
phi::dtype::bfloat16) {}
6 changes: 4 additions & 2 deletions paddle/phi/kernels/gpu/repeat_interleave_kernel.cu
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ PD_REGISTER_KERNEL(repeat_interleave,
float,
double,
int,
int64_t) {}
int64_t,
phi::dtype::bfloat16) {}

PD_REGISTER_KERNEL(repeat_interleave_with_tensor_index,
GPU,
Expand All @@ -34,4 +35,5 @@ PD_REGISTER_KERNEL(repeat_interleave_with_tensor_index,
float,
double,
int,
int64_t) {}
int64_t,
phi::dtype::bfloat16) {}
19 changes: 19 additions & 0 deletions test/legacy_test/test_repeat_interleave_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,25 @@ def test_dygraph_api(self):
expect_out = np.repeat(input_x, index, axis=None)
np.testing.assert_allclose(expect_out, np_z, rtol=1e-05)

# case input dtype is bfloat16
input_x = np.array([[1, 2, 1], [1, 2, 3]]).astype('uint16')

with base.dygraph.guard():
x = paddle.to_tensor(input_x)
index = paddle.to_tensor(index_x)
z = paddle.repeat_interleave(x, index, None)
np_z = z.numpy()
expect_out = np.repeat(input_x, index_x, axis=None)
np.testing.assert_allclose(expect_out, np_z, rtol=1e-05)

with base.dygraph.guard():
x = paddle.to_tensor(input_x)
index = 2
z = paddle.repeat_interleave(x, index, None)
np_z = z.numpy()
expect_out = np.repeat(input_x, index, axis=None)
np.testing.assert_allclose(expect_out, np_z, rtol=1e-05)

# case 1:
with base.dygraph.guard():
x = paddle.to_tensor(self.data_x)
Expand Down