Skip to content
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

[CINN] fix slice op sym infer with input(with data) and symbol starts or ends #70282

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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 @@ -236,19 +236,9 @@ inline ShapeOrData SliceRawInferSymbolicShape(
// Currently, we DO NOT support the case that any element in `axes` `starts`
// or `ends` is a Symbol.
auto vec_int64 = details::VecExpr2Int64(starts);
PADDLE_ENFORCE_EQ(
vec_int64.has_value(),
true,
common::errors::InvalidArgument(
"for slice op, all the elements in `starts` must be int64_t"));
std::vector<int64_t> starts_int = vec_int64.value();

vec_int64 = details::VecExpr2Int64(ends);
PADDLE_ENFORCE_EQ(
vec_int64.has_value(),
true,
common::errors::InvalidArgument(
"for slice op, all the elements in `ends` must be int64_t"));
std::vector<int64_t> ends_int = vec_int64.value();

const int64_t start =
Expand All @@ -274,10 +264,18 @@ inline ShapeOrData SliceRawInferSymbolicShape(
return symbol::ShapeOrDataDimExprs{
symbol::TensorShapeOrDataDimExprs(shape, out_data)};
};
bool starts_ends_all_int =
std::all_of(starts_expr.begin(),
starts_expr.end(),
[](const symbol::DimExpr &e) { return e.isa<int64_t>(); }) &&
std::all_of(ends_expr.begin(),
ends_expr.end(),
[](const symbol::DimExpr &e) { return e.isa<int64_t>(); });

const auto &out_shape = in_shapeordata.data().has_value()
? GetDataDimExprs()
: GetShapeDimExprs();
const auto &out_shape =
in_shapeordata.data().has_value() && starts_ends_all_int
? GetDataDimExprs()
: GetShapeDimExprs();
Copy link
Contributor

Choose a reason for hiding this comment

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

这两个函数起名有点模糊,之后可以考虑系统性优化下

Copy link
Contributor

Choose a reason for hiding this comment

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

是的,这俩是历史遗留问题了,slice后面估计要大改

Copy link
Contributor Author

Choose a reason for hiding this comment

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

收到

if (out_shape.data().has_value() && out_shape.shape().empty()) { // 0D tensor
const paddle::dialect::DenseTensorType &tensor_type =
out.type().dyn_cast<paddle::dialect::DenseTensorType>();
Expand Down