Both solutions are correct and wrong at the same time, because you are not defining the variable loss. If the two criteria are exactly the same one, you can create just one object and do:
criterion = nn.L1Loss()
loss = criterion(input_1,output_1)
loss += criterion(input_2,output_2)
loss.backward()