Hello,
I have a model that outputs two values, one for a classification task, and other for a regression task. Because I don’t know if it is even possible to use in a single loss function multiple output / target pairs, my model outputs a single tensor where input[:8] are the probabilities for the classification task, and input[8] is the regressed scalar, so the loss function:
def species_length_loss(input, target):
    input_species = input[:,:8]
    input_length  = input[:,8]

    target_species = target[:,0].long()
    target_length  = target[:,1]

    if target_species != 7: #doesn't work b/c target_species is N (batch size)
        loss = F.mse_loss(input_length, target_length) * 1e-4 + F.nll_loss(input_species, target_species)
    else:
        loss = F.nll_loss(input_species, target_species)

    return loss

I’ve placed the if statement to illustrate what I want to do, but even if just leave loss = F.mse_loss(input_length, target_length) * 1e-4 + F.nll_loss(input_species, target_species)  (w/o the statement) I get the error:
RuntimeError: one of the variables needed for gradient computation has been modified by an inplace operation
Any ideas of suggestions how to accomplish this?
Thanks