You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tvm.apache.org by Haichen Shen via TVM Discuss <no...@discuss.tvm.ai> on 2020/04/07 00:19:16 UTC

[TVM Discuss] [Development] Gather_nd semantics


Currently Relay `gather_nd` op uses the [mxnet semantic](https://mxnet.apache.org/api/python/docs/api/ndarray/op/index.html#mxnet.ndarray.op.gather_nd), which each column in `indices` indicates the indices in `data`. However, Tensorflow [`gather_nd`](https://www.tensorflow.org/api_docs/python/tf/gather_nd) uses each row to indicate the indices. 

Let's use this topic is to discuss whether we should change the current semantics from mxnet `gather_nd` to tf `gather_nd`.

cc @kazum @srkreddy1238 @Laurawly





---
[Visit Topic](https://discuss.tvm.ai/t/gather-nd-semantics/6243/1) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.ai/email/unsubscribe/b2a6a3133524ef8c6293056347df7822b8e0cdfaa4923d442cf6fe6af0452328).

[TVM Discuss] [Development] Gather_nd semantics

Posted by adobay via TVM Discuss <no...@discuss.tvm.ai>.

[quote="kazum, post:6, topic:6243"]
in_indices
[/quote]

ha-haļ¼Œgreat. 
can you help me review my pull request about cumsum? thanks.
https://github.com/apache/incubator-tvm/pull/5289





---
[Visit Topic](https://discuss.tvm.ai/t/gather-nd-semantics/6243/7) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.ai/email/unsubscribe/8433dd67a7af6a229b1039c5de1c5d53e59135270c3293cccc18f0042cf87d5c).

[TVM Discuss] [Development] Gather_nd semantics

Posted by Morita Kazutaka via TVM Discuss <no...@discuss.tvm.ai>.

[quote="adobay, post:5, topic:6243"]
```
in_indices = tf.placeholder(tf.float32, np_indices.shape, name="in_indices")
out = tf.gather_nd(in_data, indices)
```
[/quote]

These lines should be
```
in_indices = tf.placeholder(tf.int32, np_indices.shape, name="in_indices")
out = tf.gather_nd(in_data, in_indices)
```
then, your test worked correctly on my environment.





---
[Visit Topic](https://discuss.tvm.ai/t/gather-nd-semantics/6243/6) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.ai/email/unsubscribe/4472b194ede7fe476088acd69a66c79b97a5fd8b6652494f84fc4610ddcc131c).

[TVM Discuss] [Development] Gather_nd semantics

Posted by adobay via TVM Discuss <no...@discuss.tvm.ai>.

seems incorrect, can not pass my test case@kazum
```python
#######################################################################
# GatherNd
# --------------------------
def _gather_nd(in_shape, indices):
    """test operator GatherNd"""
    np_indices = np.asarray(indices, dtype='int32')
    tf.reset_default_graph()
    with tf.Graph().as_default():
        np_data = np.random.uniform(size=in_shape).astype("float32")
        in_data = tf.placeholder(tf.float32, in_shape, name="in_data")
        in_indices = tf.placeholder(tf.float32, np_indices.shape, name="in_indices")
        out = tf.gather_nd(in_data, indices)
        compare_tf_with_tvm([np_data, np_indices], ['in_data:0', 'in_indices:0'], out.name)


def test_forward_gather_nd():
    _gather_nd((2, 3), [[0, 0], [1, 1]])
    _gather_nd((2, 3), [[1], [0]])
    _gather_nd((2, 3, 4), [[1]])
    _gather_nd((4, 3, 2), [[0, 1], [1, 0]])
    _gather_nd((2, 4), [[[0, 0]], [[0, 1]]])
    _gather_nd((4, 2), [[[1]], [[0]]])
    _gather_nd((2, 4, 2), [[[1]], [[0]]])
    _gather_nd((2, 2, 3), [[[0, 1], [1, 0]], [[0, 0], [1, 1]]])
    _gather_nd((2, 3, 3), [[[0, 0, 1], [1, 0, 1]], [[0, 1, 1], [1, 1, 0]]])
```





---
[Visit Topic](https://discuss.tvm.ai/t/gather-nd-semantics/6243/5) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.ai/email/unsubscribe/45fe43e3b19eb496a8603efd052477d9a746b011c3af10fcbaf4767e7e4b8fb2).

[TVM Discuss] [Development] Gather_nd semantics

Posted by Morita Kazutaka via TVM Discuss <no...@discuss.tvm.ai>.

https://github.com/apache/incubator-tvm/pull/5279





---
[Visit Topic](https://discuss.tvm.ai/t/gather-nd-semantics/6243/3) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.ai/email/unsubscribe/704e7a848dbbefb7c7cc940f0946df9ed7739377b15d8e29a2a428b6399d63c7).

[TVM Discuss] [Development] Gather_nd semantics

Posted by Morita Kazutaka via TVM Discuss <no...@discuss.tvm.ai>.

I think we don't need to change the current semantics.  We can easily implement Tensorflow gather_nd with the mxnet gather_nd (and vice versa).

Here is a pseudo code:
```
tf_gather_nd(data, indices) = relay.gather_nd(data, transpose(indices, [N-1, 0, 1, ..., N-2]))
```
where N is the dimension of indices.

The current tensorflow frontend doesn't do this conversion.  I'll send a fix for this.





---
[Visit Topic](https://discuss.tvm.ai/t/gather-nd-semantics/6243/2) to respond.

You are receiving this because you enabled mailing list mode.

To unsubscribe from these emails, [click here](https://discuss.tvm.ai/email/unsubscribe/29e910cb36923eb5654e3bc632554ede105c63fc9f4d08c21a4fc305bd20b8da).