How to do multi output regression with skorch/pytorch

Hi, I’m trying to figure out how to do multi output regression with skorch or Pytorch. Actually I tried to do this with pytorch and somehow I managed to do this which worked and I got to see my loss decrease over epochs but I’m not sure if it is the best way. here is what I did:

def train(model, criterion, optimizer, loader, epochs):
    losses = []
    for e in range(epochs):
        epoch_loss = 0
        for x, y in loader:
            y1, y2 = y[:, 0], y[:, 1]
            y_pred = model(x)
            y_pred1, y_pred2 = y_pred[:, 0], y_pred[:, 1]
            loss1 = criterion(y_pred1, y1)
            loss2 = criterion(y_pred2, y2)
            loss = (loss1 + loss2) * 0.5

you can see that my model return two outputs and I’m calculating every loss separated and then taking the average. I did this because if I called the loss directly on the output and target it will take the average of the whole tensor and that’s bad somehow since I have two different losses for two different values. How I achieve this in pytorch or better in skorch since it is easier to use and to implement cross validation?

moreover can you explain to me how multi regression would work in pytorch? I mean for example if I’m predicting two values that one of them between 100-1000 and the other between 0-1, how would summing and taking the average of the losses work!?