Do you see this issue for the last batch?
If you are using a DataLoader, the last batch might be smaller, if the length of your dataset is not divisible by the batch_size without a remainder. In your case, the last batch might only contain two samples, thus you cannot index it using [2, 0, 0, 0].