Weights for different datasets

If you have 2 different datasets that you would like to upweight training samples from one more the than other, how would you go about that? This is similar to what we do in class imbalance but for datasets instead of classes.
A small example would be great and appreciated!

Cost functions like CrossEntropyLoss have a parameter reduction that you can set to none so that you get the loss per instance, as I understand it. You could maybe use that and weight the relevant instances yourself before combining all losses and calling backward.