I hope my title makes sense. I would like to know whether the following two snippets of code are equivalent or not:
criterion = nn.MSELoss()
output = net(input)
loss = criterion(output, target)
loss.backward()

Where output is an array of multiple values. Would the next snippet of code be identical?
criterion = nn.MSELoss()
output = net(input)
loss = 0
for (out, tar) in zip(output, target):
    loss += criterion(out, tar)
loss.backward()

Now assume I am not using MSELoss but a custom loss function I wrote myself. Would this still hold?