This is an automated email from the ASF dual-hosted git repository.
haoj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-mxnet.git
The following commit(s) were added to refs/heads/master by this push:
new f55fd06 Add warning message for fallback operators (#17697)
f55fd06 is described below
commit f55fd06aa1fe2650b53cc75190fce3d7f81999c0
Author: Hao Jin <[email protected]>
AuthorDate: Fri Feb 28 21:36:09 2020 -0800
Add warning message for fallback operators (#17697)
---
python/mxnet/numpy/multiarray.py | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/python/mxnet/numpy/multiarray.py b/python/mxnet/numpy/multiarray.py
index c7c0ec0..3354ce8 100644
--- a/python/mxnet/numpy/multiarray.py
+++ b/python/mxnet/numpy/multiarray.py
@@ -190,6 +190,8 @@ _set_np_ndarray_class(_np_ndarray_cls)
_NUMPY_ARRAY_FUNCTION_DICT = {}
_NUMPY_ARRAY_UFUNC_DICT = {}
+_FALLBACK_ARRAY_FUNCTION_WARNED_RECORD = {}
+_FALLBACK_ARRAY_UFUNC_WARNED_RECORD = {}
@set_module('mxnet.numpy') # pylint: disable=invalid-name
@@ -263,6 +265,11 @@ class ndarray(NDArray):
.format(name)
onp_op = _get_np_op(name)
new_inputs = [arg.asnumpy() if isinstance(arg, ndarray) else
arg for arg in inputs]
+ if onp_op not in _FALLBACK_ARRAY_UFUNC_WARNED_RECORD:
+ import logging
+ logging.warning("np.%s is a fallback operator, "
+ "which is actually using official numpy's
implementation", name)
+ _FALLBACK_ARRAY_UFUNC_WARNED_RECORD[onp_op] = True
out = onp_op(*new_inputs, **kwargs)
return _as_mx_np_array(out, ctx=inputs[0].ctx)
else:
@@ -277,6 +284,7 @@ class ndarray(NDArray):
this function.
"""
mx_np_func = _NUMPY_ARRAY_FUNCTION_DICT.get(func, None)
+ func_name = func.__name__
if mx_np_func is None:
# try to fallback to official NumPy op
if is_recording():
@@ -290,6 +298,11 @@ class ndarray(NDArray):
new_kwargs = {}
for k, v in kwargs.items():
new_kwargs[k] = v.asnumpy() if isinstance(v, ndarray) else v
+ if func not in _FALLBACK_ARRAY_FUNCTION_WARNED_RECORD:
+ import logging
+ logging.warning("np.%s is a fallback operator, "
+ "which is actually using official numpy's
implementation.", func_name)
+ _FALLBACK_ARRAY_FUNCTION_WARNED_RECORD[func] = True
out = func(*new_args, **new_kwargs)
return _as_mx_np_array(out, ctx=cur_ctx)
else: