You could use the WeightedRandomSampler to over- or undersample the dataset. Here is an example showing how to use it.
WeightedRandomSampler