interesaaat commented on issue #6282:
URL: https://github.com/apache/incubator-tvm/issues/6282#issuecomment-675009079
This should work:
```
import numpy as np
import torch
class My_module(torch.nn.Module):
def __init__(self, features):
super(My_module, self).__init__()
self._features = torch.from_numpy(features)
def forward(self, x):
return torch.index_select(self._features, 0, x).view(-1, 1)
indexes = np.array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0,
0, 0, 0, 0], dtype=np.int64)
features = np.array([83, 192, 173, 168, 36, 120, 0, 0, 0, 34, 0,
0, 86, 92,
0, 17, 0, 0, 133, 0, 0, 165, 113, 33, 98, 97, 96, 63,
0, 0, 0, 0, 0, 135, 0, 167, 0, 52, 145, 0, 0, 0,
95, 179, 0, 0, 0, 147, 62, 30, 0, 0, 134, 0, 0, 156,
0, 0, 139, 132, 100, 0, 0, 145, 0, 0, 187, 191, 81, 140,
120, 161, 0, 186, 0, 0, 185, 182, 42, 127, 0, 0, 109, 0,
0, 33, 94, 23, 0, 0, 0, 108, 183, 0, 0, 102, 0, 0,
42, 134, 63, 39, 0, 0, 0, 143, 0, 189, 0, 0, 0, 122,
47, 0, 1, 0, 0, 159, 21, 70, 0, 0, 0, 22, 0, 58,
33, 0, 0, 0, 51, 196, 0, 0, 0, 78, 178, 0, 154, 0,
0, 0, 77, 87, 0, 0, 190, 18, 103, 161, 0, 0, 185, 0,
79, 0, 142, 0, 0, 59, 0, 0, 115, 69, 0, 59, 190, 0,
0, 0, 85, 0, 51, 24, 0, 0, 158, 95, 0, 0, 195, 0,
0], dtype=np.int32)
test_result = np.array([[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83],
[83]])
t_indexes = torch.from_numpy(indexes)
pt_model = My_module(features)
result = pt_model.forward(t_indexes).numpy()
np.testing.assert_array_equal(test_result, result)
```
----------------------------------------------------------------
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:
[email protected]