-
Notifications
You must be signed in to change notification settings - Fork 108
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
ImportError on default Colab session - CPU Runtime #548
Comments
Hello, I think this is stupid of Colab as what is the point to install Cupy on a machine without a GPU (it is like putting F1 tires on a small car ;) ). Luckily we have a simple work around: Do:
and
and then everything will work file (see here for more details https://pylops.readthedocs.io/en/latest/gpu.html) |
I agree it seems like a weird environment choice, but I have collaborators who have an HPC environment similar to this, so I think it goes beyond just Colab. I'm not sure what the advantages are, but presumably, there must be some. I worked out the fix of using environment variables, and it makes sense when using The proposed fix I suggested would safeguard against this a little bit more than |
Sorry, my phone showed me just part of your message so I didn't realize you had proposed a solution. For sure, you have identified a problem that we never thought about before, and we should make our code able to run as dependency of other projects in environments like Colab :) Alright, a couple of questions:
|
The error message raised is not very helpful which is one of the reasons it took so long to patch, I assumed it was cupy related and didnt think to check I found the error in colab with the following: import traceback
try:
import pylops
except Exception:
print(traceback.format_exc()) Which outputs: Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/cupy/__init__.py", line 18, in <module>
from cupy import _core # NOQA
File "/usr/local/lib/python3.10/dist-packages/cupy/_core/__init__.py", line 3, in <module>
from cupy._core import core # NOQA
ImportError: libcuda.so.1: cannot open shared object file: No such file or directory
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<ipython-input-3-94acb765c275>", line 4, in <cell line: 3>
import pylops
File "/usr/local/lib/python3.10/dist-packages/pylops/__init__.py", line 49, in <module>
from .linearoperator import *
File "/usr/local/lib/python3.10/dist-packages/pylops/linearoperator.py", line 34, in <module>
from pylops.optimization.basic import cgls
File "/usr/local/lib/python3.10/dist-packages/pylops/optimization/basic.py", line 9, in <module>
from pylops.optimization.cls_basic import CG, CGLS, LSQR
File "/usr/local/lib/python3.10/dist-packages/pylops/optimization/cls_basic.py", line 12, in <module>
from pylops.optimization.basesolver import Solver
File "/usr/local/lib/python3.10/dist-packages/pylops/optimization/basesolver.py", line 8, in <module>
from pylops.optimization.callback import Callbacks
File "/usr/local/lib/python3.10/dist-packages/pylops/optimization/callback.py", line 8, in <module>
from pylops.utils.metrics import mae, mse, psnr, snr
File "/usr/local/lib/python3.10/dist-packages/pylops/utils/__init__.py", line 2, in <module>
from .backend import *
File "/usr/local/lib/python3.10/dist-packages/pylops/utils/backend.py", line 35, in <module>
import cupy as cp
File "/usr/local/lib/python3.10/dist-packages/cupy/__init__.py", line 20, in <module>
raise ImportError(f'''
ImportError:
================================================================
Failed to import CuPy.
If you installed CuPy via wheels (cupy-cudaXXX or cupy-rocm-X-X), make sure that the package matches with the version of CUDA or ROCm installed.
On Linux, you may need to set LD_LIBRARY_PATH environment variable depending on how you installed CUDA/ROCm.
On Windows, try setting CUDA_PATH environment variable.
Check the Installation Guide for details:
https://docs.cupy.dev/en/latest/install.html
Original error:
ImportError: libcuda.so.1: cannot open shared object file: No such file or directory
================================================================
This is where I was thinking of making the edit, as it looks like this is where it propagates the |
Thanks for the tip about I suggest you try to make a PR with your suggested solution (using |
One additional point: reading about
I don't think we should use deprecated methods as sooner than later those will be removed in new versions of import.. maybe |
good catch, I should have typed |
Awesome, I'll start a draft PR with a rough outline for what I envisaged, and you can tag whoever else should look it over, and we can discuss the details there. I haven't PR'd into this repo before, so the first commits might not be up to scratch but will just serve as an initial outline. The contributing docs look detailed, so hopefully, it'll be straightforward to get it up to standard once you're/we're happy with the code functionality |
Importing
pylops
in the default session of Colab with a CPU runtime leads to anImportError
. Colab now hascupy-cuda11x==11.0.0
installed in the default environment. Consequently your test fails to pick up that trying to import cupy will lead to anImportError
This can be solved in colab by adding:
This isn't the most robust and wouldn't help any packages using
pylops
as a dependency.I was going to PR a change along the lines of, but it would be great to get some feedback first
Steps to reproduce:
In a new notebook on google colab, with a new CPU runtime:
The text was updated successfully, but these errors were encountered: