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 weighted_sample_neighbors for CINN #67858

Merged
merged 5 commits into from
Sep 3, 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 @@ -2840,11 +2840,60 @@ bool WarprnntOpInferSymbolicShape(
// return true;
// }

// bool WeightedSampleNeighborsOpInferSymbolicShape(
// pir::Operation *op, pir::InferSymbolicShapeContext *infer_context) {
// // pass
// return true;
// }
bool WeightedSampleNeighborsOpInferSymbolicShape(
pir::Operation *op, pir::InferSymbolicShapeContext *infer_context) {
auto GSNShapeCheck = [](const ExprVec &input_shape,
std::string tensor_name,
pir::InferSymbolicShapeContext *infer_context) {
if (input_shape.size() == 2) {
infer_context->AddEqualCstr(input_shape[1], symbol::DimExpr(1));
} else {
PADDLE_ENFORCE_EQ(
input_shape.size(),
1,
phi::errors::InvalidArgument(
"The %s should be 1D, when it is not 2D, but we get %d",
tensor_name,
input_shape.size()));
}
};

const auto &row_shape =
infer_context->GetShapeOrDataForValue(op->operand_source(0)).shape();
const auto &col_ptr_shape =
infer_context->GetShapeOrDataForValue(op->operand_source(1)).shape();
const auto &edge_weight_shape =
infer_context->GetShapeOrDataForValue(op->operand_source(2)).shape();
const auto &x_shape =
infer_context->GetShapeOrDataForValue(op->operand_source(3)).shape();
const auto &eids_shape =
infer_context->GetShapeOrDataForValue(op->operand_source(4)).shape();
bool return_eids = op->attribute<pir::BoolAttribute>("return_eids").data();

GSNShapeCheck(row_shape, "row", infer_context);
GSNShapeCheck(col_ptr_shape, "col_ptr", infer_context);
GSNShapeCheck(edge_weight_shape, "edge_weight", infer_context);
GSNShapeCheck(x_shape, "input_nodes", infer_context);

infer_context->SetShapeOrDataForValue(
op->result(0),
symbol::ShapeOrDataDimExprs{symbol::TensorShapeOrDataDimExprs(
{infer_context->GetNextSymName()})});
infer_context->SetShapeOrDataForValue(
op->result(1),
symbol::ShapeOrDataDimExprs{symbol::TensorShapeOrDataDimExprs(
{infer_context->GetNextSymName()})});
if (return_eids) {
GSNShapeCheck(eids_shape, "eids", infer_context);
infer_context->SetShapeOrDataForValue(
op->result(2),
symbol::ShapeOrDataDimExprs{symbol::TensorShapeOrDataDimExprs(
{infer_context->GetNextSymName()})});
} else {
infer_context->SetSymbolForValueByStaticShape(op->result(2));
}
return true;
}

bool WhereOpInferSymbolicShape(pir::Operation *op,
pir::InferSymbolicShapeContext *infer_context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ OP_DECLARE_INFER_SYMBOLIC_SHAPE(ViterbiDecode)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(Warpctc)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(Warprnnt)
// OP_DECLARE_INFER_SYMBOLIC_SHAPE(WeightOnlyLinear)
// OP_DECLARE_INFER_SYMBOLIC_SHAPE(WeightedSampleNeighbors)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(WeightedSampleNeighbors)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(Where)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(Where_)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(YoloLoss)
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 @@ -5123,7 +5123,7 @@
kernel :
func : weighted_sample_neighbors
optional : eids
# interfaces : paddle::dialect::InferSymbolicShapeInterface
interfaces : paddle::dialect::InferSymbolicShapeInterface

- op : where
args : (Tensor condition, Tensor x, Tensor y)
Expand Down