piiswrong closed pull request #10424: [MXNET-185] Improved error message URL: https://github.com/apache/incubator-mxnet/pull/10424
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 fd95641274d..64003585dba 100644 --- a/python/mxnet/gluon/block.py +++ b/python/mxnet/gluon/block.py @@ -458,7 +458,13 @@ def _build_cache(self, *args): for name in out.list_inputs()] def _finish_deferred_init(self, hybrid, *args): - self.infer_shape(*args) + try: + self.infer_shape(*args) + except Exception as e: + error_msg = "Deferred initialization failed because shape"\ + " cannot be inferred \n {}".format(e) + raise ValueError(error_msg) + if hybrid: for is_arg, i in self._cached_op_args: if not is_arg: @@ -509,11 +515,14 @@ 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)}) + with warnings.catch_warnings(record=True) as w: + 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)}) + zip(out.list_auxiliary_states(), aux_attrs)}) for i in self.collect_params().values(): setattr(i, attr, sdict[i.name]) ---------------------------------------------------------------- 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