Skip to content

Commit

Permalink
repeat_interleave support bf16 dtype (#61854) (#61899)
Browse files Browse the repository at this point in the history
* repeat_interleave support bf16 dtype

* support bf16 on cpu
  • Loading branch information
tianhaodongbd authored Feb 21, 2024
1 parent b6a38d0 commit 96c2aaf
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
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 = base.dygraph.to_variable(self.data_x)
Expand Down

0 comments on commit 96c2aaf

Please sign in to comment.