Skip to content

[CINN] Fixed arange float16 and bfloat16 support #72669

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 1 commit into from
May 12, 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
Original file line number Diff line number Diff line change
Expand Up @@ -554,6 +554,12 @@ class ArangeOpPattern
case phi::DataType::INT32:
input = phi::Scalar(input.to<int>());
break;
case phi::DataType::FLOAT16:
input = phi::Scalar(input.to<float>());
break;
case phi::DataType::BFLOAT16:
input = phi::Scalar(input.to<float>());
break;
default:
input = phi::Scalar(input.to<int64_t>());
}
Expand Down
14 changes: 13 additions & 1 deletion paddle/cinn/hlir/op/elementwise.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1310,8 +1310,20 @@ std::shared_ptr<framework::OpStrategy> StrategyForArangeSymbolic(
EXPR_FROM_ATTR(int)
} else if (dtype.is_int(64)) {
EXPR_FROM_ATTR(int64_t)
} else if (dtype.is_bfloat16()) {
EXPR_FROM_ATTR(float)
start->set_type(cinn::common::BFloat16());
step->set_type(cinn::common::BFloat16());
} else if (dtype.is_float16()) {
EXPR_FROM_ATTR(float)
start->set_type(cinn::common::Float16());
step->set_type(cinn::common::Float16());
} else {
CINN_NOT_IMPLEMENTED
PADDLE_ENFORCE_NOT_NULL(
nullptr,
::common::errors::InvalidArgument(
"The dtype of arange op should be float32, float64, int32, int64, "
"bfloat16 or float16."));
}

#undef EXPR_FROM_ATTR
Expand Down
4 changes: 4 additions & 0 deletions paddle/phi/infermeta/nullary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ void ArangeInferMeta(const Scalar& start,
GET_SIZE_GIVEN_TYPE(double)
case DataType::INT32:
GET_SIZE_GIVEN_TYPE(int)
case DataType::FLOAT16:
GET_SIZE_GIVEN_TYPE(float)
case DataType::BFLOAT16:
GET_SIZE_GIVEN_TYPE(float)
default:
GET_SIZE_GIVEN_TYPE(int64_t)
}
Expand Down
Loading