Thanks for replying! It is a big project and the code is a bit complicated, so can you detail the part you want to check?
PS: If I use the form: loss = loss1 + 0*loss2, the memory usage is normal (7971MB).