If you use the retain_graph=True parameter, the gradients will be kept after you run a backward pass.
e.backward(loss2, retain_graph=True)
This means, you can now run another backward without getting an error.