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

【BUAA】【Infer Symbolic Shape】add shardindex #67407

Merged
merged 3 commits into from
Aug 16, 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
Original file line number Diff line number Diff line change
Expand Up @@ -1960,6 +1960,25 @@ bool ShapeOpInferSymbolicShape(pir::Operation *op,
return true;
}

bool ShardIndexOpInferSymbolicShape(
pir::Operation *op, pir::InferSymbolicShapeContext *infer_context) {
const auto &in_shape_or_data =
infer_context->GetShapeOrDataForValue(op->operand_source(0));
const std::vector<symbol::DimExpr> &in_shape = in_shape_or_data.shape();
PADDLE_ENFORCE_GE(
in_shape.size(),
2,
common::errors::InvalidArgument("Rank of Input(X) should be at least 2, "
"but the value given is %d.",
in_shape.size()));
infer_context->AddEqualCstr(in_shape[in_shape.size() - 1],
symbol::DimExpr{1});
infer_context->SetShapeOrDataForValue(
op->result(0),
symbol::ShapeOrDataDimExprs{symbol::TensorShapeOrDataDimExprs(in_shape)});
return true;
}

bool RreluOpInferSymbolicShape(pir::Operation *op,
pir::InferSymbolicShapeContext *infer_context) {
float lower = op->attribute<pir::FloatAttribute>("lower").data();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ OP_DECLARE_INFER_SYMBOLIC_SHAPE(Reshape_)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(Rrelu)
// OP_DECLARE_INFER_SYMBOLIC_SHAPE(SequencePool)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(Shape)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(ShardIndex)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(ShapeSr)
// OP_DECLARE_INFER_SYMBOLIC_SHAPE(ShardIndex)
// OP_DECLARE_INFER_SYMBOLIC_SHAPE(ShuffleChannel)
Expand Down
2 changes: 1 addition & 1 deletion paddle/phi/ops/yaml/ops.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4233,7 +4233,7 @@
func : ShardIndexInferMeta
kernel :
func : shard_index
# interfaces : paddle::dialect::InferSymbolicShapeInterface
interfaces : paddle::dialect::InferSymbolicShapeInterface

- op : share_data
args: (Tensor x)
Expand Down