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

AttributeError: module 'torch.linalg' has no attribute 'lu_factor' #2

Open
yufei0726 opened this issue Nov 6, 2024 · 6 comments
Open

Comments

@yufei0726
Copy link

I encountered this problem when calling QPfunction, but I printed and saw that the eigenvalues ​​of the Q matrix were all positive and there were no diagonal zero elements. I hope someone can answer this question.

Traceback (most recent call last):
File "C:\ProgramData\anaconda3\envs\dQP\lib\site-packages\qpth\solvers\pdipm\batch.py", line 380, in pre_factor_kkt
Q_LU = lu_hack(Q)
File "C:\ProgramData\anaconda3\envs\dQP\lib\site-packages\qpth\solvers\pdipm\batch.py", line 9, in lu_hack
data, pivots = torch.linalg.lu_factor(x, pivot=not x.is_cuda)
AttributeError: module 'torch.linalg' has no attribute 'lu_factor'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "runcarsim1.py", line 114, in
sys.exit(main())
File "runcarsim1.py", line 55, in main
control = controller(traj_ref, current_state)
File "C:\ProgramData\anaconda3\envs\dQP\lib\site-packages\torch\nn\modules\module.py", line 1102, in _call_impl
return forward_call(*input, **kwargs)
File "D:\syf\differentiable-control\QPnet.py", line 44, in forward
x = self.dQP(traj_ref, current_state)
File "D:\syf\differentiable-control\QPnet.py", line 231, in dQP
deltU = QPFunction(verbose = 0)(Q_obj.double(), P_obj.double(), G.double(), h.double(), e, e)
File "C:\ProgramData\anaconda3\envs\dQP\lib\site-packages\qpth\qp.py", line 93, in forward
ctx.Q_LU, ctx.S_LU, ctx.R = pdipm_b.pre_factor_kkt(Q, G, A)
File "C:\ProgramData\anaconda3\envs\dQP\lib\site-packages\qpth\solvers\pdipm\batch.py", line 382, in pre_factor_kkt
raise RuntimeError("""
RuntimeError:
qpth Error: Cannot perform LU factorization on Q.
Please make sure that your Q matrix is PSD and has
a non-zero diagonal.

@Weixy21
Copy link
Owner

Weixy21 commented Nov 6, 2024

This may be the problem of a new version Pytorch. You may try older version of Pytorch (e.g., '1.10.1+cu113', I received a similar warning for this problem that this will be unavailable in the future version).

@yufei0726
Copy link
Author

I think I solved this problem. I checked the pytorch documentation and found that the functions with problems are only available in pytorch versions after 1.13. So I installed pytorch 1.13.1+cu116 and the corresponding torchvision and torchaudio to solve the problem. I hope my solution can help others. Thank you very much for your reply!

@yufei0726
Copy link
Author

But I often get an error that my Q matrix is ​​not semi-positive definite. I don't know if there is any experience to deal with this situation.

@Weixy21
Copy link
Owner

Weixy21 commented Nov 7, 2024

Q is usually defined as an identity matrix. If there is such an issue with an identity Q, then it might also be the pytorch version problem. '1.10.1+cu113' has no such a problem.

@yufei0726
Copy link
Author

I construct the optimization as a path tracking problem. The Q matrix is ​​currently derived from the dynamic parameters and the artificially set weight matrix.

@Weixy21
Copy link
Owner

Weixy21 commented Nov 7, 2024

Then you need to ensure that the artificially set weight matrix should always make Q positive definite, e.g., with non-negative diagonal items for diagonal Q.

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

2 participants