Solved by ptrblck in post #6 
              
              
                I used 0.4.0 and tried to stay as close to your code as possible. 
This code works on my machine: 
data = torch.randn(1000, 1)
target = torch.cat((
    torch.zeros(998),
    torch.ones(1),
    torch.ones(1)*2
)).long()

cls_weights = torch.from_numpy(
    compute_class_weight('balanced', np.unique(t…