[GitHub] [incubator-mxnet] mseth10 commented on a change in pull request #18690: [WIP] optimize graph in presence of dynamic shape ops

2020-07-26 Thread GitBox


mseth10 commented on a change in pull request #18690:
URL: https://github.com/apache/incubator-mxnet/pull/18690#discussion_r460591522



##
File path: src/operator/subgraph/build_subgraph.cc
##
@@ -360,6 +405,17 @@ void SelectSubgraphNodes(nnvm::Graph* g, 
SubgraphSelectorV2Ptr subgraph_selector
 // filter out unqualified pre-selected nodes
 std::vector filtered_nodes = 
subgraph_selector->Filter(preselected_nodes);
 
+const SubgraphPropertyPtr& subg_prop = 
g->GetAttr("subgraph_property");
+if (subg_prop->HasAttr("ensure_CachedOp_input")
+&& subg_prop->GetAttr("ensure_CachedOp_input")) {
+  // check if subgraph has external input.
+  // if not, reject the first op (in top order) from the subgraph
+  // to make sure CachedOp gets external input.
+  if (filtered_nodes.size() > 0 && !HasInputEntries(*g, simple_nodes, 
filtered_nodes)) {
+filtered_nodes.erase(filtered_nodes.begin());

Review comment:
   why are we calling `Filter` twice? Can we move `ensure_CachedOp_input` 
before the `Filter` call and check for Input Entries in 
`PreSelectSubgraphNodes`?





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




[GitHub] [incubator-mxnet] mseth10 commented on a change in pull request #18690: [WIP] optimize graph in presence of dynamic shape ops

2020-07-26 Thread GitBox


mseth10 commented on a change in pull request #18690:
URL: https://github.com/apache/incubator-mxnet/pull/18690#discussion_r460570318



##
File path: src/operator/subgraph/build_subgraph.cc
##
@@ -360,6 +405,17 @@ void SelectSubgraphNodes(nnvm::Graph* g, 
SubgraphSelectorV2Ptr subgraph_selector
 // filter out unqualified pre-selected nodes
 std::vector filtered_nodes = 
subgraph_selector->Filter(preselected_nodes);
 
+const SubgraphPropertyPtr& subg_prop = 
g->GetAttr("subgraph_property");
+if (subg_prop->HasAttr("ensure_CachedOp_input")
+&& subg_prop->GetAttr("ensure_CachedOp_input")) {
+  // check if subgraph has external input.
+  // if not, reject the first op (in top order) from the subgraph
+  // to make sure CachedOp gets external input.
+  if (filtered_nodes.size() > 0 && !HasInputEntries(*g, simple_nodes, 
filtered_nodes)) {
+filtered_nodes.erase(filtered_nodes.begin());

Review comment:
   Can you double check? We don’t run filter function after removing first 
node from subgraph. In the case when preselected nodes contain exactly two ops, 
filter function does not do anything, right? And then if one node gets removed, 
do we discard the resulting subgraph containing a single node? Can you show me 
how that works?





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




[GitHub] [incubator-mxnet] mseth10 commented on a change in pull request #18690: [WIP] optimize graph in presence of dynamic shape ops

2020-07-26 Thread GitBox


mseth10 commented on a change in pull request #18690:
URL: https://github.com/apache/incubator-mxnet/pull/18690#discussion_r460503949



##
File path: src/operator/subgraph/build_subgraph.cc
##
@@ -360,6 +405,17 @@ void SelectSubgraphNodes(nnvm::Graph* g, 
SubgraphSelectorV2Ptr subgraph_selector
 // filter out unqualified pre-selected nodes
 std::vector filtered_nodes = 
subgraph_selector->Filter(preselected_nodes);
 
+const SubgraphPropertyPtr& subg_prop = 
g->GetAttr("subgraph_property");
+if (subg_prop->HasAttr("ensure_CachedOp_input")
+&& subg_prop->GetAttr("ensure_CachedOp_input")) {
+  // check if subgraph has external input.
+  // if not, reject the first op (in top order) from the subgraph
+  // to make sure CachedOp gets external input.
+  if (filtered_nodes.size() > 0 && !HasInputEntries(*g, simple_nodes, 
filtered_nodes)) {
+filtered_nodes.erase(filtered_nodes.begin());

Review comment:
   @waytrue17 are we handling the case when this leads to `filtered_nodes` 
containing only one node? we should ideally reject such a subgraph.





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




[GitHub] [incubator-mxnet] mseth10 commented on a change in pull request #18690: [WIP] optimize graph in presence of dynamic shape ops

2020-07-23 Thread GitBox


mseth10 commented on a change in pull request #18690:
URL: https://github.com/apache/incubator-mxnet/pull/18690#discussion_r459798576



##
File path: src/operator/subgraph/static_shape_subgraph_property.cc
##
@@ -0,0 +1,80 @@
+/*
+ * 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.
+ */
+
+#include "./common.h"
+#include "./subgraph_property.h"
+#include "../../imperative/cached_op.h"
+
+namespace mxnet {
+namespace op {
+
+/*
+ * This selects nodes for a subgraph that only contains static shape operators
+ * and it visits nodes via both input and output links.
+ */
+class StaticShapeOpSelector: public SubgraphSelector {
+ public:
+  virtual bool Select(const nnvm::Node _node) {
+const auto& infershape = 
nnvm::Op::GetAttr("FInferShape");
+return !seed_node.is_variable() && infershape.count(seed_node.op());
+  }
+
+  virtual bool SelectInput(const nnvm::Node _node, const nnvm::Node 
_node) {
+const auto& infershape = 
nnvm::Op::GetAttr("FInferShape");
+return !input_node.is_variable() && infershape.count(input_node.op());
+  }
+
+  virtual bool SelectOutput(const nnvm::Node _node, const nnvm::Node 
_node) {
+const auto& infershape = 
nnvm::Op::GetAttr("FInferShape");
+return !output_node.is_variable() && infershape.count(output_node.op());
+  }

Review comment:
   right, there is no advantage of having a single node subgraph, we can 
reject such subgraphs in the subgraph property's `CreateSubgraphNode` 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




[GitHub] [incubator-mxnet] mseth10 commented on a change in pull request #18690: [WIP] optimize graph in presence of dynamic shape ops

2020-07-16 Thread GitBox


mseth10 commented on a change in pull request #18690:
URL: https://github.com/apache/incubator-mxnet/pull/18690#discussion_r455544340



##
File path: python/mxnet/symbol/symbol.py
##
@@ -2627,6 +2628,15 @@ def detach(self):
 def backward(self):
 raise NotImplementedForSymbol(self.backward, None)
 
+def optimize_for_dynamic_shape_op(self):
+"""Check if any dynamic shape op presents in the symbol, if yes, 
partition all static shape ops for optimization
+returns the optimized symbol.
+"""
+out = SymbolHandle()
+check_call(_LIB.MXOptimizeForDynamicShapeOp(self.handle, 
ctypes.byref(out)))
+from .numpy import _Symbol as np_symbol

Review comment:
   you can import it once on top of file





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




[GitHub] [incubator-mxnet] mseth10 commented on a change in pull request #18690: [WIP] optimize graph in presence of dynamic shape ops

2020-07-14 Thread GitBox


mseth10 commented on a change in pull request #18690:
URL: https://github.com/apache/incubator-mxnet/pull/18690#discussion_r454730389



##
File path: include/mxnet/c_api.h
##
@@ -3262,6 +3262,17 @@ MXNET_DLL int MXEnginePushSyncND(EngineSyncFunc 
sync_func, void* func_param,
  EngineFnPropertyHandle prop_handle 
DEFAULT(NULL),
  int priority DEFAULT(0), const char* opr_name 
DEFAULT(NULL));
 
+/*!
+ * \brief This function first check if any dynamic shape op presents in the 
symbol.
+ * \brief If yes, partition all static ops for execution optimization.
+ * \param sym_handle handler of the symbole.
+ * \param has_dynamic_shape status handler where true means dynamic shape op 
prestns and false otherwise.
+ * \param ret_sym_handle handler of result symbol
+ */
+MXNET_DLL int MXPartitionForStaticShapeOps(SymbolHandle sym_handle, 
+   bool* has_dynamic_shape, 

Review comment:
   remove this





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




[GitHub] [incubator-mxnet] mseth10 commented on a change in pull request #18690: [WIP] optimize graph in presence of dynamic shape ops

2020-07-14 Thread GitBox


mseth10 commented on a change in pull request #18690:
URL: https://github.com/apache/incubator-mxnet/pull/18690#discussion_r454728340



##
File path: python/mxnet/symbol/symbol.py
##
@@ -2513,6 +2513,18 @@ def detach(self):
 def backward(self):
 raise NotImplementedForSymbol(self.backward, None)
 
+def partition_for_static_shape_ops(self):
+"""Check if any dynamic shape ops present in the symbol, if yes, 
partition static shape ops for optimization
+returns the optimized symbol.
+"""
+out = SymbolHandle()
+has_dynamic_shape_ops = ctypes.c_bool(False)

Review comment:
   remove this variable





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