Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

[DEBUG] enable custom error type #17128

Merged
merged 5 commits into from
Dec 31, 2019
Merged

[DEBUG] enable custom error type #17128

merged 5 commits into from
Dec 31, 2019

Conversation

szha
Copy link
Member

@szha szha commented Dec 19, 2019

Description

enable throwing custom error type from backend

With this patch, by prepending error messages with the error type, the frontend will automatically throw exception of that type if the type has been registered.

An example in a check in transpose and its effect

Logging in C++

    CHECK_EQ(axes_set.size(), axes.ndim()) << "ValueError: Repeated axis in transpose."
                                           << " param.axes = "
                                           << param.axes;

Effect

In [1]: from mxnet import np

In [2]: dat = np.random.normal(0, 1, (3, 4, 5))

In [3]: dat.transpose((0, 0, 1))
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-3-3ad259b4e371> in <module>
----> 1 dat.transpose((0, 0, 1))

~/mxnet-distro/mxnet-build/python/mxnet/numpy/multiarray.py in transpose(self, *axes)
   1460             elif axes[0] is None:
   1461                 axes = None
-> 1462         return _mx_np_op.transpose(self, axes=axes)
   1463
   1464     def flip(self, *args, **kwargs):

~/mxnet-distro/mxnet-build/python/mxnet/ndarray/register.py in transpose(a, axes, out, name, **kwargs)

~/mxnet-distro/mxnet-build/python/mxnet/_ctypes/ndarray.py in _imperative_invoke(handle, ndargs, keys, vals, out, is_np_op, output_is_list)
    105         c_str_array(keys),
    106         c_str_array([str(s) for s in vals]),
--> 107         ctypes.byref(out_stypes)))
    108
    109     create_ndarray_fn = _np_ndarray_cls if is_np_op else _ndarray_cls

~/mxnet-distro/mxnet-build/python/mxnet/base.py in check_call(ret)
    271     """
    272     if ret != 0:
--> 273         raise get_last_ffi_error()
    274
    275

ValueError: Traceback (most recent call last):
  File "src/operator/numpy/np_matrix_op.cc", line 77
ValueError: Check failed: axes_set.size() == axes.ndim() (2 vs. 3) : Repeated axis in transpose. param.axes = [0,0,1]

Checklist

Essentials

Please feel free to remove inapplicable items for your PR.

  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage:
  • Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
  • Code is well-documented:
  • For new C++ functions in header files, their functionalities and arguments are documented.
  • To the best of my knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Changes

  • Auto-detection for exception type in error message

Comments

  • If this change is a backward incompatible change, why must this change be made.
  • Interesting edge cases to note here

@eric-haibin-lin
Copy link
Member

Is the plan to apply this convention to all numpy ops?

@szha
Copy link
Member Author

szha commented Dec 20, 2019

@eric-haibin-lin yes. It should also be feasible to throw numpy exception types directly to match the exact behavior in numpy. cc @haojin2 @reminisce

@sxjscience
Copy link
Member

Nice feature!!! Should we also add the reference of TVM?

@ZhennanQin
Copy link
Contributor

Nice feature! I'm thinking if we can extend this or do similar thing to LOG(INFO) in C code. Currently, mixed log style from C and python is a bit confused for users.

@szha szha merged commit c020f37 into apache:master Dec 31, 2019
@szha szha deleted the py_error branch December 31, 2019 08:59
apeforest added a commit to apeforest/incubator-mxnet that referenced this pull request Jan 16, 2020
apeforest added a commit to apeforest/incubator-mxnet that referenced this pull request Jan 16, 2020
apeforest added a commit to apeforest/incubator-mxnet that referenced this pull request Jan 19, 2020
apeforest added a commit to apeforest/incubator-mxnet that referenced this pull request Jan 19, 2020
apeforest added a commit to apeforest/incubator-mxnet that referenced this pull request Jan 20, 2020
szha added a commit that referenced this pull request Jan 22, 2020
* fix build error due to  #17128

* whitelist all *MX* API

* Update libmxnet.sym

* Update libmxnet.ver

Co-authored-by: Sheng Zha <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants