Weighted Random Sampler and Weights in loss function

Is there any difference in giving weights in sampler and giving weights in loss function for unbalanced datasets?

While both can be used to counter the negative effects of an imbalanced dataset, you will see different results, as the strategies of over-/undersampling and loss weighting are independent to each other.