larroy commented on a change in pull request #14728: [MXNET-1386] fix for shape 
mismatch
URL: https://github.com/apache/incubator-mxnet/pull/14728#discussion_r297428082
 
 

 ##########
 File path: src/executor/graph_executor.cc
 ##########
 @@ -558,20 +558,31 @@ void GraphExecutor::InitArguments(const 
nnvm::IndexedGraph& idx,
                                   const std::unordered_set<std::string>& 
shared_arg_names,
                                   const Executor* shared_exec,
                                   std::unordered_map<std::string, NDArray>* 
shared_buffer,
+                                  std::vector<std::string>* in_names,
                                   std::vector<NDArray>* in_arg_vec,
                                   std::vector<NDArray>* arg_grad_vec,
                                   std::vector<NDArray>* aux_state_vec) {
+  // build name/index map for graph input nodes
+  std::map<std::string, uint32_t> inv_name_map;
+  for (size_t i = 0; i < num_forward_inputs_; ++i) {
+    const uint32_t nid = idx.input_nodes().at(i);
+    const std::string& arg_name = idx[nid].source->attrs.name;
+    inv_name_map[arg_name] = nid;
+  }
+
   // initialize in_args, arg_grads, and aux_states and populate grad_store_
   data_entry_.resize(idx.num_node_entries());
   size_t arg_top = 0, aux_top = 0;
   const auto& mutable_nodes = idx.mutable_input_nodes();
   for (size_t i = 0; i < num_forward_inputs_; ++i) {
-    const uint32_t nid = idx.input_nodes().at(i);
+    // get name from input names vector, and lookup new index of graph input 
node
+    const std::string& arg_name = in_names->at(i);
+    const uint32_t nid = inv_name_map[arg_name];
 
 Review comment:
   should you check that it exists? otherwise you could get a default 
constructed one (zero) IIRC. Not sure if this is possible, maybe assert.

----------------------------------------------------------------
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