You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2018/08/31 16:41:09 UTC

[GitHub] apeforest commented on a change in pull request #12412: Infer dtype in SymbolBlock import from input symbol

apeforest commented on a change in pull request #12412: Infer dtype in SymbolBlock import from input symbol
URL: https://github.com/apache/incubator-mxnet/pull/12412#discussion_r214409314
 
 

 ##########
 File path: python/mxnet/gluon/block.py
 ##########
 @@ -1053,13 +1053,34 @@ def __init__(self, outputs, inputs, params=None):
                     "SymbolBlock doesn't support Parameter '%s' because its storage " \
                     "type is 'row_sparse'." % j.name
 
-        for i in out.list_arguments():
-            if i not in input_names:
-                self.params.get(i, allow_deferred_init=True)
+        # Infer type of parameters. Without this, every parameter will be created with
+        # default type i.e., fp32
+        arg_params = out.list_arguments()
+        aux_params = out.list_auxiliary_states()
+
+        infer_type_success, arg_types, aux_types = _infer_param_types(inputs[0],
+                                                                      out,
+                                                                      arg_params,
+                                                                      aux_params)
+
+        if infer_type_success:
+            # Use inferred types for params
+            for i, arg in enumerate(arg_params):
+                if arg not in input_names:
+                    self.params.get(arg, allow_deferred_init=True, dtype=arg_types[i])
+
+            for i, aux in enumerate(aux_params):
+                if aux not in input_names:
+                    self.params.get(aux, grad_req='null', allow_deferred_init=True, dtype=aux_types[i])
+        else:
+            # Use default types for params
+            for i, arg in enumerate(arg_params):
 
 Review comment:
   Maybe no enumerate is needed since you don't use index i in this loop?

----------------------------------------------------------------
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