Repository: pytorch
Issue: Accessing elements of tensor with multi-dimensional index results `IndexError`
Labels: triaged,module: numpy,module: advanced indexing

## 🐛 Bug

<!-- A clear and concise description of what the bug is. -->

Accessing the elements of a tensor with a multi-dimensional index results in an `IndexError`, e.g. "index 6 is out of bounds for dimension 0 with size 5". 

This problem only occurs if indexing the elements with a torch tensor, while no error is raised if the same elements are indexed with a list or a numpy array.

## To Reproduce

Steps to reproduce the behavior:

```
import torch
a = torch.arange(5 * 7 * 9).view(5,7,9)
print(a.shape)
b = torch.Tensor([[0, 6, 8], [4,6,8]]).transpose(0, 1).long()
print(b.shape)
# no error occurs, elements are selected as expected
print(a[b.tolist()])
print(a[b.numpy()])
# index error occurs
print(a[b])
```

Error message:

```
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-1-47068bc99d32> in <module>
      8 a[b.numpy()]
      9 # index error occurs
---> 10 a[b]

IndexError: index 6 is out of bounds for dimension 0 with size 5
```

## Expected behavior

`a[b]` should not result in an index error and `a[b]` should return the same result as `a[b.numpy()]`, `a[b.tolist()]`.

## Environment

```
Collecting environment information...
PyTorch version: 1.5.0
Is debug build: False
CUDA used to build PyTorch: 10.1

OS: Ubuntu 18.04.3 LTS (x86_64)
GCC version: (GCC) 7.1.0
Clang version: Could not collect
CMake version: version 3.10.2

Python version: 3.7 (64-bit runtime)
Is CUDA available: True
CUDA runtime version: 10.1.105
GPU models and configuration:
GPU 0: Quadro GP100
GPU 1: Quadro GP100

Nvidia driver version: 418.116.00
cuDNN version: Could not collect

Versions of relevant libraries:
[pip] numpy==1.18.5
[pip] pytorch3d==0.2.0
[pip] torch==1.5.0
[pip] torchfile==0.1.0
[pip] torchvision==0.6.0a0+82fd1c8
[conda] blas                      1.0                         mkl
[conda] cudatoolkit               10.1.243             h6bb024c_0
[conda] faiss-cpu                 1.6.3            py37h6bb024c_0    pytorch
[conda] mkl                       2020.1                      217
[conda] mkl-service               2.3.0            py37he904b0f_0
[conda] mkl_fft                   1.0.15           py37ha843d7b_0
[conda] mkl_random                1.1.1            py37h0573a6f_0
[conda] numpy                     1.18.5                   pypi_0    pypi
[conda] numpy-base                1.18.1           py37hde5b4d6_1
[conda] pytorch                   1.5.0           py3.7_cuda10.1.243_cudnn7.6.3_0    pytorch
[conda] pytorch3d                 0.2.0                    pypi_0    pypi
[conda] torchfile                 0.1.0                    pypi_0    pypi
[conda] torchvision               0.6.0                py37_cu101    pytorch
```

## Additional context

This problem does not occur when using a one-dimensional input tensor and index tensor. For example, the same code from above with only the first dimension works as expected:

```
import torch
a = torch.arange(5).view(5)
print(a.shape)
b = torch.Tensor([[0], [4]]).transpose(0, 1).long()
print(b.shape)
# no error occurs, elements are selected as expected
print(a[b.tolist()])
print(a[b.numpy()])
# index error occurs
print(a[b])
```

cc @mruberry @rgommers