ariwaranosai closed pull request #10604: fix strip prefix in HybridBlock with 
parameter to control it.
URL: https://github.com/apache/incubator-mxnet/pull/10604
 
 
   

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/python/mxnet/gluon/block.py b/python/mxnet/gluon/block.py
index 0f415436116..8f18aa5eea2 100644
--- a/python/mxnet/gluon/block.py
+++ b/python/mxnet/gluon/block.py
@@ -578,7 +578,7 @@ def infer_type(self, *args):
         """Infers data type of Parameters from inputs."""
         self._infer_attrs('infer_type', 'dtype', *args)
 
-    def export(self, path, epoch=0):
+    def export(self, path, epoch=0, strip_prefix=False):
         """Export HybridBlock to json format that can be loaded by 
`mxnet.mod.Module`
         or the C++ interface.
 
@@ -592,6 +592,8 @@ def export(self, path, epoch=0):
             will be created, where xxxx is the 4 digits epoch number.
         epoch : int
             Epoch number of saved model.
+        strip_prefix: bool
+            Whether strip prefix or not
         """
         if not self._cached_graph:
             raise RuntimeError(
@@ -604,11 +606,13 @@ def export(self, path, epoch=0):
         aux_names = set(sym.list_auxiliary_states())
         arg_dict = {}
         for name, param in self.collect_params().items():
+            save_name = name[name.startswith(self.prefix)
+                             and len(self.prefix):] if strip_prefix else name
             if name in arg_names:
-                arg_dict['arg:%s'%name] = param._reduce()
+                arg_dict['arg:%s'%save_name] = param._reduce()
             else:
                 assert name in aux_names
-                arg_dict['aux:%s'%name] = param._reduce()
+                arg_dict['aux:%s'%save_name] = param._reduce()
         ndarray.save('%s-%04d.params'%(path, epoch), arg_dict)
 
     def forward(self, x, *args):


 

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


With regards,
Apache Git Services

Reply via email to