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/10 07:10:38 UTC

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

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

 ##########
 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:
   unnecessary new lines.
   
   Also in line 158-159, would it make sense to use `*p_save_inputs` directly instead of creating another `save_inputs` variable like how you have done in `RecordOp` 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:
users@infra.apache.org


With regards,
Apache Git Services