-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FRONTEND][Mxnet][nuymp] Adding _npi_advanced_indexing_multiple #7230
[FRONTEND][Mxnet][nuymp] Adding _npi_advanced_indexing_multiple #7230
Conversation
ref_res = mx.np.array(data_np)[row_sel, col] | ||
|
||
# TODO need to add the proper symbol operator | ||
mx_sym = mx.sym.np.(data.as_np_ndarray()[row_sel, col]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any idea what to use in mx.sym.np
for the advanced indexing
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may use this:
import mxnet as mx
mx.npx.set_np()
row_sel = mx.sym.var('row_sel').as_np_ndarray()
col = mx.sym.var('col').as_np_ndarray()
data = mx.sym.var('data').as_np_ndarray()
out = data[row_sel, col]
print(out)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @sxjscience
Thank you for the suggestion; however, I still not clear how to create mx_sym
so that I can use it for relay.frontend.from_mxnet
.
Any suggestion would appreciated.
Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to do the following?
row_sel_sym = mx.sym.var('row_sel').as_np_ndarray()
col_sym = mx.sym.var('col').as_np_ndarray()
data_sym = mx.sym.var('data').as_np_ndarray()
mx_sym = data_sym[row_sel_sym, col_sym]
Then, you may pass mx_sym
to the relay.frontend.from_mxnet
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @sxjscience
Thank you for the suggestion. I think I had tried that as well.
So with the following, I got this exception IndexError: Only integer, slice, or tuple of these types are supported! Received key=(<_Symbol row_sel>, <_Symbol col>)
from mxnet/symbol/numpy/_symbol.py:135:
(link)
I will dig more, but if you have any suggestion, please let me know.
def test_forward_npi_advanced_indexing_multiple(data_shape, row_sel, col, dtype, target, ctx, kind):
data_np = np.random.uniform(size=data_shape).astype(dtype)
ref_res = mx.np.array(data_np)[row_sel, col]
row_sel_sym = mx.sym.var("row_sel").as_np_ndarray()
data_sym = mx.sym.var("data").as_np_ndarray()
col_sym = mx.sym.var("col").as_np_ndarray()
mx_sym = data_sym[row_sel_sym, col_sym]
mod, _ = relay.frontend.from_mxnet(
mx_sym, shape={"data": data_shape, "row_sel": row_sel, "col": col}, dtype=dtype
)
intrp = relay.create_executor(kind, mod=mod, ctx=ctx, target=target)
op_res = intrp.evaluate()(data_np)
tvm.testing.assert_allclose(op_res.asnumpy(), ref_res.asnumpy(), rtol=1e-5)
tvm.testing.assert_allclose(ref_res.asnumpy(), ref_res.asnumpy(), rtol=1e-5)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I think you will need to install the nightly version of MXNet 2.0. You may follow the guide in https://github.com/dmlc/gluon-nlp.
# Install the version with CUDA 10.1
python3 -m pip install -U --pre "mxnet-cu101>=2.0.0b20201206" -f https://dist.mxnet.io/python
# Install the version with CUDA 10.2
python3 -m pip install -U --pre "mxnet-cu102>=2.0.0b20201206" -f https://dist.mxnet.io/python
# Install the version with CUDA 11
python3 -m pip install -U --pre "mxnet-cu110>=2.0.0b20201206" -f https://dist.mxnet.io/python
# Install the cpu-only version
python3 -m pip install -U --pre "mxnet>=2.0.0b20201206" -f https://dist.mxnet.io/python
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, I have updated the MXNet; however, something had happened to my workspace.
I kept getting this, let me try few more things, and get back on the test case.
..
Check failed: it != type_key2index_.end() == false: Cannot find type auto_scheduler.PythonBasedMeasureCallback. Did you forget to register the node by TVM_REGISTER_NODE_TYPE ?
e24cff8
to
f62760d
Compare
- need to add test case
- TODO: need to find a proper symbol for comparison - currently test function is NOT valid
f62760d
to
4c763cd
Compare
This PR appears to be out of date, please feel free to reopen it if this is not the case. As part of the new year we are attempting to triage the project's open pull requests to ensure that code which Thanks again for your contribution, and feel free to reach out to discuss these changes. |
Adding _npi_advanced_indexing_multiple as discussed in #7186
Need to find a proper
mx.sym.np
and wanted ask for the reviewers help to find it, so that test case can be valid@sxjscience , @junrushao1994
Details:
_npi_advanced_indexing_multiple, BART model. This is triggered when we call a[idx1, idx2]. Also see the MXNet-side implementation.
Standalone example
Pytorch advanced indxing example