Good to hear it’s working now!
However, your approach should also work, as the indices are sampled to select the target classes.
You could replace the TensorDataset with this dummy dataset:
class MyDataset(Dataset):
    def __init__(self, data, target):
        self.data = data
        self.target = target
        
    def __getitem__(self, index):
        
        return index
    
    def __len__(self):
        return len(self.data)

, and you will see, that the indices of 998 and 999 are repeated very often.
Could you provide a code snippet so that I could have another look and make sure it’s not a bug for a special edge case?