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.122】【BUAA】Add batch_fc #67348

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 @@ -228,12 +228,41 @@ bool AucOpInferSymbolicShape(pir::Operation *op,
return true;
}

// bool BatchFcOpInferSymbolicShape(pir::Operation *op,
// pir::InferSymbolicShapeContext
// *infer_context) {
// // pass
// return true;
// }
bool BatchFcOpInferSymbolicShape(
pir::Operation *op, pir::InferSymbolicShapeContext *infer_context) {
const auto &input_shape_or_data =
infer_context->GetShapeOrDataForValue(op->operand_source(0));
const auto &w_shape_or_data =
infer_context->GetShapeOrDataForValue(op->operand_source(1));
const auto &bias_shape_or_data =
infer_context->GetShapeOrDataForValue(op->operand_source(2));

const std::vector<symbol::DimExpr> &input_dims = input_shape_or_data.shape();
const std::vector<symbol::DimExpr> &w_dims = w_shape_or_data.shape();
const std::vector<symbol::DimExpr> &bias_dims = bias_shape_or_data.shape();

PADDLE_ENFORCE_EQ(
input_dims.size(),
3,
common::errors::InvalidArgument("Input of BatchFcOp should have 3D."));
PADDLE_ENFORCE_EQ(
w_dims.size(),
3,
common::errors::InvalidArgument("W of BatchFcOp should have 3D."));
infer_context->AddEqualCstr(input_dims[0], w_dims[0]);
infer_context->AddEqualCstr(input_dims[2], w_dims[1]);
infer_context->AddEqualCstr(bias_dims[0], input_dims[0]);
infer_context->AddEqualCstr(bias_dims[1], w_dims[2]);

std::vector<symbol::DimExpr> out_dims = {
input_dims[0], input_dims[1], w_dims[2]};

infer_context->SetShapeOrDataForValue(
op->result(0),
symbol::ShapeOrDataDimExprs{symbol::TensorShapeOrDataDimExprs(out_dims)});

return true;
}

bool BatchNormOpInferSymbolicShape(
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(AddN)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(Auc)
// OP_DECLARE_INFER_SYMBOLIC_SHAPE(AssignPos)
// OP_DECLARE_INFER_SYMBOLIC_SHAPE(BroadcastTensors)
// OP_DECLARE_INFER_SYMBOLIC_SHAPE(BatchFc)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(BatchFc)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(BatchNorm)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(BatchNorm_)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(BicubicInterp)
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 @@ -464,6 +464,7 @@
func : batch_fc
data_type: input
backward: batch_fc_grad
interfaces : paddle::dialect::InferSymbolicShapeInterface

- op : bce_loss
args : (Tensor input, Tensor label)
Expand Down