Skip to content

Support Half/BFloat16 in glu #7824

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 2 commits into from
Jan 23, 2025
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
10 changes: 4 additions & 6 deletions kernels/portable/cpu/op_glu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,10 @@ Tensor& glu_out(
const size_t non_negative_dim = dim < 0 ? dim + self.dim() : dim;
const auto in_dtype = self.scalar_type();

ET_SWITCH_FLOAT_TYPES(in_dtype, ctx, "glu", CTYPE_IN, [&]() {
if (out.scalar_type() == ScalarType::Float) {
glu_out_tensor<CTYPE_IN, float>(self, non_negative_dim, out);
} else {
glu_out_tensor<CTYPE_IN, double>(self, non_negative_dim, out);
}
ET_SWITCH_FLOATHBF16_TYPES(in_dtype, ctx, "glu", CTYPE_IN, [&]() {
ET_SWITCH_FLOATHBF16_TYPES(out.scalar_type(), ctx, "glu", CTYPE_OUT, [&]() {
glu_out_tensor<CTYPE_IN, CTYPE_OUT>(self, non_negative_dim, out);
});
});

return out;
Expand Down
18 changes: 16 additions & 2 deletions kernels/test/op_glu_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,28 @@ class OpGluOutTest : public OperatorTest {
TEST_F(OpGluOutTest, AllInputFloatOutputSupport) {
#define TEST_ENTRY(ctype, dtype) \
test_glu_out<ScalarType::dtype, ScalarType::Float>();
ET_FORALL_FLOAT_TYPES(TEST_ENTRY);
ET_FORALL_FLOATHBF16_TYPES(TEST_ENTRY);
#undef TEST_ENTRY
}

TEST_F(OpGluOutTest, AllInputDoubleOutputSupport) {
#define TEST_ENTRY(ctype, dtype) \
test_glu_out<ScalarType::dtype, ScalarType::Double>();
ET_FORALL_FLOAT_TYPES(TEST_ENTRY);
ET_FORALL_FLOATHBF16_TYPES(TEST_ENTRY);
#undef TEST_ENTRY
}

TEST_F(OpGluOutTest, AllInputHalfOutputSupport) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't testing when the inputs are Half/Bfloat16

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops! fixed

#define TEST_ENTRY(ctype, dtype) \
test_glu_out<ScalarType::dtype, ScalarType::Half>();
ET_FORALL_FLOATHBF16_TYPES(TEST_ENTRY);
#undef TEST_ENTRY
}

TEST_F(OpGluOutTest, AllInputBFloat16OutputSupport) {
#define TEST_ENTRY(ctype, dtype) \
test_glu_out<ScalarType::dtype, ScalarType::BFloat16>();
ET_FORALL_FLOATHBF16_TYPES(TEST_ENTRY);
#undef TEST_ENTRY
}

Expand Down
Loading