a = cross_entropy(output, label)
b = nllloss(output, label)
a.backward(retain_graph=True)
b.backward()

Memory used by CUDA will increase until memory out.
However
a = cross_entropy(output, label)
a += nllloss(output, label)
a.backward()

The problem mentioned before will not appear.