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

CVXPY + GPU error #902

Closed
Mahsalo opened this issue Dec 12, 2019 · 17 comments
Closed

CVXPY + GPU error #902

Mahsalo opened this issue Dec 12, 2019 · 17 comments

Comments

@Mahsalo
Copy link

Mahsalo commented Dec 12, 2019

Hi

I'm trying to run a simple optimization problem using CVXPY on GPU (on the cluster) but it gives the following error:

import _scs_gpu
ModuleNotFoundError: No module named '_scs_gpu'

Is there a specific module to import to get rid of this error? I could not find an example of running optimization on GPU using CVXPY online. This is the part of the code in which I have enabled the use of GPU.

X=prob.solve(solver=cp.SCS, gpu= True,use_indirect=True,eps=10(-8),verbose=False)**

Any help would be appreciated.

Thanks

@rileyjmurray
Copy link
Collaborator

Cvxpy itself doesn’t use GPUs. The decision to use a GPU or not depends on the solver. I think SCS is the only cvxpy solver which has possible GPU support. To use that GPU support, you have to compile SCS from source (with an appropriate compiler flag).

Sent with GitHawk

@Mahsalo
Copy link
Author

Mahsalo commented Dec 13, 2019

Cvxpy itself doesn’t use GPUs. The decision to use a GPU or not depends on the solver. I think SCS is the only cvxpy solver which has possible GPU support. To use that GPU support, you have to compile SCS from source (with an appropriate compiler flag).

Sent with GitHawk

Thanks for your response. I have already installed scs (pip install scs) if that's what you mean. I have also tried running the following (according to one of the users):

python3 setup.py install --scs --gpu --int

but it does not recognize --scs option. I don't know how to compile SCS from the source. Any hints?

@rileyjmurray
Copy link
Collaborator

Back when I used SCS, “pip install scs” did not include GPU support. I had to download SCS source code (from its GitHub repository) and follow GPU-specific setup instructions.

@bodono is seems that this is really an SCS question, rather than a cvxpy question. Do you agree? If so, can you take over this discussion, possibly on the SCS repo?

Sent with GitHawk

@bodono
Copy link
Contributor

bodono commented Dec 18, 2019

Thanks for your response. I have already installed scs (pip install scs) if that's what you mean. I have also tried running the following (according to one of the users):

python3 setup.py install --scs --gpu --int

but it does not recognize --scs option. I don't know how to compile SCS from the source. Any hints?

I just tested that and it works for me. First of all, uninstall scs (pip uninstall scs, you might have to run it a couple of times) and delete any artifacts in the scs directory (rm -rf build scs.egg-info dist). Then two things:

  1. When you run that command, right at the top you should see something like:
=> python3 setup.py install --scs --gpu --int
Namespace(blas64=False, extraverbose=False, float32=False, gpu=True, int32=True, scs=True)

note the gpu=True flag, do you see that?

  1. When you open a python instance try:
import _scs_gpu

what happens?

@theocnrds
Copy link

Hi,
I worked myself through this conversation because I had the same problem. The installation finally worked with cloning the git repo and installing it this way afterwards:

=> python3 setup.py install --scs --gpu --int

Now I want to use it also with cvxpy but a ModuleNotFoundError is raised with python not finding the module '_scs_gpu'.
That part also throws a ModuleNotFoundError:

  1. When you open a python instance try:
import _scs_gpu

what happens?

Do you have another advice how to process this problem?

Thanks

@bodono
Copy link
Contributor

bodono commented Dec 20, 2019

Can you clean out the repo then paste in here what you see when you try to install?

@theocnrds
Copy link

Namespace(blas64=False, extraverbose=False, float32=False, gpu=True, int32=False, scs=True)
running install
running bdist_egg
running egg_info
writing scs.egg-info/PKG-INFO
writing dependency_links to scs.egg-info/dependency_links.txt
writing requirements to scs.egg-info/requires.txt
writing top-level names to scs.egg-info/top_level.txt
blas_mkl_info:
NOT AVAILABLE
blis_info:
NOT AVAILABLE
openblas_info:
libraries = ['openblas', 'openblas']
library_dirs = ['/usr/local/lib']
language = c
define_macros = [('HAVE_CBLAS', None)]
blas_opt_info:
libraries = ['openblas', 'openblas']
library_dirs = ['/usr/local/lib']
language = c
define_macros = [('HAVE_CBLAS', None)]
lapack_mkl_info:
NOT AVAILABLE
openblas_lapack_info:
libraries = ['openblas', 'openblas']
library_dirs = ['/usr/local/lib']
language = c
define_macros = [('HAVE_CBLAS', None)]
lapack_opt_info:
libraries = ['openblas', 'openblas']
library_dirs = ['/usr/local/lib']
language = c
define_macros = [('HAVE_CBLAS', None)]
{'libraries': ['mkl_rt', 'pthread'], 'library_dirs': ['/usr/local/lib'], 'define_macros': [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)], 'include_dirs': ['/usr/local/include', '/usr/include']}
{'libraries': ['mkl_rt', 'pthread'], 'library_dirs': ['/usr/local/lib'], 'define_macros': [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)], 'include_dirs': ['/usr/local/include', '/usr/include']}
scs 2.1.2 is already the active version in easy-install.pth

Installed /usr/local/lib/python3.6/dist-packages/scs-2.1.2-py3.6-linux-x86_64.egg
Processing dependencies for scs==2.1.2
Searching for scipy==1.3.3
Best match: scipy 1.3.3
Adding scipy 1.3.3 to easy-install.pth file

Using /usr/local/lib/python3.6/dist-packages
Searching for numpy==1.17.4
Best match: numpy 1.17.4
Adding numpy 1.17.4 to easy-install.pth file
Installing f2py script to /usr/local/bin
Installing f2py3 script to /usr/local/bin
Installing f2py3.6 script to /usr/local/bin

Using /usr/local/lib/python3.6/dist-packages
Finished processing dependencies for scs==2.1.2

@bodono
Copy link
Contributor

bodono commented Dec 20, 2019

This line:
scs 2.1.2 is already the active version in easy-install.pth
indicates to me that you already have SCS installed. Did you uninstall it first? When I run it on a fresh instance I see
Adding scs 2.1.2 to easy-install.pth file

@theocnrds
Copy link

Yes I uninstalled it before, but only once. Additionally I removed the folder manually and now I get the following:

Namespace(blas64=False, extraverbose=False, float32=False, gpu=True, int32=False, scs=True)
running install
running bdist_egg
running egg_info
creating scs.egg-info
writing scs.egg-info/PKG-INFO
writing dependency_links to scs.egg-info/dependency_links.txt
writing requirements to scs.egg-info/requires.txt
writing top-level names to scs.egg-info/top_level.txt
writing manifest file 'scs.egg-info/SOURCES.txt'
blas_mkl_info:
NOT AVAILABLE
blis_info:
NOT AVAILABLE
openblas_info:
libraries = ['openblas', 'openblas']
library_dirs = ['/usr/local/lib']
language = c
define_macros = [('HAVE_CBLAS', None)]
blas_opt_info:
libraries = ['openblas', 'openblas']
library_dirs = ['/usr/local/lib']
language = c
define_macros = [('HAVE_CBLAS', None)]
lapack_mkl_info:
NOT AVAILABLE
openblas_lapack_info:
libraries = ['openblas', 'openblas']
library_dirs = ['/usr/local/lib']
language = c
define_macros = [('HAVE_CBLAS', None)]
lapack_opt_info:
libraries = ['openblas', 'openblas']
library_dirs = ['/usr/local/lib']
language = c
define_macros = [('HAVE_CBLAS', None)]
{'libraries': ['mkl_rt', 'pthread'], 'library_dirs': ['/usr/local/lib'], 'define_macros': [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)], 'include_dirs': ['/usr/local/include', '/usr/include']}
{'libraries': ['mkl_rt', 'pthread'], 'library_dirs': ['/usr/local/lib'], 'define_macros': [('SCIPY_MKL_H', None), ('HAVE_CBLAS', None)], 'include_dirs': ['/usr/local/include', '/usr/include']}
In file included from /usr/local/lib/python3.6/dist-packages/numpy/core/include/numpy/ndarraytypes.h:1830:0,
from /usr/local/lib/python3.6/dist-packages/numpy/core/include/numpy/ndarrayobject.h:12,
from /usr/local/lib/python3.6/dist-packages/numpy/core/include/numpy/arrayobject.h:4,
from src/scsmodule.c:5:
/usr/local/lib/python3.6/dist-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
#warning "Using deprecated NumPy API, disable it with "
^~~~~~~
scs/src/rw.c: In function ‘scs_read_data’:
scs/src/rw.c:143:3: warning: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Wunused-result]
fread(&(file_int_sz), sizeof(uint32_t), 1, fin);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
MANY TIMES
...
scs/src/rw.c:96:3: warning: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Wunused-result]
fread(A->i, sizeof(scs_int), Anz, fin);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/local/lib/python3.6/dist-packages/numpy/core/include/numpy/ndarraytypes.h:1830:0,
from /usr/local/lib/python3.6/dist-packages/numpy/core/include/numpy/ndarrayobject.h:12,
from /usr/local/lib/python3.6/dist-packages/numpy/core/include/numpy/arrayobject.h:4,
from src/scsmodule.c:5:
/usr/local/lib/python3.6/dist-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
#warning "Using deprecated NumPy API, disable it with "
^~~~~~~
scs/src/rw.c: In function ‘scs_read_data’:
scs/src/rw.c:143:3: warning: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Wunused-result]
fread(&(file_int_sz), sizeof(uint32_t), 1, fin);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
MANY TIMES
...
scs/src/rw.c:96:3: warning: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Wunused-result]
fread(A->i, sizeof(scs_int), Anz, fin);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/local/lib/python3.6/dist-packages/numpy/core/include/numpy/ndarraytypes.h:1830:0,
from /usr/local/lib/python3.6/dist-packages/numpy/core/include/numpy/ndarrayobject.h:12,
from /usr/local/lib/python3.6/dist-packages/numpy/core/include/numpy/arrayobject.h:4,
from src/scsmodule.c:5:
/usr/local/lib/python3.6/dist-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
#warning "Using deprecated NumPy API, disable it with "
^~~~~~~
scs/src/rw.c: In function ‘scs_read_data’:
scs/src/rw.c:143:3: warning: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Wunused-result]
fread(&(file_int_sz), sizeof(uint32_t), 1, fin);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
MANY TIMES
...
scs/src/rw.c:96:3: warning: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Wunused-result]
fread(A->i, sizeof(scs_int), Anz, fin);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/local/lib/python3.6/dist-packages/numpy/core/include/numpy/ndarraytypes.h:1830:0,
from /usr/local/lib/python3.6/dist-packages/numpy/core/include/numpy/ndarrayobject.h:12,
from /usr/local/lib/python3.6/dist-packages/numpy/core/include/numpy/arrayobject.h:4,
from python_linsys/private.c:2:
/usr/local/lib/python3.6/dist-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
#warning "Using deprecated NumPy API, disable it with "
^~~~~~~
In file included from /usr/local/lib/python3.6/dist-packages/numpy/core/include/numpy/ndarraytypes.h:1830:0,
from /usr/local/lib/python3.6/dist-packages/numpy/core/include/numpy/ndarrayobject.h:12,
from /usr/local/lib/python3.6/dist-packages/numpy/core/include/numpy/arrayobject.h:4,
from src/scsmodule.c:5:
/usr/local/lib/python3.6/dist-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2: warning: #warning "Using deprecated NumPy API, disable it with " "#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-Wcpp]
#warning "Using deprecated NumPy API, disable it with "
^~~~~~~
scs/src/rw.c: In function ‘scs_read_data’:
scs/src/rw.c:143:3: warning: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Wunused-result]
fread(&(file_int_sz), sizeof(uint32_t), 1, fin);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
MANY TIMES
...
scs/src/rw.c:96:3: warning: ignoring return value of ‘fread’, declared with attribute warn_unused_result [-Wunused-result]
fread(A->i, sizeof(scs_int), Anz, fin);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Adding scs 2.1.2 to easy-install.pth file

Installed /usr/local/lib/python3.6/dist-packages/scs-2.1.2-py3.6-linux-x86_64.egg
Processing dependencies for scs==2.1.2
Searching for scipy==1.3.3
Best match: scipy 1.3.3
Adding scipy 1.3.3 to easy-install.pth file

Using /usr/local/lib/python3.6/dist-packages
Searching for numpy==1.17.4
Best match: numpy 1.17.4
Adding numpy 1.17.4 to easy-install.pth file
Installing f2py script to /usr/local/bin
Installing f2py3 script to /usr/local/bin
Installing f2py3.6 script to /usr/local/bin

Using /usr/local/lib/python3.6/dist-packages
Finished processing dependencies for scs==2.1.2

But I still get the ModuleNotFoundError when importing _scs_gpu

@bodono
Copy link
Contributor

bodono commented Dec 20, 2019

Ok now what do you get when you ls /usr/local/lib/python3.6/dist-packages/scs-2.1.2-py3.6-linux-x86_64.egg

@theocnrds
Copy link

EGG-INFO
pycache
scs
_scs_direct.cpython-36m-x86_64-linux-gnu.so
_scs_direct.py
_scs_gpu.cpython-36m-x86_64-linux-gnu.so
_scs_gpu.py
_scs_indirect.cpython-36m-x86_64-linux-gnu.so
_scs_indirect.py
_scs_python.cpython-36m-x86_64-linux-gnu.so
_scs_python.py

@bodono
Copy link
Contributor

bodono commented Dec 20, 2019

So it's installed, probably something is wrong with the way your python install is using the paths. You could try adding that directory to the PYTHONPATH.

@theocnrds
Copy link

Okay, after a short search on google I did it that way:

import sys
sys.path.append('/usr/local/lib/python3.6/dist-packages/')

That doesn't change anything. I have to admit that I'm not a pro programmer yet. :'D
Also I'm working on Google Colab, which is a little frustrating.

@SteveDiamond
Copy link
Collaborator

You guys can keep talking, but this is not a cvxpy issue.

@vilsaira
Copy link

vilsaira commented Nov 7, 2021

This is still not a cvxpy issue but as I failed to find conversation/solutions elsewhere in the web despite this being a bit old question, here is my solution to it. Worked in Google Colab and might work in other venvs too with adjustments.

In Colab
!pip install cvxpy
!pip uninstall scs -y
!git clone --recursive https://github.com/bodono/scs-python.git
!cd /content/scs-python && python -m pip install . --install-option="--scs --gpu --int"

Second row uninstalls scs that comes with cvxpy. Third row clones the scs-python to your Colab env and fourth row cds to the cloned directory and runs install. This approach sets PYTHONPATH correctly withing venv thus avoiding the problem in path that comes with using python3 setup.py install --scs --gpu --int.

After that import _scs_gpu worked for me in Colab.

@YiJU-thu
Copy link

YiJU-thu commented Dec 6, 2021

This is still not a cvxpy issue but as I failed to find conversation/solutions elsewhere in the web despite this being a bit old question, here is my solution to it. Worked in Google Colab and might work in other venvs too with adjustments.

In Colab !pip install cvxpy !pip uninstall scs -y !git clone --recursive https://github.com/bodono/scs-python.git !cd /content/scs-python && python -m pip install . --install-option="--scs --gpu --int"

Second row uninstalls scs that comes with cvxpy. Third row clones the scs-python to your Colab env and fourth row cds to the cloned directory and runs install. This approach sets PYTHONPATH correctly withing venv thus avoiding the problem in path that comes with using python3 setup.py install --scs --gpu --int.

After that import _scs_gpu worked for me in Colab.

Hi, I am trying to work on Colab with GPU accelaration for cvxpy. Your reply excites me, but I tried, but not succeed. Do i need anything besides the four lines of commands? After running that I would have "Successfully installed scs-3.0.0", but when I run "import _scs_gpu", it still "ModuleNotFoundError: No module named '_scs_gpu'". Thank you so much!

@SherryC98
Copy link

I tried this:

pip uninstall scs -y
pip install scs

which solved my problem

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

8 participants