Below are examples from Pytorch’s forums which address your question.

list(WeightedRandomSampler([0.1, 0.9, 0.4, 0.7, 3.0, 0.6], 5, replacement=True))
Output: [0, 0, 0, 1, 0]
list(WeightedRandomSampler([0.9, 0.4, 0.05, 0.2, 0.3, 0.1], 5, replacement=False))
Output: [0, 1, 4, 3, 2]

For a batch size < no_of classes, using Replacement = False would generate independent samples. If batch size > no_of classes, it would throw this error, RuntimeError: cannot sample n_sample > prob_dist.size(-1) samples without replacement.