You can add the losses inplace as long as no errors are raised, but would accumulate the computation graphs. This post 4 explains it in more detail.
The losses wouldn’t be equal, since you are scaling loss2 by len(x) in each iteration.