piiswrong commented on a change in pull request #7356: decouple record/train 
and add state readers
URL: https://github.com/apache/incubator-mxnet/pull/7356#discussion_r131578941

 File path: python/mxnet/autograd.py
 @@ -54,26 +76,28 @@ class RecordingStateScope(object):
             y = model(x)
-    def __init__(self, enter_state, is_train):
-        self._enter_state = enter_state
+    def __init__(self, is_record, is_train):
+        self._enter_is_record = is_record
         self._enter_is_train = is_train
-        self._prev = None
+        self._prev_is_record = None
         self._prev_is_train = None
     def __enter__(self):
-        self._prev = set_recording(self._enter_state)
-        self._prev_is_train = set_training(self._enter_is_train)
+        if self._enter_is_record is not None:
+            self._prev_is_record = set_recording(self._enter_is_record)
+        if self._enter_is_train is not None:
+            self._prev_is_train = set_training(self._enter_is_train)
     def __exit__(self, ptype, value, trace):
-        if self._prev != self._enter_state:
-            set_recording(self._prev)
-        if self._prev_is_train != self._enter_is_train:
+        if self._enter_is_record is not None and self._prev_is_record != 
+            set_recording(self._prev_is_record)
+        if self._enter_is_train is not None and self._prev_is_train != 
 def record(is_train=True):
-    """Returns a training scope context to be used in 'with' statement
-    and captures training code.
+    """Returns an autograd recording scope context to be used in 'with' 
+    and captures codes that need gradients to be calculated.
 Review comment:
   code is not countable
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:

With regards,
Apache Git Services

Reply via email to