Solved by ptrblck in post #2 
              
              
                I think the easiest approach would be to specify reduction='none' in your criterion and then multiply each output with your weights: 
target = torch.tensor([[0,1,0,1,0,0]], dtype=torch.float32)
output = torch.randn(1, 6, requires_grad=True)
weights = torch.tensor([0.16, 0.16, 0.25, 0.25, 0.083, 0.08…