i want to extract the value of loss for each sample in a training/testing batch. how to get this more efficiently ?
should i use this method below :

call loss function two times

loss_fn = nn.MSELoss( )
loss_all = loss_fn (input, target) 
loss_each =  torch.mean( loss_fn (input, target).detach(),1 ) 
loss_all.backward() # this loss used for backward 
other_computation( loss_each) # not used for backward

thanks very much