From 2a81091f8f550c73cc71521b0bd345f7caac775a Mon Sep 17 00:00:00 2001 From: Bartosz Kuncer Date: Tue, 19 Oct 2021 13:13:10 +0200 Subject: [PATCH 1/5] Add aliases --- python/mxnet/amp/lists/symbol_bf16.py | 2 ++ python/mxnet/amp/lists/symbol_fp16.py | 4 ++++ src/operator/quantization/quantize_graph_pass.cc | 2 +- src/operator/subgraph/dnnl/dnnl_conv.cc | 1 + src/operator/subgraph/dnnl/dnnl_fc.cc | 1 + src/operator/subgraph/dnnl/dnnl_post_quantize_property.h | 2 +- src/operator/subgraph/dnnl/dnnl_transformer.cc | 2 ++ .../subgraph/dnnl/dnnl_transformer_post_quantize_property.h | 6 ++++-- 8 files changed, 16 insertions(+), 4 deletions(-) diff --git a/python/mxnet/amp/lists/symbol_bf16.py b/python/mxnet/amp/lists/symbol_bf16.py index 86f5b0aabe72..a727bf5d0ff5 100644 --- a/python/mxnet/amp/lists/symbol_bf16.py +++ b/python/mxnet/amp/lists/symbol_bf16.py @@ -362,6 +362,8 @@ 'zeros_like', '_sg_onednn_conv', '_sg_onednn_fully_connected', + '_sg_mkldnn_conv', + '_sg_mkldnn_fully_connected', 'broadcast_mul', 'Convolution_v1', 'IdentityAttachKLSparseReg', diff --git a/python/mxnet/amp/lists/symbol_fp16.py b/python/mxnet/amp/lists/symbol_fp16.py index b561b335d9a7..f5084c601eee 100644 --- a/python/mxnet/amp/lists/symbol_fp16.py +++ b/python/mxnet/amp/lists/symbol_fp16.py @@ -615,6 +615,10 @@ '_sg_onednn_fully_connected', '_sg_onednn_selfatt_qk', '_sg_onednn_selfatt_valatt', + '_sg_mkldnn_conv', + '_sg_mkldnn_fully_connected', + '_sg_mkldnn_selfatt_qk', + '_sg_mkldnn_selfatt_valatt', ]) # Functions that have to be cast to FP32 only for diff --git a/src/operator/quantization/quantize_graph_pass.cc b/src/operator/quantization/quantize_graph_pass.cc index 3835f1a3a9c9..877c038ba213 100644 --- a/src/operator/quantization/quantize_graph_pass.cc +++ b/src/operator/quantization/quantize_graph_pass.cc @@ -187,7 +187,7 @@ inline QuantizeType NeedQuantize(ObjectPtr node, need = false; if (need) { if ((quantize_granularity == "channel-wise") && - (node->op() == Op::Get("_sg_onednn_fully_connected"))) { + (node->op() == Op::Get("_sg_onednn_fully_connected") || node->op() == Op::Get("_sg_mkldnn_fully_connected"))) { quantized_node->attrs.dict["channel_wise_quantize"] = "True"; } quantized_node_map->insert(std::make_pair(node, quantized_node)); diff --git a/src/operator/subgraph/dnnl/dnnl_conv.cc b/src/operator/subgraph/dnnl/dnnl_conv.cc index 8702430d45b0..f85ece31e450 100644 --- a/src/operator/subgraph/dnnl/dnnl_conv.cc +++ b/src/operator/subgraph/dnnl/dnnl_conv.cc @@ -731,6 +731,7 @@ bool SgDNNLAvoidConvQuantizeInput(const NodeAttrs& attrs, } NNVM_REGISTER_OP(_sg_onednn_conv) + .add_alias("_sg_mkldnn_conv") .describe(R"code(_sg_onednn_conv)code" ADD_FILELINE) .set_num_inputs(SgDNNLConvNumInputs) .set_num_outputs([](const NodeAttrs& attrs) { diff --git a/src/operator/subgraph/dnnl/dnnl_fc.cc b/src/operator/subgraph/dnnl/dnnl_fc.cc index 24910e71b9d4..c07b8f7b8835 100644 --- a/src/operator/subgraph/dnnl/dnnl_fc.cc +++ b/src/operator/subgraph/dnnl/dnnl_fc.cc @@ -652,6 +652,7 @@ static bool SgDNNLAvoidFCQuantizeInput(const NodeAttrs& attrs, } NNVM_REGISTER_OP(_sg_onednn_fully_connected) + .add_alias("_sg_mkldnn_fully_connected") .describe(R"code(_sg_onednn_fully_connected)code" ADD_FILELINE) .set_num_inputs([](const NodeAttrs& attrs) { auto const& full_param = nnvm::get(attrs.parsed); diff --git a/src/operator/subgraph/dnnl/dnnl_post_quantize_property.h b/src/operator/subgraph/dnnl/dnnl_post_quantize_property.h index 6da43869afd9..594b767bdafe 100644 --- a/src/operator/subgraph/dnnl/dnnl_post_quantize_property.h +++ b/src/operator/subgraph/dnnl/dnnl_post_quantize_property.h @@ -56,7 +56,7 @@ class SgDNNLPostQuantizeSelector : public SubgraphSelector { bool Select(const nnvm::Node& n) override { if (n.op() && support_requantize_fusion_op_name.count(n.op()->name)) { - if (n.op()->name == "_sg_onednn_conv") { + if (n.op()->name == "_sg_onednn_conv" || n.op()->name == "_sg_mkldnn_conv") { auto const& param = nnvm::get(n.attrs.parsed); if (param.full_conv_param.dnnl_param.quantized) { status = kStart; diff --git a/src/operator/subgraph/dnnl/dnnl_transformer.cc b/src/operator/subgraph/dnnl/dnnl_transformer.cc index 965aff4df301..e71761a4bd51 100644 --- a/src/operator/subgraph/dnnl/dnnl_transformer.cc +++ b/src/operator/subgraph/dnnl/dnnl_transformer.cc @@ -306,6 +306,7 @@ nnvm::ObjectPtr SgDNNLSelfAttQKQuantizedOp(const NodeAttrs& attrs) { } NNVM_REGISTER_OP(_sg_onednn_selfatt_qk) + .add_alias("_sg_mkldnn_selfatt_qk") .describe(R"code(_sg_onednn_selfatt_qk)code" ADD_FILELINE) .set_num_inputs([](const NodeAttrs& attrs) { auto const& param = nnvm::get(attrs.parsed); @@ -700,6 +701,7 @@ void DNNLSelfAttValAttOp::Forward(const OpContext& ctx, } NNVM_REGISTER_OP(_sg_onednn_selfatt_valatt) + .add_alias("_sg_mkldnn_selfatt_valatt") .describe(R"code(_sg_onednn_selfatt_valatt)code" ADD_FILELINE) .set_num_inputs([](const NodeAttrs& attrs) { auto const& param = nnvm::get(attrs.parsed); diff --git a/src/operator/subgraph/dnnl/dnnl_transformer_post_quantize_property.h b/src/operator/subgraph/dnnl/dnnl_transformer_post_quantize_property.h index 7528de54083d..f1c2f6c3c9e4 100644 --- a/src/operator/subgraph/dnnl/dnnl_transformer_post_quantize_property.h +++ b/src/operator/subgraph/dnnl/dnnl_transformer_post_quantize_property.h @@ -53,7 +53,8 @@ class SgDNNLTransformerPostQuantizeSelector : public SubgraphSelector { bool Select(const nnvm::Node& n) override { if ((!disable_all) && (n.op() == Op::Get("_sg_onednn_selfatt_qk") || - n.op() == Op::Get("_sg_onednn_selfatt_valatt"))) { + n.op() == Op::Get("_sg_onednn_selfatt_valatt") || n.op() == Op::Get("_sg_mkldnn_selfatt_qk") || + n.op() == Op::Get("_sg_mkldnn_selfatt_valatt"))) { status = disable_all ? kSuccess : kStart; matched_list.clear(); matched_list.push_back(&n); @@ -152,7 +153,8 @@ class SgDNNLTransformerPostQuantizeProperty : public SubgraphProperty { if (node->is_variable()) return; if (node->op() == Op::Get("_sg_onednn_selfatt_qk") || - node->op() == Op::Get("_sg_onednn_selfatt_valatt")) { + node->op() == Op::Get("_sg_onednn_selfatt_valatt") || node->op() == Op::Get("_sg_mkldnn_selfatt_qk") || + node->op() == Op::Get("_sg_mkldnn_selfatt_valatt")) { interleaved_node = node; } else if (node->op() == Op::Get("_contrib_requantize")) { requantize_node = node; From e8093402d876d3ce233ccd084cbfa47d11c84237 Mon Sep 17 00:00:00 2001 From: Bartosz Kuncer Date: Tue, 19 Oct 2021 13:56:13 +0200 Subject: [PATCH 2/5] Apply clang format --- src/operator/quantization/quantize_graph_pass.cc | 3 ++- .../dnnl/dnnl_transformer_post_quantize_property.h | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/operator/quantization/quantize_graph_pass.cc b/src/operator/quantization/quantize_graph_pass.cc index 877c038ba213..37f154258894 100644 --- a/src/operator/quantization/quantize_graph_pass.cc +++ b/src/operator/quantization/quantize_graph_pass.cc @@ -187,7 +187,8 @@ inline QuantizeType NeedQuantize(ObjectPtr node, need = false; if (need) { if ((quantize_granularity == "channel-wise") && - (node->op() == Op::Get("_sg_onednn_fully_connected") || node->op() == Op::Get("_sg_mkldnn_fully_connected"))) { + (node->op() == Op::Get("_sg_onednn_fully_connected") || + node->op() == Op::Get("_sg_mkldnn_fully_connected"))) { quantized_node->attrs.dict["channel_wise_quantize"] = "True"; } quantized_node_map->insert(std::make_pair(node, quantized_node)); diff --git a/src/operator/subgraph/dnnl/dnnl_transformer_post_quantize_property.h b/src/operator/subgraph/dnnl/dnnl_transformer_post_quantize_property.h index f1c2f6c3c9e4..e86d5604d6bf 100644 --- a/src/operator/subgraph/dnnl/dnnl_transformer_post_quantize_property.h +++ b/src/operator/subgraph/dnnl/dnnl_transformer_post_quantize_property.h @@ -53,7 +53,8 @@ class SgDNNLTransformerPostQuantizeSelector : public SubgraphSelector { bool Select(const nnvm::Node& n) override { if ((!disable_all) && (n.op() == Op::Get("_sg_onednn_selfatt_qk") || - n.op() == Op::Get("_sg_onednn_selfatt_valatt") || n.op() == Op::Get("_sg_mkldnn_selfatt_qk") || + n.op() == Op::Get("_sg_onednn_selfatt_valatt") || + n.op() == Op::Get("_sg_mkldnn_selfatt_qk") || n.op() == Op::Get("_sg_mkldnn_selfatt_valatt"))) { status = disable_all ? kSuccess : kStart; matched_list.clear(); @@ -153,8 +154,9 @@ class SgDNNLTransformerPostQuantizeProperty : public SubgraphProperty { if (node->is_variable()) return; if (node->op() == Op::Get("_sg_onednn_selfatt_qk") || - node->op() == Op::Get("_sg_onednn_selfatt_valatt") || node->op() == Op::Get("_sg_mkldnn_selfatt_qk") || - node->op() == Op::Get("_sg_mkldnn_selfatt_valatt")) { + node->op() == Op::Get("_sg_onednn_selfatt_valatt") || + node->op() == Op::Get("_sg_mkldnn_selfatt_qk") || + node->op() == Op::Get("_sg_mkldnn_selfatt_valatt")) { interleaved_node = node; } else if (node->op() == Op::Get("_contrib_requantize")) { requantize_node = node; From a3625513919a716468750e4c8cb5acb346ebae07 Mon Sep 17 00:00:00 2001 From: Bartosz Kuncer Date: Tue, 19 Oct 2021 14:17:35 +0200 Subject: [PATCH 3/5] Remove unnecessary _sg_mkldnn_* --- python/mxnet/amp/lists/symbol_bf16.py | 2 -- python/mxnet/amp/lists/symbol_fp16.py | 4 ---- src/operator/quantization/quantize_graph_pass.cc | 3 +-- src/operator/subgraph/dnnl/dnnl_post_quantize_property.h | 2 +- .../dnnl/dnnl_transformer_post_quantize_property.h | 8 ++------ 5 files changed, 4 insertions(+), 15 deletions(-) diff --git a/python/mxnet/amp/lists/symbol_bf16.py b/python/mxnet/amp/lists/symbol_bf16.py index a727bf5d0ff5..86f5b0aabe72 100644 --- a/python/mxnet/amp/lists/symbol_bf16.py +++ b/python/mxnet/amp/lists/symbol_bf16.py @@ -362,8 +362,6 @@ 'zeros_like', '_sg_onednn_conv', '_sg_onednn_fully_connected', - '_sg_mkldnn_conv', - '_sg_mkldnn_fully_connected', 'broadcast_mul', 'Convolution_v1', 'IdentityAttachKLSparseReg', diff --git a/python/mxnet/amp/lists/symbol_fp16.py b/python/mxnet/amp/lists/symbol_fp16.py index f5084c601eee..b561b335d9a7 100644 --- a/python/mxnet/amp/lists/symbol_fp16.py +++ b/python/mxnet/amp/lists/symbol_fp16.py @@ -615,10 +615,6 @@ '_sg_onednn_fully_connected', '_sg_onednn_selfatt_qk', '_sg_onednn_selfatt_valatt', - '_sg_mkldnn_conv', - '_sg_mkldnn_fully_connected', - '_sg_mkldnn_selfatt_qk', - '_sg_mkldnn_selfatt_valatt', ]) # Functions that have to be cast to FP32 only for diff --git a/src/operator/quantization/quantize_graph_pass.cc b/src/operator/quantization/quantize_graph_pass.cc index 37f154258894..3835f1a3a9c9 100644 --- a/src/operator/quantization/quantize_graph_pass.cc +++ b/src/operator/quantization/quantize_graph_pass.cc @@ -187,8 +187,7 @@ inline QuantizeType NeedQuantize(ObjectPtr node, need = false; if (need) { if ((quantize_granularity == "channel-wise") && - (node->op() == Op::Get("_sg_onednn_fully_connected") || - node->op() == Op::Get("_sg_mkldnn_fully_connected"))) { + (node->op() == Op::Get("_sg_onednn_fully_connected"))) { quantized_node->attrs.dict["channel_wise_quantize"] = "True"; } quantized_node_map->insert(std::make_pair(node, quantized_node)); diff --git a/src/operator/subgraph/dnnl/dnnl_post_quantize_property.h b/src/operator/subgraph/dnnl/dnnl_post_quantize_property.h index 594b767bdafe..6da43869afd9 100644 --- a/src/operator/subgraph/dnnl/dnnl_post_quantize_property.h +++ b/src/operator/subgraph/dnnl/dnnl_post_quantize_property.h @@ -56,7 +56,7 @@ class SgDNNLPostQuantizeSelector : public SubgraphSelector { bool Select(const nnvm::Node& n) override { if (n.op() && support_requantize_fusion_op_name.count(n.op()->name)) { - if (n.op()->name == "_sg_onednn_conv" || n.op()->name == "_sg_mkldnn_conv") { + if (n.op()->name == "_sg_onednn_conv") { auto const& param = nnvm::get(n.attrs.parsed); if (param.full_conv_param.dnnl_param.quantized) { status = kStart; diff --git a/src/operator/subgraph/dnnl/dnnl_transformer_post_quantize_property.h b/src/operator/subgraph/dnnl/dnnl_transformer_post_quantize_property.h index e86d5604d6bf..7528de54083d 100644 --- a/src/operator/subgraph/dnnl/dnnl_transformer_post_quantize_property.h +++ b/src/operator/subgraph/dnnl/dnnl_transformer_post_quantize_property.h @@ -53,9 +53,7 @@ class SgDNNLTransformerPostQuantizeSelector : public SubgraphSelector { bool Select(const nnvm::Node& n) override { if ((!disable_all) && (n.op() == Op::Get("_sg_onednn_selfatt_qk") || - n.op() == Op::Get("_sg_onednn_selfatt_valatt") || - n.op() == Op::Get("_sg_mkldnn_selfatt_qk") || - n.op() == Op::Get("_sg_mkldnn_selfatt_valatt"))) { + n.op() == Op::Get("_sg_onednn_selfatt_valatt"))) { status = disable_all ? kSuccess : kStart; matched_list.clear(); matched_list.push_back(&n); @@ -154,9 +152,7 @@ class SgDNNLTransformerPostQuantizeProperty : public SubgraphProperty { if (node->is_variable()) return; if (node->op() == Op::Get("_sg_onednn_selfatt_qk") || - node->op() == Op::Get("_sg_onednn_selfatt_valatt") || - node->op() == Op::Get("_sg_mkldnn_selfatt_qk") || - node->op() == Op::Get("_sg_mkldnn_selfatt_valatt")) { + node->op() == Op::Get("_sg_onednn_selfatt_valatt")) { interleaved_node = node; } else if (node->op() == Op::Get("_contrib_requantize")) { requantize_node = node; From 3d3cc0eb9b7c7cbe6ed4883b65f4afa166804b73 Mon Sep 17 00:00:00 2001 From: Bartosz Kuncer Date: Tue, 19 Oct 2021 16:17:03 +0200 Subject: [PATCH 4/5] Fix review --- src/operator/subgraph/dnnl/dnnl_post_quantize_property.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/operator/subgraph/dnnl/dnnl_post_quantize_property.h b/src/operator/subgraph/dnnl/dnnl_post_quantize_property.h index 6da43869afd9..594b767bdafe 100644 --- a/src/operator/subgraph/dnnl/dnnl_post_quantize_property.h +++ b/src/operator/subgraph/dnnl/dnnl_post_quantize_property.h @@ -56,7 +56,7 @@ class SgDNNLPostQuantizeSelector : public SubgraphSelector { bool Select(const nnvm::Node& n) override { if (n.op() && support_requantize_fusion_op_name.count(n.op()->name)) { - if (n.op()->name == "_sg_onednn_conv") { + if (n.op()->name == "_sg_onednn_conv" || n.op()->name == "_sg_mkldnn_conv") { auto const& param = nnvm::get(n.attrs.parsed); if (param.full_conv_param.dnnl_param.quantized) { status = kStart; From 9a1a8184330d42f50559d956e54f1d0b72c89603 Mon Sep 17 00:00:00 2001 From: Bartosz Kuncer Date: Tue, 19 Oct 2021 21:26:17 +0200 Subject: [PATCH 5/5] Simplify comparison --- src/operator/subgraph/dnnl/dnnl_post_quantize_property.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/operator/subgraph/dnnl/dnnl_post_quantize_property.h b/src/operator/subgraph/dnnl/dnnl_post_quantize_property.h index 594b767bdafe..662b792d737d 100644 --- a/src/operator/subgraph/dnnl/dnnl_post_quantize_property.h +++ b/src/operator/subgraph/dnnl/dnnl_post_quantize_property.h @@ -56,7 +56,7 @@ class SgDNNLPostQuantizeSelector : public SubgraphSelector { bool Select(const nnvm::Node& n) override { if (n.op() && support_requantize_fusion_op_name.count(n.op()->name)) { - if (n.op()->name == "_sg_onednn_conv" || n.op()->name == "_sg_mkldnn_conv") { + if (n.op() == Op::Get("_sg_onednn_conv")) { auto const& param = nnvm::get(n.attrs.parsed); if (param.full_conv_param.dnnl_param.quantized) { status = kStart;