Skip to content
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 @@ -359,6 +359,42 @@ bool EigvalshOpInferSymbolicShape(
return EighOpInferSymbolicShape(op, infer_context);
}

bool FakeChannelWiseQuantizeAbsMaxOpInferSymbolicShape(

@gongshaotian gongshaotian Jul 29, 2024 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

看一下添加OpTest单测是否复杂

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

已经存在TestFakeChannelWiseQuantizeAbsMaxOp(OpTest)但没有打开 check_pir 和 check_symbol_infer 两个flag,请问这个情况如何修改

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

  1. 不需要再修改单测了 2. 需要把PR标题修改为全英文

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

已完成修改

pir::Operation *op, pir::InferSymbolicShapeContext *infer_context) {
const auto &x_shape_or_data =
infer_context->GetShapeOrDataForValue(op->operand_source(0));

int bit_length = op->attribute<pir::Int32Attribute>("bit_length").data();
int quant_axis = op->attribute<pir::Int32Attribute>("quant_axis").data();

PADDLE_ENFORCE_EQ(bit_length >= 1 && bit_length <= 16,
true,
common::errors::InvalidArgument(
"'bit_length' should be between 1 and 16, but "
"the received is %d",
bit_length));
PADDLE_ENFORCE_EQ(
quant_axis == 0 || quant_axis == 1,
true,
common::errors::InvalidArgument("'quant_axis' should be 0 or 1, but "
"the received is %d",
quant_axis));

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

std::vector<symbol::DimExpr> out_scale_shape = {
x_shape_or_data.shape()[quant_axis]};
infer_context->SetShapeOrDataForValue(
op->result(1),
symbol::ShapeOrDataDimExprs{
symbol::TensorShapeOrDataDimExprs(out_scale_shape)});

return true;
}

bool FftC2cOpInferSymbolicShape(pir::Operation *op,
pir::InferSymbolicShapeContext *infer_context) {
const auto &x_shape_or_data =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ OP_DECLARE_INFER_SYMBOLIC_SHAPE(Diagonal)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(DistributeFpnProposals)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(Eigh)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(Eigvalsh)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(FakeChannelWiseQuantizeAbsMax)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(FftC2c)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(FftC2r)
OP_DECLARE_INFER_SYMBOLIC_SHAPE(FftR2c)
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 @@ -1649,6 +1649,7 @@
kernel :
func : fake_channel_wise_quantize_abs_max
data_type : x
interfaces : paddle::dialect::InferSymbolicShapeInterface

- op : fake_channel_wise_quantize_dequantize_abs_max
args : (Tensor x, int bit_length = 8, int round_type = 1, int quant_axis = 0)
Expand Down