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

Prevent importing chainer immediately raises an error with cupy>=10 #8616

Merged
merged 3 commits into from
Jan 4, 2022

Conversation

belltailjp
Copy link
Contributor

@belltailjp belltailjp commented Dec 28, 2021

When cupy>=10 is installed, importing chainer immediately raises the following error.

>>> import cupy; cupy.__version__
'10.0.0'
>>> import chainer
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.9/site-packages/chainer/__init__.py", line 10, in <module>
    from chainer import backends  # NOQA
  File "/usr/local/lib/python3.9/site-packages/chainer/backends/__init__.py", line 1, in <module>
    from chainer.backends import cuda  # NOQA
  File "/usr/local/lib/python3.9/site-packages/chainer/backends/cuda.py", line 124, in <module>
    _cupy_major = numpy.lib.NumpyVersion(cupy.__version__).major
  File "/usr/local/lib/python3.9/site-packages/numpy/lib/_version.py", line 59, in __init__
    raise ValueError("Not a valid numpy version string")
ValueError: Not a valid numpy version string

This PR is to fix this issue.
I am quite aware that there is (and should be) absolutely no guarantee that chainer and the latest cupy work fine together. But for those who have to use or maintain codes that still rely on some of chainer functionalities with their own risk, I'd like to prevent the situation where just importing chainer immediately fails.

Copy link
Member

@kmaehashi kmaehashi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

chainer/backends/cuda.py Outdated Show resolved Hide resolved
@kmaehashi
Copy link
Member

Btw, you can also workaround the issue by upgrading to NumPy 1.21 or later.
numpy/numpy#19214

Co-authored-by: Kenichi Maehashi <webmaster@kenichimaehashi.com>
chainer/backends/cuda.py Outdated Show resolved Hide resolved
@kmaehashi
Copy link
Member

/test

@kmaehashi kmaehashi self-assigned this Jan 4, 2022
@kmaehashi kmaehashi merged commit 6018f48 into chainer:master Jan 4, 2022
@kmaehashi
Copy link
Member

Confirmed locally. Thanks!

@kmaehashi kmaehashi added this to the v7.8.1 milestone Jan 4, 2022
@kmaehashi kmaehashi added the cat:enhancement Implementation that does not break interfaces. label Jan 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cat:enhancement Implementation that does not break interfaces.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants