Solved by chetan_patil in post #2 
              
              
                Hi, if you clearly look at the documentation, the weight must be same size of the target or predictions. 
In your case, the weight Tensor must be of size [128,1] and not [128,2]. 
You can use the weights the following way. 
weight = torch.zeros_like(target)
weight[target==0] = 3
weight[target==1] = …