Note that the input to the WeightedRandomSampler in pytorch’s example is weight[target] and not weight. The length of  weight_target  is target whereas the length of weight is equal to the number of classes. This is probably the reason for the difference. Try using WeightedRandomSampler(..,...,..,replacement=False) to prevent it from happening.
As far as the loss for each steps go, it looks good. See if you could aggregate together all the losses and check if the loss for every subsequent epoch is decreasing.
However, having a batch with the same class is definitely an issue.