You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by gi...@git.apache.org on 2017/08/18 19:05:45 UTC

[GitHub] piiswrong commented on a change in pull request #7494: gluon save/load optimizer states

piiswrong commented on a change in pull request #7494: gluon save/load optimizer states
URL: https://github.com/apache/incubator-mxnet/pull/7494#discussion_r134033688
 
 

 ##########
 File path: python/mxnet/gluon/trainer.py
 ##########
 @@ -158,3 +158,37 @@ def step(self, batch_size, ignore_stale_grad=False):
                 if not ignore_stale_grad or arr._fresh_grad:
                     upd(i, grad, arr)
                     arr._fresh_grad = False
+
+    def save_optimizer_states(self, fname):
+        """Saves optimizer (updater) state to a file.
+
+        Parameters
+        ----------
+        fname : str
+            Path to output states file.
+        """
+        assert self._optimizer is not None
+
+        if self._update_on_kvstore:
+            self._kvstore.save_optimizer_states(fname)
+        else:
+            with open(fname, 'wb') as fout:
+                fout.write(self._updaters[0].get_states())
 
 Review comment:
   This is wrong. Need to save all the states
 
----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services