I’m not sure if for the same network model both approaches would yield the exact same loss – apart from my last comment below – I’m not even sure if it indeed has to be the exact same loss.
For text generation models using RNNs, I usually see the first approach where the loss is computed for each word/letter step by step; see this Pytorch Seq2Seq tutorial for example 36, where the loss is computed between each input and target word of the sequence and summed up. I follow this approach for an RNN autoencoder which is essentially just a Seq2Seq model.
For a CNN autoencoder, I use the second approach, since there are no time steps, i.e., the whole output sequence is generated at the same time. Here, after the forward() I loop over each input-target pair to calculate the loss between words of all pairs.

loss.backward()  in each loop step

I’ve never seen loss.backward() within a loop itself. This might be wrong – not sure if it will work in fact. I’ve only ever seen that the loss is aggregated (sum) within the loop and backward() called only once after the loop is finished.