spaCy icon indicating copy to clipboard operation
spaCy copied to clipboard

SpaCy 3.8.2 CUDA extras are not compatible with numpy 2.0

Open CptCaptain opened this issue 1 year ago • 2 comments

We wanted to use GPUs for spacy after recently upgrading to spacy v3.8, but this was impossible due to conflicting requirements. The spacy[cudaXXX] still depend on cupy < 13.0.0, which is incompatible with numpy 2.0. Support for this has been added in cupy 13.2 back in june.

How to reproduce the behaviour

Try to install spacy[cuda12x]==3.8.2.

Details

ERROR: Cannot install spacy and spacy[cuda12x]==3.8.2 because these package versions have conflicting dependencies.

The conflict is caused by:
    spacy 3.8.2 depends on numpy>=1.19.0; python_version >= "3.9"
    spacy[cuda12x] 3.8.2 depends on numpy>=1.19.0; python_version >= "3.9"
    cupy-cuda12x 11.5.0 depends on numpy<1.26 and >=1.20
    thinc 8.3.2 depends on numpy<2.1.0 and >=2.0.0; python_version >= "3.9"
    spacy 3.8.2 depends on numpy>=1.19.0; python_version >= "3.9"
    spacy[cuda12x] 3.8.2 depends on numpy>=1.19.0; python_version >= "3.9"
    cupy-cuda12x 11.5.0 depends on numpy<1.26 and >=1.20
    thinc 8.3.1 depends on numpy<2.1.0 and >=2.0.0; python_version >= "3.9"
    spacy 3.8.2 depends on numpy>=1.19.0; python_version >= "3.9"
    spacy[cuda12x] 3.8.2 depends on numpy>=1.19.0; python_version >= "3.9"
    cupy-cuda12x 11.5.0 depends on numpy<1.26 and >=1.20
    thinc 8.3.0 depends on numpy<2.1.0 and >=2.0.0; python_version >= "3.9"

Your Environment

  • Operating System: Ubuntu
  • Python Version Used: 3.10
  • spaCy Version Used: 3.8.2 (failed to install)
  • Environment Information:

CptCaptain avatar Oct 30 '24 14:10 CptCaptain

see also https://github.com/explosion/spaCy/issues/13669

lsmith77 avatar Nov 06 '24 08:11 lsmith77

This is a common compatibility issue due to version conflicts between spaCy, CuPy, and NumPy. Here are a few approaches you could try to resolve the issue:

  1. Downgrade NumPy Temporarily

    • You could try installing an earlier version of NumPy (below 2.0) that is compatible with CuPy < 13.0.0. For example:

pip install numpy<2.0

•	Then, install spaCy with the compatible CUDA version:

pip install "spacy[cuda113]" # Replace 113 with the correct version for your CUDA toolkit

•	Note: This may not be sustainable in the long term, especially if you need NumPy 2.0 for other dependencies. This is a temporary workaround until spaCy adds support for CuPy >= 13.2.
  1. Use CuPy 13.2+ Independently of spaCy

    • Install CuPy 13.2 or later directly, bypassing the version constraint by not using spacy[cudaXXX]:

pip install cupy-cuda113 # Replace 113 with your CUDA version pip install spacy

•	Then, configure spaCy manually to use the installed CuPy version.

import spacy spacy.require_gpu()

•	This way, spaCy uses the existing CuPy installation without enforcing its specific version requirements.
  1. Use a Conda Environment

    • Conda has more flexibility in handling dependencies and might offer versions that work well together:

conda create -n spacy-gpu-env python=3.10 conda activate spacy-gpu-env conda install -c conda-forge spacy cupy numpy=1.24

•	Check compatibility as you go. After setting up the environment, test spaCy with require_gpu() as shown above.
  1. Monitor for Updates and SpaCy Compatibility Patches

    • Since support for NumPy 2.0 in CuPy 13.2 was added recently, spaCy may soon include support for CuPy >= 13.2 in future releases. It could be beneficial to keep an eye on upcoming spaCy releases or GitHub issues related to GPU support, as they may incorporate fixes for this conflict.

One of these workarounds should help you proceed with GPU support on spaCy. Let me know if you need further guidance on any of these steps!

Niket420 avatar Nov 09 '24 05:11 Niket420

Current versions of spaCy now support a wider numpy compatibility range, which should resolve this.

honnibal avatar Nov 04 '25 14:11 honnibal