未验证 提交 8412d6c0 编写于 作者: 王明冬 提交者: GitHub

register the with_quant_attr attribute for all operattor. test=develop (#35591)

上级 ec252914
......@@ -25,7 +25,7 @@ std::unordered_set<std::string> 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 {
......
......@@ -98,6 +98,12 @@ void OpProtoAndCheckerMaker::operator()(proto::OpProto* proto,
AddAttr<std::string>(OpDeviceAttrName(), "Device type of this operator.")
.SetDefault("")
.AsExtra();
AddAttr<bool>(OpWithQuantAttrName(),
"Whether the operator has attributes used by quantization. ")
.SetDefault(false)
.AsExtra();
Validate();
}
......
......@@ -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);
......
......@@ -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())) {
......
......@@ -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; });
......
......@@ -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)
"""
......
......@@ -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)
......
......@@ -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()
]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册