You could use a weighted loss as described e.g. in the nn.CrossEntropyLoss docs or alternatively you could use over/undersampling using a WeightedRandomSampler. Here is an example of its usage.
nn.CrossEntropyLoss
WeightedRandomSampler