which version of pytorch you used? I can run this part code alone successfully.
In [1]: import torch

In [2]: _feature = torch.rand(4,6,50)

In [3]: top = 10

In [4]: _b, _c = 4, 6

In [5]: _feature = _feature.view(_b, _c, -1)  # [N, C, K]
   ...: assert _feature is not None, "Error-1"
   ...: _feature_sum = torch.sum(_feature.pow(2), dim=1)  # [N, K]
   ...: assert _feature is not None, "Error-2"
   ...: _idx = torch.topk(_feature_sum, top, dim=-1, sorted=False)[1]  # [N, top]
   ...: if _idx.max() > 10000:
   ...:     print("_idx error")
   ...:     print(_idx.max())
   ...: _jdx = torch.arange(_b).unsqueeze(1).repeat(1, top)
   ...: _feature = _feature[_jdx, :, _idx]  # [N, top, C]

In [6]: _feature.shape
Out[6]: torch.Size([4, 10, 6])

The problem above appears randomly.