One approach will be for your dataset to return the index in the __getitem__ function and then you can have access to it.
# In dataset definition
  def __getitem__(self, idx):
    return foo, bar, idx # To replace just foo, bar

# In train loop
  for foos, bars, idxs in dataloader:
    # Now you have access to the indices in the dataset of each sample.

Another approach is to get a dataloader that does not shuffle the samples, and then you know that the indices are given in increasing order from 0 to dataset_size by groups of batch_size.