Hi @richard, thanks for the reply:
I made this customized loss. However, the optimizer does not optimize the w1 and  w2. (I am using pytorch 0.3)
class MY_LOSS(nn.Module):
    def __init__(self):
        super(MY_LOSS, self).__init__()
        self.loss1 = nn.CrossEntropyLoss()
        self.loss2 = nn.MSELoss()
        self.w1 = Variable(torch.Tensor(1), requires_grad=True).type(FLOAT)
        self.w2 = Variable(torch.Tensor(1), requires_grad=True).type(FLOAT)


    def forward(self, inp1, tar1, inp2, tar2):

        loss1 = self.loss1(inp1, tar1)
        loss2 = self.loss2(inp2, tar2) 

        combined_loss = loss1 * torch.exp(-self.w1) + self.w1 + loss2 * torch.exp(-self.w2) + self.w2
        return combined_loss, loss1, loss2, self.w1, self.w2