You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2021/01/08 06:33:56 UTC
[GitHub] [tvm] insop opened a new pull request #7230: [FRONTEND][Mxnet][nuymp] Adding _npi_advanced_indexing_multiple
insop opened a new pull request #7230:
URL: https://github.com/apache/tvm/pull/7230
Adding _npi_advanced_indexing_multiple as discussed in https://github.com/apache/tvm/issues/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.
- Example from (BART)[https://raw.githubusercontent.com/dmlc/gluon-nlp/master/src/gluonnlp/models/bart.py]
```
batch_indices = mx.npx.arange_like(sequence, axis=0).astype(mx.np.int32)
outputs = sequence[batch_indices, valid_length - 1]
```
- Standalone example
```
import mxnet as mx
from mxnet import use_np
from mxnet.gluon import nn
from mxnet import np, npx
sequence = np.array([[1, 2,11,12], [3, 4,23,24], [5, 6,35,36]])
Out[30]:
array([[ 1., 2., 11., 12.],
[ 3., 4., 23., 24.],
[ 5., 6., 35., 36.]])
batch_indices = mx.npx.arange_like(sequence, axis=0).astype(mx.np.int32)
Out[32]: array([0, 1, 2], dtype=int32)
valid_length=2
outputs = sequence[batch_indices, valid_length - 1]
Out[35]: array([2., 4., 6.])
```
- Pytorch advanced indxing example
```
import torch
In [44]: a = torch.randn(5, 7, dtype=torch.double)
In [45]: a
Out[45]:
tensor([[-1.2230, 0.7823, 0.6655, -0.8564, -0.2611, -0.0423, -0.6728],
[ 1.6607, 0.9779, -0.2754, -0.7090, -0.3243, 2.2017, -1.7534],
[-1.9319, 0.5544, 2.0244, -0.8144, -0.2657, 0.7849, -0.4825],
[ 0.0085, 1.0663, 0.1695, -0.3458, -0.4960, 1.2339, 0.6244],
[ 0.5265, -2.0689, -0.4739, 0.5544, 0.8612, 0.2270, -2.0888]],
dtype=torch.float64)
In [46]: t = a[(0,1,2,3,4),1]
In [47]: t
Out[47]: tensor([ 0.7823, 0.9779, 0.5544, 1.0663, -2.0689], dtype=torch.float64)
In [48]: t = a[(0,1,2,3,3),1] In [49]: t
Out[49]: tensor([0.7823, 0.9779, 0.5544, 1.0663, 1.0663], dtype=torch.float64)
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] insop commented on a change in pull request #7230: [FRONTEND][Mxnet][nuymp] Adding _npi_advanced_indexing_multiple
Posted by GitBox <gi...@apache.org>.
insop commented on a change in pull request #7230:
URL: https://github.com/apache/tvm/pull/7230#discussion_r553766990
##########
File path: tests/python/frontend/mxnet/test_forward.py
##########
@@ -1935,6 +1935,29 @@ def verify(data_shape, axis, use_length, length):
verify((2, 3, 4), 2, True, np.array([[3, 4, 2], [1, 2, 1]]).astype("int32"))
+@pytest.mark.parametrize(
+ "data_shape, row_sel, col",
+ [
+ ((5, 7), (0, 1, 2, 3, 4,), 2),
+ ],
+)
+@pytest.mark.parametrize("dtype", ["float64", "float32"])
+@tvm.testing.parametrize_targets
+@pytest.mark.parametrize("kind", ["graph", "vm", "debug"])
+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)
+ data = mx.sym.var("data")
+ 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])
Review comment:
@junrushao1994, @sxjscience
Any idea what to use in `mx.sym.np` for the `advanced indexing` ?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] insop commented on a change in pull request #7230: [FRONTEND][Mxnet][nuymp] Adding _npi_advanced_indexing_multiple
Posted by GitBox <gi...@apache.org>.
insop commented on a change in pull request #7230:
URL: https://github.com/apache/tvm/pull/7230#discussion_r555005379
##########
File path: tests/python/frontend/mxnet/test_forward.py
##########
@@ -1935,6 +1935,29 @@ def verify(data_shape, axis, use_length, length):
verify((2, 3, 4), 2, True, np.array([[3, 4, 2], [1, 2, 1]]).astype("int32"))
+@pytest.mark.parametrize(
+ "data_shape, row_sel, col",
+ [
+ ((5, 7), (0, 1, 2, 3, 4,), 2),
+ ],
+)
+@pytest.mark.parametrize("dtype", ["float64", "float32"])
+@tvm.testing.parametrize_targets
+@pytest.mark.parametrize("kind", ["graph", "vm", "debug"])
+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)
+ data = mx.sym.var("data")
+ 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])
Review comment:
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.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] jroesch closed pull request #7230: [FRONTEND][Mxnet][nuymp] Adding _npi_advanced_indexing_multiple
Posted by GitBox <gi...@apache.org>.
jroesch closed pull request #7230:
URL: https://github.com/apache/tvm/pull/7230
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] sxjscience commented on a change in pull request #7230: [FRONTEND][Mxnet][nuymp] Adding _npi_advanced_indexing_multiple
Posted by GitBox <gi...@apache.org>.
sxjscience commented on a change in pull request #7230:
URL: https://github.com/apache/tvm/pull/7230#discussion_r555115290
##########
File path: tests/python/frontend/mxnet/test_forward.py
##########
@@ -1935,6 +1935,29 @@ def verify(data_shape, axis, use_length, length):
verify((2, 3, 4), 2, True, np.array([[3, 4, 2], [1, 2, 1]]).astype("int32"))
+@pytest.mark.parametrize(
+ "data_shape, row_sel, col",
+ [
+ ((5, 7), (0, 1, 2, 3, 4,), 2),
+ ],
+)
+@pytest.mark.parametrize("dtype", ["float64", "float32"])
+@tvm.testing.parametrize_targets
+@pytest.mark.parametrize("kind", ["graph", "vm", "debug"])
+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)
+ data = mx.sym.var("data")
+ 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])
Review comment:
Is it possible to do the following?
```python
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`.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] jroesch commented on pull request #7230: [FRONTEND][Mxnet][nuymp] Adding _npi_advanced_indexing_multiple
Posted by GitBox <gi...@apache.org>.
jroesch commented on pull request #7230:
URL: https://github.com/apache/tvm/pull/7230#issuecomment-1016828336
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
is ready for review and/or merging receives adequate attention.
Thanks again for your contribution, and feel free to reach out to discuss these changes.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] insop commented on a change in pull request #7230: [FRONTEND][Mxnet][nuymp] Adding _npi_advanced_indexing_multiple
Posted by GitBox <gi...@apache.org>.
insop commented on a change in pull request #7230:
URL: https://github.com/apache/tvm/pull/7230#discussion_r555663382
##########
File path: tests/python/frontend/mxnet/test_forward.py
##########
@@ -1935,6 +1935,29 @@ def verify(data_shape, axis, use_length, length):
verify((2, 3, 4), 2, True, np.array([[3, 4, 2], [1, 2, 1]]).astype("int32"))
+@pytest.mark.parametrize(
+ "data_shape, row_sel, col",
+ [
+ ((5, 7), (0, 1, 2, 3, 4,), 2),
+ ],
+)
+@pytest.mark.parametrize("dtype", ["float64", "float32"])
+@tvm.testing.parametrize_targets
+@pytest.mark.parametrize("kind", ["graph", "vm", "debug"])
+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)
+ data = mx.sym.var("data")
+ 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])
Review comment:
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](https://github.com/apache/incubator-mxnet/blob/124d8417984ed9205f972eb1c2cadbf028b94eb3/python/mxnet/symbol/numpy/_symbol.py#L149))
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)
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] insop commented on a change in pull request #7230: [FRONTEND][Mxnet][nuymp] Adding _npi_advanced_indexing_multiple
Posted by GitBox <gi...@apache.org>.
insop commented on a change in pull request #7230:
URL: https://github.com/apache/tvm/pull/7230#discussion_r557322175
##########
File path: tests/python/frontend/mxnet/test_forward.py
##########
@@ -1935,6 +1935,29 @@ def verify(data_shape, axis, use_length, length):
verify((2, 3, 4), 2, True, np.array([[3, 4, 2], [1, 2, 1]]).astype("int32"))
+@pytest.mark.parametrize(
+ "data_shape, row_sel, col",
+ [
+ ((5, 7), (0, 1, 2, 3, 4,), 2),
+ ],
+)
+@pytest.mark.parametrize("dtype", ["float64", "float32"])
+@tvm.testing.parametrize_targets
+@pytest.mark.parametrize("kind", ["graph", "vm", "debug"])
+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)
+ data = mx.sym.var("data")
+ 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])
Review comment:
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 ?
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] sxjscience commented on a change in pull request #7230: [FRONTEND][Mxnet][nuymp] Adding _npi_advanced_indexing_multiple
Posted by GitBox <gi...@apache.org>.
sxjscience commented on a change in pull request #7230:
URL: https://github.com/apache/tvm/pull/7230#discussion_r554773549
##########
File path: tests/python/frontend/mxnet/test_forward.py
##########
@@ -1935,6 +1935,29 @@ def verify(data_shape, axis, use_length, length):
verify((2, 3, 4), 2, True, np.array([[3, 4, 2], [1, 2, 1]]).astype("int32"))
+@pytest.mark.parametrize(
+ "data_shape, row_sel, col",
+ [
+ ((5, 7), (0, 1, 2, 3, 4,), 2),
+ ],
+)
+@pytest.mark.parametrize("dtype", ["float64", "float32"])
+@tvm.testing.parametrize_targets
+@pytest.mark.parametrize("kind", ["graph", "vm", "debug"])
+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)
+ data = mx.sym.var("data")
+ 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])
Review comment:
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)
```
##########
File path: tests/python/frontend/mxnet/test_forward.py
##########
@@ -1935,6 +1935,29 @@ def verify(data_shape, axis, use_length, length):
verify((2, 3, 4), 2, True, np.array([[3, 4, 2], [1, 2, 1]]).astype("int32"))
+@pytest.mark.parametrize(
+ "data_shape, row_sel, col",
+ [
+ ((5, 7), (0, 1, 2, 3, 4,), 2),
+ ],
+)
+@pytest.mark.parametrize("dtype", ["float64", "float32"])
+@tvm.testing.parametrize_targets
+@pytest.mark.parametrize("kind", ["graph", "vm", "debug"])
+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)
+ data = mx.sym.var("data")
+ 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])
Review comment:
You may use this:
```python
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)
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] insop commented on a change in pull request #7230: [FRONTEND][Mxnet][nuymp] Adding _npi_advanced_indexing_multiple
Posted by GitBox <gi...@apache.org>.
insop commented on a change in pull request #7230:
URL: https://github.com/apache/tvm/pull/7230#discussion_r553766990
##########
File path: tests/python/frontend/mxnet/test_forward.py
##########
@@ -1935,6 +1935,29 @@ def verify(data_shape, axis, use_length, length):
verify((2, 3, 4), 2, True, np.array([[3, 4, 2], [1, 2, 1]]).astype("int32"))
+@pytest.mark.parametrize(
+ "data_shape, row_sel, col",
+ [
+ ((5, 7), (0, 1, 2, 3, 4,), 2),
+ ],
+)
+@pytest.mark.parametrize("dtype", ["float64", "float32"])
+@tvm.testing.parametrize_targets
+@pytest.mark.parametrize("kind", ["graph", "vm", "debug"])
+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)
+ data = mx.sym.var("data")
+ 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])
Review comment:
@junrushao1994, @sxjscience
Any idea what to use in `mx.sym.np` for the `advanced indexing` ?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] insop commented on a change in pull request #7230: [FRONTEND][Mxnet][nuymp] Adding _npi_advanced_indexing_multiple
Posted by GitBox <gi...@apache.org>.
insop commented on a change in pull request #7230:
URL: https://github.com/apache/tvm/pull/7230#discussion_r553766990
##########
File path: tests/python/frontend/mxnet/test_forward.py
##########
@@ -1935,6 +1935,29 @@ def verify(data_shape, axis, use_length, length):
verify((2, 3, 4), 2, True, np.array([[3, 4, 2], [1, 2, 1]]).astype("int32"))
+@pytest.mark.parametrize(
+ "data_shape, row_sel, col",
+ [
+ ((5, 7), (0, 1, 2, 3, 4,), 2),
+ ],
+)
+@pytest.mark.parametrize("dtype", ["float64", "float32"])
+@tvm.testing.parametrize_targets
+@pytest.mark.parametrize("kind", ["graph", "vm", "debug"])
+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)
+ data = mx.sym.var("data")
+ 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])
Review comment:
@junrushao1994, @sxjscience
Need your help to find a proper `mx.sym.np` for the `advanced indexing`, currently the test is not valid yet.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [tvm] sxjscience commented on a change in pull request #7230: [FRONTEND][Mxnet][nuymp] Adding _npi_advanced_indexing_multiple
Posted by GitBox <gi...@apache.org>.
sxjscience commented on a change in pull request #7230:
URL: https://github.com/apache/tvm/pull/7230#discussion_r556152281
##########
File path: tests/python/frontend/mxnet/test_forward.py
##########
@@ -1935,6 +1935,29 @@ def verify(data_shape, axis, use_length, length):
verify((2, 3, 4), 2, True, np.array([[3, 4, 2], [1, 2, 1]]).astype("int32"))
+@pytest.mark.parametrize(
+ "data_shape, row_sel, col",
+ [
+ ((5, 7), (0, 1, 2, 3, 4,), 2),
+ ],
+)
+@pytest.mark.parametrize("dtype", ["float64", "float32"])
+@tvm.testing.parametrize_targets
+@pytest.mark.parametrize("kind", ["graph", "vm", "debug"])
+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)
+ data = mx.sym.var("data")
+ 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])
Review comment:
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.
```bash
# 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
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org