@codeflux
Another alternative would be to use
retain_graph=True

# Now compute gradients:
d_loss_dx = grad(outputs=loss, inputs=x, retain_graph=True)
d_loss_dv = grad(outputs=loss, inputs=v, retain_graph=True)
d_loss_dy = grad(outputs=loss, inputs=y)

print(f'dloss/dx:\n {d_loss_dx}')
print(f'dloss/dv:\n {d_loss_dv}')
print(f'dloss/dy:\n {d_loss_dy}')