anirudh2290 closed pull request #11210: [MXNET-532] Clarify documentation of 
save_parameters(), load_parameters()
URL: https://github.com/apache/incubator-mxnet/pull/11210
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/docs/tutorials/index.md b/docs/tutorials/index.md
index a970c0a52ef..e095a83419b 100644
--- a/docs/tutorials/index.md
+++ b/docs/tutorials/index.md
@@ -38,7 +38,7 @@ Select API: 
     * [Visual Question 
Answering](http://gluon.mxnet.io/chapter08_computer-vision/visual-question-answer.html)
 <img 
src="https://upload.wikimedia.org/wikipedia/commons/6/6a/External_link_font_awesome.svg";
 alt="External link" height="15px" style="margin: 0px 0px 3px 3px;"/>
 * Practitioner Guides
     * [Multi-GPU 
training](http://gluon.mxnet.io/chapter07_distributed-learning/multiple-gpus-gluon.html)
 <img 
src="https://upload.wikimedia.org/wikipedia/commons/6/6a/External_link_font_awesome.svg";
 alt="External link" height="15px" style="margin: 0px 0px 3px 3px;"/>
-    * [Checkpointing and Model Serialization (a.k.a. saving and 
loading)](http://gluon.mxnet.io/chapter03_deep-neural-networks/serialization.html)
 <img 
src="https://upload.wikimedia.org/wikipedia/commons/6/6a/External_link_font_awesome.svg";
 alt="External link" height="15px" style="margin: 0px 0px 3px 3px;"/> 
([Alternative](/tutorials/gluon/save_load_params.html))
+    * [Checkpointing and Model Serialization (a.k.a. saving and 
loading)](/tutorials/gluon/save_load_params.html) <img 
src="https://upload.wikimedia.org/wikipedia/commons/6/6a/External_link_font_awesome.svg";
 alt="External link" height="15px" style="margin: 0px 0px 3px 3px;"/> 
([Alternative](http://gluon.mxnet.io/chapter03_deep-neural-networks/serialization.html))
     * [Inference using an ONNX 
model](/tutorials/onnx/inference_on_onnx_model.html)
     * [Fine-tuning an ONNX model on 
Gluon](/tutorials/onnx/fine_tuning_gluon.html)
     * [Visualizing Decisions of Convolutional Neural 
Networks](/tutorials/vision/cnn_visualization.html)
diff --git a/python/mxnet/gluon/block.py b/python/mxnet/gluon/block.py
index 689b7abf14b..09de6fa4dc3 100644
--- a/python/mxnet/gluon/block.py
+++ b/python/mxnet/gluon/block.py
@@ -268,12 +268,12 @@ def collect_params(self, select=None):
         children's Parameters(default), also can returns the select 
:py:class:`ParameterDict`
         which match some given regular expressions.
 
-        For example, collect the specified parameter in ['conv1_weight', 
'conv1_bias', 'fc_weight',
+        For example, collect the specified parameters in ['conv1_weight', 
'conv1_bias', 'fc_weight',
         'fc_bias']::
 
             model.collect_params('conv1_weight|conv1_bias|fc_weight|fc_bias')
 
-        or collect all paramters which their name ends with 'weight' or 
'bias', this can be done
+        or collect all parameters whose names end with 'weight' or 'bias', 
this can be done
         using regular expressions::
 
             model.collect_params('.*weight|.*bias')
@@ -309,6 +309,18 @@ def _collect_params_with_prefix(self, prefix=''):
 
     def save_parameters(self, filename):
         """Save parameters to file.
+        This function is to be used to save parameters of a Gluon model, note 
that
+        the saved parameters are not meant to be loaded in a different 
language binding for now.
+        Saving parameters using `.save_parameters()` is different than
+        `.collect_params().save()` and `.save_params()`, which are deprecated 
ways
+        to save the parameters of a model and should be avoided.
+
+        If your model is hybridizable and you want to export a serialized 
version of the
+        structure of the model as well as its parameters please refer to
+        :py:meth:`HybridBlock.export`. Such model can then be loaded back in 
any language binding
+        or even in Gluon using a :py:class:`SymbolBlock`.
+        Refer to this tutorial for a complete overview of saving/loading 
models with
+        MXNet: 
https://mxnet.incubator.apache.org/tutorials/gluon/save_load_params.html
 
         filename : str
             Path to file.
@@ -335,11 +347,15 @@ def save_params(self, filename):
     def load_parameters(self, filename, ctx=None, allow_missing=False,
                         ignore_extra=False):
         """Load parameters from file.
+        This function is to be used to load parameters of a Gluon model that 
were
+        saved using the `.save_parameters()` function. Any other use is 
undefined behaviour.
+        Refer to this tutorial for a complete overview of saving/loading 
models with
+        MXNet: 
https://mxnet.incubator.apache.org/tutorials/gluon/save_load_params.html
 
         filename : str
             Path to parameter file.
         ctx : Context or list of Context, default cpu()
-            Context(s) initialize loaded parameters on.
+            Context(s) to initialize loaded parameters on.
         allow_missing : bool, default False
             Whether to silently skip loading parameters not represents in the 
file.
         ignore_extra : bool, default False
@@ -382,7 +398,7 @@ def load_params(self, filename, ctx=None, 
allow_missing=False,
         filename : str
             Path to parameter file.
         ctx : Context or list of Context, default cpu()
-            Context(s) initialize loaded parameters on.
+            Context(s) to initialize loaded parameters on.
         allow_missing : bool, default False
             Whether to silently skip loading parameters not represents in the 
file.
         ignore_extra : bool, default False


 

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to