sandeep-krishnamurthy 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_r214461812
 
 

 ##########
 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):
+                if arg not in input_names:
+                    self.params.get(arg, allow_deferred_init=True)
 
-        for i in out.list_auxiliary_states():
-            if i not in input_names:
-                self.params.get(i, grad_req='null', allow_deferred_init=True)
+            for i, aux in enumerate(aux_params):
 
 Review comment:
   N/A with latest refactoring. 

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