Repository: pytorch
Issue: CUDA error in ../aten/src/ATen/native/cuda/IndexKernel.cu when index tensor contains multiple indices
Labels: triaged,module: advanced indexing

### 🐛 Describe the bug

```python
import torch
a = torch.empty(2,3,4,5).cuda()
b = torch.tensor([1,0,2]).cuda()
a[b]
```

... fails with ...

```text
../aten/src/ATen/native/cuda/IndexKernel.cu:96: operator(): block: [0,0,0], thread: [120,0,0] Assertion `-sizes[i] <= index && index < sizes[i] && "index out of bounds"` failed.
../aten/src/ATen/native/cuda/IndexKernel.cu:96: operator(): block: [0,0,0], thread: [121,0,0] Assertion `-sizes[i] <= index && index < sizes[i] && "index out of bounds"` failed.
../aten/src/ATen/native/cuda/IndexKernel.cu:96: operator(): block: [0,0,0], thread: [122,0,0] Assertion `-sizes[i] <= index && index < sizes[i] && "index out of bounds"` failed.
../aten/src/ATen/native/cuda/IndexKernel.cu:96: operator(): block: [0,0,0], thread: [123,0,0] Assertion `-sizes[i] <= index && index < sizes[i] && "index out of bounds"` failed.
../aten/src/ATen/native/cuda/IndexKernel.cu:96: operator(): block: [0,0,0], thread: [124,0,0] Assertion `-sizes[i] <= index && index < sizes[i] && "index out of bounds"` failed.
../aten/src/ATen/native/cuda/IndexKernel.cu:96: operator(): block: [0,0,0], thread: [125,0,0] Assertion `-sizes[i] <= index && index < sizes[i] && "index out of bounds"` failed.
../aten/src/ATen/native/cuda/IndexKernel.cu:96: operator(): block: [0,0,0], thread: [126,0,0] Assertion `-sizes[i] <= index && index < sizes[i] && "index out of bounds"` failed.
../aten/src/ATen/native/cuda/IndexKernel.cu:96: operator(): block: [0,0,0], thread: [127,0,0] Assertion `-sizes[i] <= index && index < sizes[i] && "index out of bounds"` failed.
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/dist-packages/torch/_tensor.py", line 431, in __repr__
    return torch._tensor_str._str(self, tensor_contents=tensor_contents)
  File "/usr/local/lib/python3.9/dist-packages/torch/_tensor_str.py", line 664, in _str
    return _str_intern(self, tensor_contents=tensor_contents)
  File "/usr/local/lib/python3.9/dist-packages/torch/_tensor_str.py", line 595, in _str_intern
    tensor_str = _tensor_str(self, indent)
  File "/usr/local/lib/python3.9/dist-packages/torch/_tensor_str.py", line 347, in _tensor_str
    formatter = _Formatter(get_summarized_data(self) if summarize else self)
  File "/usr/local/lib/python3.9/dist-packages/torch/_tensor_str.py", line 138, in __init__
    tensor_view, torch.isfinite(tensor_view) & tensor_view.ne(0)
RuntimeError: CUDA error: device-side assert triggered
CUDA kernel errors might be asynchronously reported at some other API call, so the stacktrace below might be incorrect.
For debugging consider passing CUDA_LAUNCH_BLOCKING=1.
Compile with `TORCH_USE_CUDA_DSA` to enable device-side assertions.
```

Not sure if this is intended use case. Implementation of `gpu_index_kernel` seems to try supporting such usage, as [it converts linear index to an actual offset into the strides](https://github.com/pytorch/pytorch/blob/main/aten/src/ATen/native/cuda/IndexKernel.cu#L84), but [the way `sizes` is populated](https://github.com/pytorch/pytorch/blob/main/aten/src/ATen/native/cuda/IndexKernel.cu#L74) triggers the aforementioned assertion.

### Versions

```text
Versions of relevant libraries:
[pip3] byted-torch==2.1.0+u9
[pip3] flake8==4.0.1
[pip3] mypy==1.8.0
[pip3] mypy-extensions==1.0.0
[pip3] numpy==1.24.4
[pip3] onnx==1.13.1
[pip3] onnxruntime==1.7.0
[pip3] pytorch-lightning==2.0.0
[pip3] rotary-embedding-torch==0.5.3
[pip3] soft-moe-pytorch==0.1.5
[pip3] tf2onnx==1.9.3
[pip3] torch==2.1.0
[pip3] torch-complex==0.4.3
[pip3] torch-stft==0.1.4
[pip3] torchaudio==2.1.0+cu121
[pip3] torchaudio-augmentations==0.2.1
[pip3] torchlibrosa==0.1.0
[pip3] torchmetrics==1.2.1
[pip3] torchvision==0.16.0+cu121
[pip3] triton==2.1.0
[pip3] vector-quantize-pytorch==1.12.5
[conda] Could not collect
```