How to sample atleast one sample from each class for a batch in dataloaders

Writing a custom sampler as described e.g. here might also be a valid approach, as it would allow you to create the batch indices beforehand and thus make sure which class distribution is used.