I am trying to make a hard example mining implementation on PyTorch, here is the problem, this method needs backward part of (not all) loss.  For example, If the batch_size is 10, I only want to backward the losses of 5 example, how can I do that? I have tried codes like
loss[1].backward()
It can run but I am not sure it’s the right way in math.