samskalicky commented on a change in pull request #15886: Graph Partition API
URL: https://github.com/apache/incubator-mxnet/pull/15886#discussion_r317704207
 
 

 ##########
 File path: src/c_api/c_api_symbolic.cc
 ##########
 @@ -1199,3 +1200,73 @@ int MXShallowCopySymbol(SymbolHandle src, SymbolHandle* 
out) {
   *out = out_sym;
   API_END_HANDLE_ERROR(delete out_sym);
 }
+
+int MXOptimizeForBackend(SymbolHandle sym_handle,
+                         const char* backend_name,
+                         SymbolHandle* ret_sym_handle,
+                         const mx_uint len,
+                         NDArrayHandle* in_args_handle,
+                         const mx_uint num_options,
+                         const char** keys,
+                         const char** vals) {
+  nnvm::Symbol *s = new nnvm::Symbol();
+  API_BEGIN();
+  nnvm::Symbol *sym = static_cast<nnvm::Symbol *>(sym_handle);
+  *s = sym->Copy();
+  nnvm::Graph g = Symbol2Graph(*s);
+  if (len) {
+    NDArray **in_args_ptr = reinterpret_cast<NDArray**>(in_args_handle);
+    Context default_ctx = in_args_ptr[0]->ctx();
+    mxnet::ShapeVector arg_shapes(len);
+    nnvm::DTypeVector arg_dtypes(len);
+    StorageTypeVector arg_stypes(len);
+    for (mx_uint i = 0; i < len; i++) {
+      const auto &in_arg = *(in_args_ptr[i]);
+      arg_shapes[i] = in_arg.shape();
+      arg_dtypes[i] = in_arg.dtype();
+      arg_stypes[i] = in_arg.storage_type();
+      CHECK(in_arg.ctx() == default_ctx)
+          << "args[" << i << "] is on context: " << in_arg.ctx()
+          << ", whereas args[0] is on context: " << default_ctx
+          << ". All args must be on the same context.";
+    }
+    const auto& indexed_graph = g.indexed_graph();
+    const auto num_forward_inputs = indexed_graph.input_nodes().size();
+    g.attrs["context"] = std::make_shared<nnvm::any>(
+        exec::ContextVector(indexed_graph.num_nodes(), default_ctx));
+    // infer shapes
+    g = exec::InferShape(std::move(g), std::move(arg_shapes), "__shape__");
+    if (g.GetAttr<size_t>("shape_num_unknown_nodes") != 0U) {
 
 Review comment:
   Partial infer shape would not be useful here. The user has 2 choices: either 
pass args and infer shape/type before partitioning, or do not pass the args and 
just partition without shapes/types.
   
   For some backends, shapes/types will be required info to determine if an op 
can be supported. So partial infer is not helpful here. 

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to