Skip to content

[XPU] support argmin bf16 #68453

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

Merged
merged 4 commits into from
Oct 1, 2024
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
4 changes: 3 additions & 1 deletion paddle/phi/backends/xpu/xpu3_op_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ XPUOpMap& get_kl3_ops() {
phi::DataType::FLOAT32,
phi::DataType::FLOAT16})},
{"arg_min",
XPUKernelSet({phi::DataType::FLOAT32, phi::DataType::FLOAT16})},
XPUKernelSet({phi::DataType::FLOAT32,
phi::DataType::FLOAT16,
phi::DataType::BFLOAT16})},
{"argsort_grad",
XPUKernelSet({phi::DataType::INT32,
phi::DataType::INT64,
Expand Down
9 changes: 7 additions & 2 deletions paddle/phi/kernels/xpu/arg_min_max_kernel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,12 @@ PD_REGISTER_KERNEL(argmax,
kernel->OutputAt(0).SetDataType(phi::DataType::UNDEFINED);
}

PD_REGISTER_KERNEL(
argmin, XPU, ALL_LAYOUT, phi::ArgMinKernel, float, phi::dtype::float16) {
PD_REGISTER_KERNEL(argmin,
XPU,
ALL_LAYOUT,
phi::ArgMinKernel,
float,
phi::dtype::float16,
phi::dtype::bfloat16) {
kernel->OutputAt(0).SetDataType(phi::DataType::UNDEFINED);
}
14 changes: 12 additions & 2 deletions test/xpu/test_arg_min_op_xpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
create_test_class,
get_xpu_op_support_types,
)
from op_test import convert_float_to_uint16
from op_test_xpu import XPUOpTest

import paddle
Expand All @@ -41,8 +42,17 @@ def setUp(self):
self.dtype = self.in_type
self.initTestCase()

self.x = (np.random.random(self.dims)).astype(self.dtype)
self.inputs = {'X': self.x}
self.x = (np.random.random(self.dims)).astype(
self.dtype if self.dtype != np.uint16 else np.float32
)

self.inputs = {
'X': (
self.x
if self.dtype != np.uint16
else convert_float_to_uint16(self.x)
)
}
self.attrs = {'axis': self.axis, 'use_xpu': True}
self.outputs = {'Out': np.argmin(self.x, axis=self.axis)}

Expand Down