You can quite update pinverse implementation as it is easy to extract rank from svd calls results here https://github.com/pytorch/pytorch/blob/6debc28964872e26724764e213c40db366327f95/aten/src/ATen/native/LinearAlgebra.cpp#L94 4