Solved by ptrblck in post #2 
              
              
                The weight should provide a weight for each sample, while in your code it looks like you are trying to pass class weights. 
Have a look at this example on how to use the WeightedRandomSampler.