You are overwriting x_adv in this line of code:
x_adv = x_adv + gradients

which will create a non-leaf tensor and you should get a warning when trying to access it’s .grad attribute:
UserWarning: The .grad attribute of a Tensor that is not a leaf Tensor is being accessed. Its .grad attribute won't be populated during autograd.backward(). If you indeed want the gradient for a non-leaf Tensor, use .retain_grad() on the non-leaf Tensor. If you access the non-leaf Tensor by mistake, make sure you access the leaf Tensor instead. See github.com/pytorch/pytorch/pull/30531 for more informations.

You could either use the suggested .retain_grad() operation or create a new leaf tensor via x_adv = x_adv.detach().requires_grad_(True) at the end of the iteration.