As mentionned here 52, it uses the LU factorization. As for the gradient, it is implemented here : https://github.com/pytorch/pytorch/blob/e3e15b5d9534f1c10170e169f1423e9298648e86/tools/autograd/templates/Functions.cpp#L353 82