当在GPU操作,并且切片操作index越界的时候会抛出以上的异常
data = [[1, 2, 14],[3, 4, 5]]
x_data = torch.tensor(data).to('cuda')
rand_tensor = torch.rand(13).to('cuda')
rand_tensor[x_data[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.
如果是在cpu操作的话,会直接抛出IndexError
data = [[1, 2, 14],[3, 4, 5]]
x_data = torch.tensor(data)
rand_tensor = torch.rand(13)
rand_tensor[x_data[0]]
>>> IndexError: index 14 is out of bounds for dimension 0 with size 13