reminisce commented on a change in pull request #14113: Enhance subgraph API
URL: https://github.com/apache/incubator-mxnet/pull/14113#discussion_r269839151
 
 

 ##########
 File path: 
src/operator/subgraph/mkldnn/mkldnn_post_quantize_align_scale_property.h
 ##########
 @@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#ifndef 
MXNET_OPERATOR_SUBGRAPH_MKLDNN_MKLDNN_POST_QUANTIZE_ALIGN_SCALE_PROPERTY_H_
+#define 
MXNET_OPERATOR_SUBGRAPH_MKLDNN_MKLDNN_POST_QUANTIZE_ALIGN_SCALE_PROPERTY_H_
+#if MXNET_USE_MKLDNN == 1
+
+#include <string>
+#include <vector>
+#include "../common.h"
+#include "../subgraph_property.h"
+
+namespace mxnet {
+namespace op {
+
+class SgMKLDNNConcatPostQuantizeSelector : public SubgraphSelectorV2 {
+ public:
+  bool Select(const BiDirectionalNode &sn) override {
+    const auto &n = *sn.node;
+    if (n.op() == Op::Get("_contrib_quantized_concat")) {
+      matched_list_.clear();
+      visit_list_.clear();
+      visit_list_.insert(&n);
+      select_output_ = (sn.outputs.size() > 1) ? false : true;
+      return true;
+    }
+    return false;
+  }
+
+  bool SelectInput(const BiDirectionalNode &sn, const BiDirectionalNode 
&snew_node) override {
+    const auto &n = *sn.node;
+    const auto &new_node = *snew_node.node;
+    if (new_node.is_variable()) return false;
+    if (visit_list_.count(&n) == 0) return false;
+    bool multiple_outputs = false;
+    for (auto i : snew_node.outputs) {
+      if (visit_list_.count(i.first) == 0) {
+        multiple_outputs = true;
+        break;
+      }
+    }
+    if (multiple_outputs) return false;
+    if (new_node.attrs.dict.count("min_calib_range") != 0 &&
+        new_node.attrs.dict.count("max_calib_range") != 0) {
+      matched_list_.push_back(&snew_node);
+      return true;
+    } else if (new_node.op() == Op::Get("_contrib_quantized_concat") ||
+               new_node.op() == Op::Get("_contrib_quantized_pooling")) {
+      visit_list_.insert(&new_node);
+      return true;
+    }
+    return false;
+  }
+
+  bool SelectOutput(const BiDirectionalNode &sn, const BiDirectionalNode 
&snew_node) override {
+    if (!select_output_) return false;
+    const auto &n = *sn.node;
+    const auto &new_node = *snew_node.node;
+    if (new_node.is_variable()) return false;
+    if (visit_list_.count(&n) == 0) {
+      return false;
+    }
+    if (new_node.op() == Op::Get("_contrib_quantized_concat") ||
+        new_node.op() == Op::Get("_contrib_quantized_pooling")) {
+      visit_list_.insert(&new_node);
+      return true;
+    }
+    return false;
+  }
+
+  virtual std::vector<BiDirectionalNode *> Filter(
+      const std::vector<BiDirectionalNode *> &candidates) {
+    if (matched_list_.size() < 2) {
+      return std::vector<BiDirectionalNode *>(0);
+    } else {
+      std::vector<BiDirectionalNode *> ret;
+      for (auto i : matched_list_) {
+        ret.push_back(const_cast<BiDirectionalNode *>(i));
+      }
+      return ret;
+    }
+  }
+
+ private:
+  bool select_output_;
+  std::vector<const BiDirectionalNode *> matched_list_;
+  std::unordered_set<const nnvm::Node*> visit_list_;
+};
+
+class SgMKLDNNPostQuantizeAlignScaleProperty : public SubgraphProperty {
+ public:
+  SgMKLDNNPostQuantizeAlignScaleProperty() : SubgraphProperty(kAdjust) {}
+
+  static SubgraphPropertyPtr Create() {
+    static const std::string &name = "MKLDNN post-quantization scale alignment 
optimization pass";
+    auto property = std::make_shared<SgMKLDNNPostQuantizeAlignScaleProperty>();
+    property->SetAttr<std::string>("property_name", name);
+    property->SetAttr<bool>("inference_only", true);
+    return property;
+  }
+
+  void AdjustSubgraphNode(const std::vector<nnvm::Node *> &subgraph_nodes,
 
 Review comment:
   Please add docstring for this function.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to