leezu commented on a change in pull request #18413:
URL: https://github.com/apache/incubator-mxnet/pull/18413#discussion_r441043985



##########
File path: python/mxnet/gluon/block.py
##########
@@ -57,57 +57,39 @@ def __init__(self, block):
         self._local._name_scope = None
 
     @staticmethod
-    def create(prefix, params, hint):
+    def count(hint):
         """
-        Creates prefix, params, and profiler scope name for new `Block`.
+        Creates unique name for new `Block`.
         The profiler scope is to support the GPU memory profiler.
         """
         current = getattr(_BlockScope._current, "value", None)
-        block = current._block() if current is not None else None
-        if current is None or block is None:
-            if prefix is None:
-                if not hasattr(_name.NameManager._current, "value"):
-                    _name.NameManager._current.value = _name.NameManager()
-                prefix = _name.NameManager._current.value.get(None, hint) + '_'
-            # replace the trailing underscore with colon
-            profiler_scope_name = (prefix[:-1] if prefix.endswith('_') \
-                                   else prefix) + ":"
-            if params is None:
-                params = ParameterDict(prefix)
-            else:
-                params = ParameterDict(params.prefix, params)
-            return prefix, params, profiler_scope_name
+        if current is None:
+            if not hasattr(_name.NameManager._current, "value"):
+                _name.NameManager._current.value = _name.NameManager()
+            block_name = _name.NameManager._current.value.get(None, hint)
+            return block_name
 
-        if prefix is None:
-            count = current._counter.get(hint, 0)
-            prefix = '%s%d_'%(hint, count)
-            current._counter[hint] = count + 1
-        if params is None:
-            parent = block.params
-            params = ParameterDict(parent.prefix+prefix, parent._shared)
-        else:
-            params = ParameterDict(params.prefix, params)
-        # replace the trailing underscore with colon
-        profiler_scope_name = (prefix[:-1] if prefix.endswith('_') \
-                               else prefix) + ":"
-        return block.prefix + prefix, params, \
-               block._profiler_scope_name + profiler_scope_name
+        count = current._counter.get(hint, 0)
+        block_name = '%s%d'%(hint, count)
+        current._counter[hint] = count + 1
+        return block_name
 
     def __enter__(self):

Review comment:
       When removing the support for passing `symbol` to `HybridBlock`, we'll 
be able to delete the `with self.name_scope()` usage in the `get_graph` methods 
and then delete the `__enter__` and `__exit__` methods of the BlockScope. But 
that'll be for a later PR.

##########
File path: python/mxnet/gluon/block.py
##########
@@ -542,61 +460,60 @@ def load_parameters(self, filename, ctx=None, 
allow_missing=False,
                     raise ValueError(err_msg)
         else:
             loaded = ndarray.load(filename)
-        params = self._collect_params_with_prefix()
-        if not loaded and not params:
-            return
 
-        if not any('.' in i for i in loaded.keys()):
-            # legacy loading
-            loaded = None  # This should be changed to `del loaded` when 
dropping Python 2
-            self.collect_params().load(
-                filename, ctx, allow_missing, ignore_extra, self.prefix,
-                cast_dtype=cast_dtype, dtype_source=dtype_source)
+        if not loaded:
             return
+        self.load_dict(loaded, filename, ctx, allow_missing, ignore_extra, 
cast_dtype, dtype_source)
+
+    def load_dict(self, param_dict, filename=None, ctx=None, 
allow_missing=False,
+                  ignore_extra=False, cast_dtype=False, 
dtype_source="current"):
+        """Load parameters from dict
+
+        Parameters
+        ----------
+        param_dict : dict
+            Dictionary containing model parameters
+        filename : str, default None

Review comment:
       When making `load_dict` a public function (instead of internal), it 
shouldn't take a `filename` argument. The use of filename here is just due to 
how you implement `load_parameters`. 

##########
File path: python/mxnet/gluon/parameter.py
##########
@@ -431,7 +437,10 @@ def initialize(self, init=None, ctx=None, 
default_init=initializer.Uniform(),
             and :py:meth:`Parameter.init` are ``None``.
         force_reinit : bool, default False
             Whether to force re-initialization if parameter is already 
initialized.
-
+        structural_name : str, default ""
+            The structural name for the parameter in the block.
+            The value would be accessed in InitDesc.attrs['structure'] by 
self-defined initializers.
+            Users may want to initialize parameters based on the block's 
structure

Review comment:
       Unused?




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


Reply via email to