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

【Infer Symbolic Shape No.123】【BUAA】Add Bincount #67435

Merged
merged 21 commits into from
Aug 23, 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 @@ -200,12 +200,42 @@ bool Binomial_OpInferSymbolicShape(
return BinomialOpInferSymbolicShape(op, infer_context);
}

// bool BincountOpInferSymbolicShape(pir::Operation *op,
// pir::InferSymbolicShapeContext
// *infer_context) {
// // pass
// return true;
// }
bool BincountOpInferSymbolicShape(
pir::Operation *op, pir::InferSymbolicShapeContext *infer_context) {
const auto &x_shape_or_data =
infer_context->GetShapeOrDataForValue(op->operand_source(0));
const std::vector<symbol::DimExpr> &x_dims = x_shape_or_data.shape();

PADDLE_ENFORCE_EQ(x_dims.size(),
1,
common::errors::InvalidArgument(
"The 'shape' of Input(X) must be 1-D tensor. But the "
"dimension of Input(X) is [%d]",
x_dims.size()));

if (op->operand_source(1)) {
const auto &weights_shape_or_data =
infer_context->GetShapeOrDataForValue(op->operand_source(1));
const std::vector<symbol::DimExpr> &weights_dims =
weights_shape_or_data.shape();

PADDLE_ENFORCE_EQ(weights_dims.size(),
1,
common::errors::InvalidArgument(
"The 'shape' of Input(Weights) must be 1-D tensor. "
"But the dimension of Input(Weights) is [%d]",
weights_dims.size()));
infer_context->AddEqualCstr(weights_dims[0], x_dims[0]);
}

symbol::DimExpr out_unknown = infer_context->GetNextSymName();
const std::vector<symbol::DimExpr> out_dims = {out_unknown};
symbol::ShapeOrDataDimExprs output_dims{
symbol::TensorShapeOrDataDimExprs(out_dims)};
infer_context->SetShapeOrDataForValue(op->result(0), output_dims);

return true;
}

// bool BmmOpInferSymbolicShape(pir::Operation *op,
// pir::InferSymbolicShapeContext *infer_context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ OP_DECLARE_INFER_SYMBOLIC_SHAPE(BceLoss_)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(BoxClip)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(Binomial)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(Binomial_)
// OP_DECLARE_INFER_SYMBOLIC_SHAPE(Bincount)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(Bincount)
// OP_DECLARE_INFER_SYMBOLIC_SHAPE(Bmm)
// OP_DECLARE_INFER_SYMBOLIC_SHAPE(CholeskySolve)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(CtcAlign)
Expand Down
1 change: 1 addition & 0 deletions paddle/phi/ops/yaml/ops.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@
kernel:
func: bincount
optional: weights
interfaces : paddle::dialect::InferSymbolicShapeInterface

- op : binomial
args : (Tensor count, Tensor prob)
Expand Down
2 changes: 1 addition & 1 deletion test/legacy_test/test_bincount_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def init_test_case(self):
self.Out = np.bincount(self.np_input, minlength=self.minlength)

def test_check_output(self):
self.check_output(check_pir=True)
self.check_output(check_pir=True, check_symbol_infer=False)


class TestCase1(TestBincountOp):
Expand Down