Hmm, I believe the official Dataloader has some logic regarding to indexing (like you mentioned), maybe also depends on if you set shuffle=True/False ,sampler, etc, but I always add an extra guard with modulo operation ("%") even if it is redundant.
I recommend reading the official guide to have a better understanding of what you can do with DataSet and DataLoader, here is a link:

  
      pytorch.org
  
  
    

torch.utils.data — PyTorch 1.6.0 documentation 1