Hi, ptrblck
In the code above, is there anything wrong about datatype conversion?
I just remove .clone().detach() on weight and add  .numpy() to weight then pass to sampler, it works fine.
And the Pytorch raise a UserWarning when I run the snippet above:
UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).

Does WeightedRandomSampler works only fine with numpy array?