Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

torch._C._LinAlgError: torch.linalg.lstsq: (Batch element 1): The least squares solution could not be computed because the input matrix does not have full rank (error code: 4). #50

Open
black-yt opened this issue Sep 5, 2024 · 2 comments

Comments

@black-yt
Copy link

black-yt commented Sep 5, 2024

when update grid:

torch._C._LinAlgError: torch.linalg.lstsq: (Batch element 1): The least squares solution could not be computed because the input matrix does not have full rank (error code: 4).

how to solve this problem?
thanks!

@wanide
Copy link

wanide commented Sep 19, 2024

+1

@hoangthangta
Copy link

hoangthangta commented Sep 19, 2024

You can use torch.linalg.matrix_rank(A) to check the matrix's rank. In this case, we need a full-rank matrix. If not, use a regularization, may be:

# Tikhonov regularization 
lambda_value = 1e-3
A_reg = A + lambda_value * torch.eye(A.size(-1))
solution, _ = torch.linalg.lstsq(A_reg, B)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants