From 49797d85da26ffca17e66eaa83308c8d669026a9 Mon Sep 17 00:00:00 2001 From: wawltor Date: Mon, 6 Sep 2021 19:51:33 +0800 Subject: [PATCH] Add the extra flag for the some ops (#35442) * Add the extra flag for the some ops * fix the compile problem in matmul extra --- .../operators/elementwise/elementwise_op.h | 24 ++++++++---- paddle/fluid/operators/matmul_op.cc | 39 ++++++++++++------- paddle/fluid/operators/matmul_v2_op.cc | 6 ++- paddle/fluid/operators/mul_op.cc | 12 ++++-- 4 files changed, 54 insertions(+), 27 deletions(-) diff --git a/paddle/fluid/operators/elementwise/elementwise_op.h b/paddle/fluid/operators/elementwise/elementwise_op.h index d6cf58f7a15..3614602156f 100644 --- a/paddle/fluid/operators/elementwise/elementwise_op.h +++ b/paddle/fluid/operators/elementwise/elementwise_op.h @@ -165,31 +165,39 @@ class ElementwiseOpMaker : public framework::OpProtoAndCheckerMaker { "for broadcasting Y onto X. ") .SetDefault(-1); AddAttr("use_mkldnn", "(bool, default false). Used by MKLDNN.") - .SetDefault(false); + .SetDefault(false) + .AsExtra(); AddAttr("x_data_format", "This parameter is no longer used.") - .SetDefault(""); + .SetDefault("") + .AsExtra(); AddAttr("y_data_format", "This parameter is no longer used.") - .SetDefault(""); + .SetDefault("") + .AsExtra(); AddAttr( "use_quantizer", "(bool, default false) " "This parameter is no longer used. Use 'mkldnn_data_type' instead.") - .SetDefault(false); + .SetDefault(false) + .AsExtra(); AddAttr( "mkldnn_data_type", "(string, default \"float32\"). Data type of mkldnn kernel") .SetDefault("float32") - .InEnum({"float32", "int8", "bfloat16"}); + .InEnum({"float32", "int8", "bfloat16"}) + .AsExtra(); /* int8 parameters */ AddAttr("Scale_x", "(float, default 1.0f), The quantize scale of X tensor") - .SetDefault(1.0f); + .SetDefault(1.0f) + .AsExtra(); AddAttr("Scale_y", "(float, default 1.0f), The quantize scale of Y tensor") - .SetDefault(1.0f); + .SetDefault(1.0f) + .AsExtra(); AddAttr("Scale_out", "(float, default 1.0f), The quantize scale of output data") - .SetDefault(1.0f); + .SetDefault(1.0f) + .AsExtra(); AddOpComment(); } diff --git a/paddle/fluid/operators/matmul_op.cc b/paddle/fluid/operators/matmul_op.cc index 78747108d44..c0d813ccc21 100644 --- a/paddle/fluid/operators/matmul_op.cc +++ b/paddle/fluid/operators/matmul_op.cc @@ -715,53 +715,66 @@ class MatMulOpMaker : public framework::OpProtoAndCheckerMaker { AddAttr( "use_mkldnn", "(bool, default false) Indicates if MKL-DNN kernel will be used") - .SetDefault(false); + .SetDefault(false) + .AsExtra(); AddAttr>("fused_reshape_X", R"DOC(Shape of fused reshape of `X` input.)DOC") - .SetDefault({}); + .SetDefault({}) + .AsExtra(); AddAttr>("fused_reshape_Y", R"DOC(Shape of fused reshape of `Y` input.)DOC") - .SetDefault({}); + .SetDefault({}) + .AsExtra(); AddAttr>("fused_transpose_X", R"DOC(Axis of fused transpose of `X` input.)DOC") - .SetDefault({}); + .SetDefault({}) + .AsExtra(); AddAttr>("fused_transpose_Y", R"DOC(Axis of fused transpose of `Y` input.)DOC") - .SetDefault({}); + .SetDefault({}) + .AsExtra(); AddAttr>( "fused_reshape_Out", R"DOC(When MKLDNN MatMul_transpose_reshape fuse activated, " "it's a shape atribute of fused reshape for `Out` output.)DOC") - .SetDefault({}); + .SetDefault({}) + .AsExtra(); AddAttr>( "fused_transpose_Out", R"DOC(When MKLDNN MatMul_transpose_reshape fuse activated, " "it's a axis atribute of fused transpose for `Out` output.)DOC") - .SetDefault({}); + .SetDefault({}) + .AsExtra(); AddAttr( "use_quantizer", "(bool, default false) " "This parameter is no longer used. Use 'mkldnn_data_type' instead.") - .SetDefault(false); + .SetDefault(false) + .AsExtra(); AddAttr( "mkldnn_data_type", "(string, default \"float32\"). Data type of mkldnn kernel") .SetDefault("float32") - .InEnum({"float32", "int8", "bfloat16"}); + .InEnum({"float32", "int8", "bfloat16"}) + .AsExtra(); /* int8 parameters */ AddAttr("Scale_x", "(float, default 1.0f), The quantize scale of X tensor") - .SetDefault(1.0f); + .SetDefault(1.0f) + .AsExtra(); AddAttr("Scale_y", "(float, default 1.0f), The quantize scale of Y tensor") - .SetDefault(1.0f); + .SetDefault(1.0f) + .AsExtra(); AddAttr("Scale_out", "(float, default 1.0f), The quantize scale of output data") - .SetDefault(1.0f); + .SetDefault(1.0f) + .AsExtra(); AddAttr("force_fp32_output", "(bool, default false) Force INT8 kernel output FP32, only " "used in MKL-DNN INT8") - .SetDefault(false); + .SetDefault(false) + .AsExtra(); #if defined(PADDLE_WITH_MKLML) && !defined(PADDLE_WITH_CUDA) && \ !defined(PADDLE_WITH_HIP) diff --git a/paddle/fluid/operators/matmul_v2_op.cc b/paddle/fluid/operators/matmul_v2_op.cc index 4ec9a052bb2..b875149ec63 100644 --- a/paddle/fluid/operators/matmul_v2_op.cc +++ b/paddle/fluid/operators/matmul_v2_op.cc @@ -141,12 +141,14 @@ class MatMulV2OpMaker : public framework::OpProtoAndCheckerMaker { .SetDefault(false); AddAttr("use_mkldnn", "(bool, default false) Only used in mkldnn kernel") - .SetDefault(false); + .SetDefault(false) + .AsExtra(); AddAttr( "mkldnn_data_type", "(string, default \"float32\"). Data type of mkldnn kernel") .SetDefault("float32") - .InEnum({"float32", "bfloat16"}); + .InEnum({"float32", "bfloat16"}) + .AsExtra(); AddComment( R"DOC(Matrix multiplication Out = X * Y. A has shape (d0, d1 ... M, K), B has shape (d0, d1 ... K, N), Out has shape ((d0, d1 ... M, N)). diff --git a/paddle/fluid/operators/mul_op.cc b/paddle/fluid/operators/mul_op.cc index 5d168288953..14291f84584 100644 --- a/paddle/fluid/operators/mul_op.cc +++ b/paddle/fluid/operators/mul_op.cc @@ -166,22 +166,26 @@ class MulOpMaker : public framework::OpProtoAndCheckerMaker { "scale_x to be used for int8 mul input data x. scale_x has the" "same purpose as scale_in in OPs that support quantization." "Only to be used with MKL-DNN INT8") - .SetDefault(1.0f); + .SetDefault(1.0f) + .AsExtra(); AddAttr>( "scale_y", "scale_y to be used for int8 mul input data y. scale_y has the" "same purpose as scale_weights in OPs that support quantization." "Only to be used with MKL-DNN INT8") - .SetDefault({1.0f}); + .SetDefault({1.0f}) + .AsExtra(); AddAttr("scale_out", "scale_out to be used for int8 output data." "Only used with MKL-DNN INT8") - .SetDefault(1.0f); + .SetDefault(1.0f) + .AsExtra(); AddAttr( "force_fp32_output", "(bool, default false) Force quantize kernel output FP32, only " "used in quantized MKL-DNN.") - .SetDefault(false); + .SetDefault(false) + .AsExtra(); AddComment(R"DOC( Mul Operator. -- GitLab