piiswrong commented on a change in pull request #10424: Improved error message
URL: https://github.com/apache/incubator-mxnet/pull/10424#discussion_r180834843
 
 

 ##########
 File path: python/mxnet/gluon/block.py
 ##########
 @@ -507,20 +513,22 @@ def cast(self, dtype):
 
     def _infer_attrs(self, infer_fn, attr, *args):
         """Generic infer attributes."""
-        inputs, out = self._get_graph(*args)
-        args, _ = _flatten(args)
-        arg_attrs, _, aux_attrs = getattr(out, infer_fn)(
-            **{i.name: getattr(j, attr) for i, j in zip(inputs, args)})
-        sdict = {i: j for i, j in zip(out.list_arguments(), arg_attrs)}
-        sdict.update({name : attr for name, attr in \
-                      zip(out.list_auxiliary_states(), aux_attrs)})
-        for i in self.collect_params().values():
-            setattr(i, attr, sdict[i.name])
+        with warnings.catch_warnings(record=True) as w:
+            inputs, out = self._get_graph(*args)
+            args, _ = _flatten(args)
+            arg_attrs, _, aux_attrs = getattr(out, infer_fn)(
+                **{i.name: getattr(j, attr) for i, j in zip(inputs, args)})
+            if arg_attrs is None:
+                raise ValueError(w[0].message)
+            sdict = {i: j for i, j in zip(out.list_arguments(), arg_attrs)}
+            sdict.update({name : attr for name, attr in \
+                 zip(out.list_auxiliary_states(), aux_attrs)})
+            for i in self.collect_params().values():
+                setattr(i, attr, sdict[i.name])
 
     def infer_shape(self, *args):
         """Infers shape of Parameters from inputs."""
         self._infer_attrs('infer_shape', 'shape', *args)
-
 
 Review comment:
   revert

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