Skip to content

Commit 96c2aaf

Browse files
repeat_interleave support bf16 dtype (#61854) (#61899)
* repeat_interleave support bf16 dtype * support bf16 on cpu
1 parent b6a38d0 commit 96c2aaf

File tree

5 files changed

+35
-8
lines changed

5 files changed

+35
-8
lines changed

paddle/phi/kernels/cpu/repeat_interleave_grad_kernel.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ PD_REGISTER_KERNEL(repeat_interleave_with_tensor_index_grad,
104104
float,
105105
double,
106106
int,
107-
int64_t) {}
107+
int64_t,
108+
phi::dtype::bfloat16) {}
108109

109110
PD_REGISTER_KERNEL(repeat_interleave_grad,
110111
CPU,
@@ -113,4 +114,5 @@ PD_REGISTER_KERNEL(repeat_interleave_grad,
113114
float,
114115
double,
115116
int,
116-
int64_t) {}
117+
int64_t,
118+
phi::dtype::bfloat16) {}

paddle/phi/kernels/cpu/repeat_interleave_kernel.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ PD_REGISTER_KERNEL(repeat_interleave,
2525
float,
2626
double,
2727
int,
28-
int64_t) {}
28+
int64_t,
29+
phi::dtype::bfloat16) {}
2930

3031
PD_REGISTER_KERNEL(repeat_interleave_with_tensor_index,
3132
CPU,
@@ -34,4 +35,5 @@ PD_REGISTER_KERNEL(repeat_interleave_with_tensor_index,
3435
float,
3536
double,
3637
int,
37-
int64_t) {}
38+
int64_t,
39+
phi::dtype::bfloat16) {}

paddle/phi/kernels/gpu/repeat_interleave_grad_kernel.cu

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ PD_REGISTER_KERNEL(repeat_interleave_with_tensor_index_grad,
2525
float,
2626
double,
2727
int,
28-
int64_t) {}
28+
int64_t,
29+
phi::dtype::bfloat16) {}
2930
PD_REGISTER_KERNEL(repeat_interleave_grad,
3031
GPU,
3132
ALL_LAYOUT,
3233
phi::RepeatInterleaveGradKernel,
3334
float,
3435
double,
3536
int,
36-
int64_t) {}
37+
int64_t,
38+
phi::dtype::bfloat16) {}

paddle/phi/kernels/gpu/repeat_interleave_kernel.cu

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ PD_REGISTER_KERNEL(repeat_interleave,
2525
float,
2626
double,
2727
int,
28-
int64_t) {}
28+
int64_t,
29+
phi::dtype::bfloat16) {}
2930

3031
PD_REGISTER_KERNEL(repeat_interleave_with_tensor_index,
3132
GPU,
@@ -34,4 +35,5 @@ PD_REGISTER_KERNEL(repeat_interleave_with_tensor_index,
3435
float,
3536
double,
3637
int,
37-
int64_t) {}
38+
int64_t,
39+
phi::dtype::bfloat16) {}

test/legacy_test/test_repeat_interleave_op.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,25 @@ def test_dygraph_api(self):
252252
expect_out = np.repeat(input_x, index, axis=None)
253253
np.testing.assert_allclose(expect_out, np_z, rtol=1e-05)
254254

255+
# case input dtype is bfloat16
256+
input_x = np.array([[1, 2, 1], [1, 2, 3]]).astype('uint16')
257+
258+
with base.dygraph.guard():
259+
x = paddle.to_tensor(input_x)
260+
index = paddle.to_tensor(index_x)
261+
z = paddle.repeat_interleave(x, index, None)
262+
np_z = z.numpy()
263+
expect_out = np.repeat(input_x, index_x, axis=None)
264+
np.testing.assert_allclose(expect_out, np_z, rtol=1e-05)
265+
266+
with base.dygraph.guard():
267+
x = paddle.to_tensor(input_x)
268+
index = 2
269+
z = paddle.repeat_interleave(x, index, None)
270+
np_z = z.numpy()
271+
expect_out = np.repeat(input_x, index, axis=None)
272+
np.testing.assert_allclose(expect_out, np_z, rtol=1e-05)
273+
255274
# case 1:
256275
with base.dygraph.guard():
257276
x = base.dygraph.to_variable(self.data_x)

0 commit comments

Comments
 (0)