Torch.linalg.svd() backpropagation

Hello,
I have a model that calculates the svd of a matrix in the forward and i’m getting this error in the backward, any idea about how to solve it ?

RuntimeError: svd_backward: The singular vectors in the complex case are specified up to multiplication by e^{i phi}. The specified loss function depends on this phase term, making it ill-defined.

Hi @Am_b_reas,

The gradient of an SVD decomposition isn’t defined with respect to the phase as it’s degenerate, and therefore its gradient is ill-defined.

There’s some more info here: Function ‘LinalgSvdBackward0’ returned nan values in its 0th output

There’s also more info in the docs for SVD in case of ill-defined operations too: torch.linalg.svd — PyTorch 2.3 documentation