You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2019/07/18 08:10:37 UTC

[GitHub] [incubator-mxnet] marcoabreu commented on a change in pull request #14836: Refactor AGInfo and Imperative

marcoabreu commented on a change in pull request #14836: Refactor AGInfo and Imperative
URL: https://github.com/apache/incubator-mxnet/pull/14836#discussion_r304786785
 
 

 ##########
 File path: src/imperative/imperative.cc
 ##########
 @@ -124,29 +124,34 @@ void Imperative::MarkVariables(
     const std::vector<NDArray*>& variables,
     const std::vector<mx_uint>& grad_reqs,
     const std::vector<NDArray*>& gradients) {
-  for (uint32_t i = 0; i < variables.size(); ++i) {
+  for (size_t i = 0; i < variables.size(); ++i) {
     std::string str_c(std::to_string(variable_count_++));
-
-    variables[i]->entry_ = nnvm::NodeEntry{
-        nnvm::Symbol::CreateVariable("var" + str_c).outputs[0].node, 0, 0};
-    AGInfo& info = AGInfo::Create(variables[i]->entry_.node);
-    info.outputs.emplace_back(variables[i]->Detach());
-    info.out_grads.emplace_back(gradients[i]->Detach());
-    info.grad_req = static_cast<OpReqType>(grad_reqs[i]);
-    info.ctx = variables[i]->ctx();
-
-    gradients[i]->entry_ = nnvm::NodeEntry{
-        nnvm::Symbol::CreateVariable("grad" + str_c).outputs[0].node, 0, 0};
-    AGInfo& grad_info = AGInfo::Create(gradients[i]->entry_.node);
-    grad_info.outputs.emplace_back(gradients[i]->Detach());
-    grad_info.ctx = gradients[i]->ctx();
+    {
+      variables[i]->entry_ = nnvm::NodeEntry{
+          nnvm::Symbol::CreateVariable("var" + str_c).outputs[0].node, 0, 0};
+      AGInfo &info = AGInfo::Create(variables[i]->entry_.node);
+      info.outputs.emplace_back(variables[i]->Detach());
+      info.out_grads.emplace_back(gradients[i]->Detach());
+      info.grad_req = static_cast<OpReqType>(grad_reqs[i]);
+      info.ctx = variables[i]->ctx();
+    }
+    {
+      gradients[i]->entry_ = nnvm::NodeEntry{
+          nnvm::Symbol::CreateVariable("grad" + str_c).outputs[0].node, 0, 0};
+      AGInfo &grad_info = AGInfo::Create(gradients[i]->entry_.node);
+      grad_info.outputs.emplace_back(gradients[i]->Detach());
+      grad_info.ctx = gradients[i]->ctx();
+    }
   }
 }
 
 
+
+
+
 
 Review comment:
   This is a refactor already. I don't see any point for a subsequent PR if this PR is doing the actual refactor already. Please address the comments from @anirudhacharya and @apeforest .

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services