diff --git a/paddle/fluid/framework/ir/op_compat_sensible_pass.cc b/paddle/fluid/framework/ir/op_compat_sensible_pass.cc index 8261a0b8ca7c32f306b307715c53d43072c6bc92..73a8691f9e269000dfd3ff24e66b738646436df2 100644 --- a/paddle/fluid/framework/ir/op_compat_sensible_pass.cc +++ b/paddle/fluid/framework/ir/op_compat_sensible_pass.cc @@ -25,7 +25,7 @@ std::unordered_set global_extra_attrs = { "op_callstack", "op_device", "@ENABLE_CACHE_RUNTIME_CONTEXT@", "is_test", "use_mkldnn", "mkldnn_data_type", "use_quantizer", "mkldnn_data_type", "use_cudnn", - "name"}; + "name", "with_quant_attr"}; } namespace paddle { diff --git a/paddle/fluid/framework/op_proto_maker.cc b/paddle/fluid/framework/op_proto_maker.cc index fc2012b1176ef7441ef98b3c87077e1ae0e62273..3c76c4661670aff24bbf7918e888859524d8e379 100644 --- a/paddle/fluid/framework/op_proto_maker.cc +++ b/paddle/fluid/framework/op_proto_maker.cc @@ -98,6 +98,12 @@ void OpProtoAndCheckerMaker::operator()(proto::OpProto* proto, AddAttr(OpDeviceAttrName(), "Device type of this operator.") .SetDefault("") .AsExtra(); + + AddAttr(OpWithQuantAttrName(), + "Whether the operator has attributes used by quantization. ") + .SetDefault(false) + .AsExtra(); + Validate(); } diff --git a/paddle/fluid/framework/op_proto_maker.h b/paddle/fluid/framework/op_proto_maker.h index 932c76e242581296213e630f0f27f4200d27fed0..903ee73b2c01364b482983d14ecb7af8e43066d5 100644 --- a/paddle/fluid/framework/op_proto_maker.h +++ b/paddle/fluid/framework/op_proto_maker.h @@ -48,6 +48,7 @@ class OpProtoAndCheckerMaker { static const char *OpNamescopeAttrName() { return "op_namescope"; } static const char *OpCreationCallstackAttrName() { return "op_callstack"; } static const char *OpDeviceAttrName() { return "op_device"; } + static const char *OpWithQuantAttrName() { return "with_quant_attr"; } void operator()(proto::OpProto *proto, OpAttrChecker *attr_checker); diff --git a/paddle/fluid/operators/benchmark/op_tester.cc b/paddle/fluid/operators/benchmark/op_tester.cc index c8a04c3242cedbbef2a3b6d930b36b86e7ce06ec..603eec4d52232e2826408533e805e96082826d4f 100644 --- a/paddle/fluid/operators/benchmark/op_tester.cc +++ b/paddle/fluid/operators/benchmark/op_tester.cc @@ -142,7 +142,8 @@ OpTester::GetOpProtoAttrNames() { framework::OpProtoAndCheckerMaker::OpRoleAttrName(), framework::OpProtoAndCheckerMaker::OpRoleVarAttrName(), framework::OpProtoAndCheckerMaker::OpNamescopeAttrName(), - framework::OpProtoAndCheckerMaker::OpCreationCallstackAttrName()}; + framework::OpProtoAndCheckerMaker::OpCreationCallstackAttrName(), + framework::OpProtoAndCheckerMaker::OpWithQuantAttrName()}; for (int i = 0; i != proto.attrs_size(); ++i) { const auto &attr = proto.attrs(i); if (!Has(skipped_attrs, attr.name())) { diff --git a/paddle/fluid/pybind/const_value.cc b/paddle/fluid/pybind/const_value.cc index 30d04e62e69d3c3ada1dbf2fc37f072e27ce45c7..8b48d0b4e44ca8d2e0ca63c4eb8742dfd6d53271 100644 --- a/paddle/fluid/pybind/const_value.cc +++ b/paddle/fluid/pybind/const_value.cc @@ -63,6 +63,9 @@ void BindConstValue(pybind11::module* m) { framework::OpProtoAndCheckerMaker::OpCreationCallstackAttrName); op_proto_and_checker_maker.def( "kOpDeviceAttrName", framework::OpProtoAndCheckerMaker::OpDeviceAttrName); + op_proto_and_checker_maker.def( + "kOpWithQuantAttrName", + framework::OpProtoAndCheckerMaker::OpWithQuantAttrName); #if defined(PADDLE_WITH_DGC) auto dgc = m->def_submodule("dgc"); dgc.def("kDGCKName", [] { return framework::details::g_dgc_k; }); diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index dc436a70cb97db5adbd2f17dc8a7bdfa1f94517e..4a93c7d11fd8aedaaf8faf770296e6dd920e8626 100755 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -11558,13 +11558,13 @@ Examples: import paddle.fluid as fluid import numpy as np - + import paddle def gen_data(): return { "x": np.array([2, 3, 4]).astype('float32'), "y": np.array([1, 5, 2]).astype('float32') } - + paddle.enable_static() x = fluid.data(name="x", shape=[3], dtype='float32') y = fluid.data(name="y", shape=[3], dtype='float32') z = fluid.layers.elementwise_add(x, y) @@ -11582,13 +11582,14 @@ Examples: import paddle.fluid as fluid import numpy as np + import paddle def gen_data(): return { "x": np.ones((2, 3, 4, 5)).astype('float32'), "y": np.zeros((3, 4)).astype('float32') } - + paddle.enable_static() x = fluid.data(name="x", shape=[2,3,4,5], dtype='float32') y = fluid.data(name="y", shape=[3,4], dtype='float32') z = fluid.layers.elementwise_add(x, y, axis=1) @@ -11607,13 +11608,14 @@ Examples: import paddle.fluid as fluid import numpy as np + import paddle def gen_data(): return { "x": np.random.randint(1, 5, size=[2, 3, 4, 5]).astype('float32'), "y": np.random.randint(1, 5, size=[5]).astype('float32') } - + paddle.enable_static() x = fluid.data(name="x", shape=[2,3,4,5], dtype='float32') y = fluid.data(name="y", shape=[5], dtype='float32') z = fluid.layers.elementwise_add(x, y, axis=3) @@ -11649,13 +11651,14 @@ Examples: import paddle.fluid as fluid import numpy as np + import paddle def gen_data(): return { "x": np.array([2, 3, 4]).astype('float32'), "y": np.array([1, 5, 2]).astype('float32') } - + paddle.enable_static() x = fluid.data(name="x", shape=[3], dtype='float32') y = fluid.data(name="y", shape=[3], dtype='float32') z = fluid.layers.elementwise_div(x, y) @@ -11673,13 +11676,14 @@ Examples: import paddle.fluid as fluid import numpy as np + import paddle def gen_data(): return { "x": np.ones((2, 3, 4, 5)).astype('float32'), "y": np.zeros((3, 4)).astype('float32') } - + paddle.enable_static() x = fluid.data(name="x", shape=[2,3,4,5], dtype='float32') y = fluid.data(name="y", shape=[3,4], dtype='float32') z = fluid.layers.elementwise_div(x, y, axis=1) @@ -11698,13 +11702,14 @@ Examples: import paddle.fluid as fluid import numpy as np + import paddle def gen_data(): return { "x": np.random.randint(1, 5, size=[2, 3, 4, 5]).astype('float32'), "y": np.random.randint(1, 5, size=[5]).astype('float32') } - + paddle.enable_static() x = fluid.data(name="x", shape=[2,3,4,5], dtype='float32') y = fluid.data(name="y", shape=[5], dtype='float32') z = fluid.layers.elementwise_div(x, y, axis=3) @@ -11734,13 +11739,14 @@ Examples: import paddle.fluid as fluid import numpy as np + import paddle def gen_data(): return { "x": np.array([2, 3, 4]).astype('float32'), "y": np.array([1, 5, 2]).astype('float32') } - + paddle.enable_static() x = fluid.data(name="x", shape=[3], dtype='float32') y = fluid.data(name="y", shape=[3], dtype='float32') z = fluid.layers.elementwise_sub(x, y) @@ -11758,13 +11764,14 @@ Examples: import paddle.fluid as fluid import numpy as np + import paddle def gen_data(): return { "x": np.ones((2, 3, 4, 5)).astype('float32'), "y": np.zeros((3, 4)).astype('float32') } - + paddle.enable_static() x = fluid.data(name="x", shape=[2,3,4,5], dtype='float32') y = fluid.data(name="y", shape=[3,4], dtype='float32') z = fluid.layers.elementwise_sub(x, y, axis=1) @@ -11783,13 +11790,14 @@ Examples: import paddle.fluid as fluid import numpy as np + import paddle def gen_data(): return { "x": np.random.randint(1, 5, size=[2, 3, 4, 5]).astype('float32'), "y": np.random.randint(1, 5, size=[5]).astype('float32') } - + paddle.enable_static() x = fluid.data(name="x", shape=[2,3,4,5], dtype='float32') y = fluid.data(name="y", shape=[5], dtype='float32') z = fluid.layers.elementwise_sub(x, y, axis=3) @@ -11820,13 +11828,14 @@ Examples: import paddle.fluid as fluid import numpy as np + import paddle def gen_data(): return { "x": np.array([2, 3, 4]).astype('float32'), "y": np.array([1, 5, 2]).astype('float32') } - + paddle.enable_static() x = fluid.data(name="x", shape=[3], dtype='float32') y = fluid.data(name="y", shape=[3], dtype='float32') z = fluid.layers.elementwise_mul(x, y) @@ -11844,13 +11853,14 @@ Examples: import paddle.fluid as fluid import numpy as np + import paddle def gen_data(): return { "x": np.ones((2, 3, 4, 5)).astype('float32'), "y": np.zeros((3, 4)).astype('float32') } - + paddle.enable_static() x = fluid.data(name="x", shape=[2,3,4,5], dtype='float32') y = fluid.data(name="y", shape=[3,4], dtype='float32') z = fluid.layers.elementwise_mul(x, y, axis=1) @@ -11869,13 +11879,14 @@ Examples: import paddle.fluid as fluid import numpy as np + import paddle def gen_data(): return { "x": np.random.randint(1, 5, size=[2, 3, 4, 5]).astype('float32'), "y": np.random.randint(1, 5, size=[5]).astype('float32') } - + paddle.enable_static() x = fluid.data(name="x", shape=[2,3,4,5], dtype='float32') y = fluid.data(name="y", shape=[5], dtype='float32') z = fluid.layers.elementwise_mul(x, y, axis=3) @@ -11908,13 +11919,14 @@ Examples: import paddle.fluid as fluid import numpy as np + import paddle def gen_data(): return { "x": np.array([2, 3, 4]).astype('float32'), "y": np.array([1, 5, 2]).astype('float32') } - + paddle.enable_static() x = fluid.data(name="x", shape=[3], dtype='float32') y = fluid.data(name="y", shape=[3], dtype='float32') z = fluid.layers.elementwise_max(x, y) @@ -11931,13 +11943,14 @@ Examples: import paddle.fluid as fluid import numpy as np + import paddle def gen_data(): return { "x": np.ones((2, 3, 4, 5)).astype('float32'), "y": np.zeros((3, 4)).astype('float32') } - + paddle.enable_static() x = fluid.data(name="x", shape=[2,3,4,5], dtype='float32') y = fluid.data(name="y", shape=[3,4], dtype='float32') z = fluid.layers.elementwise_max(x, y, axis=1) @@ -11970,13 +11983,14 @@ Examples: import paddle.fluid as fluid import numpy as np + import paddle def gen_data(): return { "x": np.array([2, 3, 4]).astype('float32'), "y": np.array([1, 5, 2]).astype('float32') } - + paddle.enable_static() x = fluid.data(name="x", shape=[3], dtype='float32') y = fluid.data(name="y", shape=[3], dtype='float32') z = fluid.layers.elementwise_min(x, y) @@ -11992,13 +12006,14 @@ Examples: import paddle.fluid as fluid import numpy as np + import paddle def gen_data(): return { "x": np.ones((2, 3, 4, 5)).astype('float32'), "y": np.zeros((3, 4)).astype('float32') } - + paddle.enable_static() x = fluid.data(name="x", shape=[2,3,4,5], dtype='float32') y = fluid.data(name="y", shape=[3,4], dtype='float32') z = fluid.layers.elementwise_min(x, y, axis=1) @@ -12027,13 +12042,14 @@ Examples: import paddle.fluid as fluid import numpy as np + import paddle def gen_data(): return { "x": np.array([2, 3, 4]).astype('float32'), "y": np.array([1, 5, 2]).astype('float32') } - + paddle.enable_static() x = fluid.data(name="x", shape=[3], dtype='float32') y = fluid.data(name="y", shape=[3], dtype='float32') z = fluid.layers.elementwise_pow(x, y) @@ -12061,13 +12077,14 @@ Examples: import paddle.fluid as fluid import numpy as np + import paddle def gen_data(): return { "x": np.array([10, 15, 8]).astype('int32'), "y": np.array([3, 6, 5]).astype('int32') } - + paddle.enable_static() x = fluid.data(name="x", shape=[3], dtype='int32') y = fluid.data(name="y", shape=[3], dtype='int32') z = fluid.layers.elementwise_mod(x, y) @@ -12096,13 +12113,14 @@ Examples: import paddle.fluid as fluid import numpy as np + import paddle def gen_data(): return { "x": np.array([10, 15, 8]).astype('int32'), "y": np.array([3, 7, 5]).astype('int32') } - + paddle.enable_static() x = fluid.data(name="x", shape=[3], dtype='int32') y = fluid.data(name="y", shape=[3], dtype='int32') z = fluid.layers.elementwise_floordiv(x, y) @@ -13423,8 +13441,8 @@ def shuffle_channel(x, group, name=None): .. code-block:: python import paddle - import paddle.fluid as fluid - paddle.enable_static() + import paddle.fluid as fluid + paddle.enable_static() input = fluid.data(name='input', shape=[None,4,2,2], dtype='float32') out = fluid.layers.shuffle_channel(x=input, group=2) """ diff --git a/python/paddle/fluid/tests/unittests/test_operator_desc.py b/python/paddle/fluid/tests/unittests/test_operator_desc.py index 0a7afe8caf22de8631b2dfb056b922fda174b0e1..cf1f12411e22ca964d3e7c816829b93e27aed3ee 100644 --- a/python/paddle/fluid/tests/unittests/test_operator_desc.py +++ b/python/paddle/fluid/tests/unittests/test_operator_desc.py @@ -70,7 +70,8 @@ class TestOperator(unittest.TestCase): set([ "x_num_col_dims", "y_num_col_dims", "op_role", "op_role_var", "use_mkldnn", "scale_x", "scale_y", "scale_out", - "force_fp32_output", "op_namescope", "op_callstack", "op_device" + "force_fp32_output", "op_namescope", "op_callstack", + "op_device", "with_quant_attr" ])) self.assertEqual(mul_op.has_attr("x_num_col_dims"), True) self.assertEqual(mul_op.attr_type("x_num_col_dims"), core.AttrType.INT) diff --git a/python/paddle/utils/cpp_extension/extension_utils.py b/python/paddle/utils/cpp_extension/extension_utils.py index 4a9ecb9b78b1d23dad89b80c59ebb55d03a716bb..0a2d71abfdee4f16a142ce1d100d27017681abca 100644 --- a/python/paddle/utils/cpp_extension/extension_utils.py +++ b/python/paddle/utils/cpp_extension/extension_utils.py @@ -100,7 +100,8 @@ DEFAULT_OP_ATTR_NAMES = [ core.op_proto_and_checker_maker.kOpRoleVarAttrName(), core.op_proto_and_checker_maker.kOpNameScopeAttrName(), core.op_proto_and_checker_maker.kOpCreationCallstackAttrName(), - core.op_proto_and_checker_maker.kOpDeviceAttrName() + core.op_proto_and_checker_maker.kOpDeviceAttrName(), + core.op_proto_and_checker_maker.kOpWithQuantAttrName() ]