The memory after DEL operation don’t return to the device.
You need to use the same variable for same outputs and DEL this variable.
I think that you can do this:
optimizer.zero_grad()
out = network(input)
loss1 = criterion(out, target1)
del out
out = network(input)
loss2 = criterion(out, target2)
del out
loss = loss1 + loss2
loss.backward()