I would say that your second equation (e.g.2) is the correct one.
According to the doc (https://pytorch.org/tutorials/beginner/blitz/autograd_tutorial.html#sphx-glr-beginner-blitz-autograd-tutorial-py 4):

To stop a tensor from tracking history, you can call  .detach()  to detach it from the computation history, and to prevent future computation from being tracked.

Hence, your tensor in e.g.1 would be tracked until the softmax while e.g.2 would stop tracking the gradient at logits_u_w