spaCy icon indicating copy to clipboard operation
spaCy copied to clipboard

Error when GPU initialization and model loading are in different notebook cells

Open bitmman opened this issue 5 years ago • 38 comments

How to reproduce the behaviour

Installed the latest version following the instruction

pip install -U pip setuptools wheel
pip install -U spacy[cuda110]
python -m spacy download en_core_web_trf

The installation was successful, and gpu is available:

import spacy
from thinc.api import set_gpu_allocator, require_gpu
import spacy_transformers
print(spacy.prefer_gpu(),require_gpu(0))
True True

However, Error: "a bytes-like object is required, not 'cupy.core.core.ndarray'" happened, when using "en_core_web_trf".

nlp = spacy.load("en_core_web_trf")
sent = 'Hello World'
doc = nlp(sent)
TypeError                                 Traceback (most recent call last)
<ipython-input-12-66e94dc9d1fd> in <module>
      1 sent = 'Hello World'
----> 2 doc = nlp(sent)


~/anaconda3/envs/acl/lib/python3.8/site-packages/spacy/language.py in __call__(self, text, disable, component_cfg)
    992                 raise ValueError(Errors.E109.format(name=name)) from e
    993             except Exception as e:
--> 994                 error_handler(name, proc, [doc], e)
    995             if doc is None:
    996                 raise ValueError(Errors.E005.format(name=name))

~/anaconda3/envs/acl/lib/python3.8/site-packages/spacy/util.py in raise_error(proc_name, proc, docs, e)
   1493 
   1494 def raise_error(proc_name, proc, docs, e):
-> 1495     raise e
   1496 
   1497 

~/anaconda3/envs/acl/lib/python3.8/site-packages/spacy/language.py in __call__(self, text, disable, component_cfg)
    987                 error_handler = proc.get_error_handler()
    988             try:
--> 989                 doc = proc(doc, **component_cfg.get(name, {}))
    990             except KeyError as e:
    991                 # This typically happens if a component is not initialized

~/anaconda3/envs/acl/lib/python3.8/site-packages/spacy/pipeline/trainable_pipe.pyx in spacy.pipeline.trainable_pipe.TrainablePipe.__call__()

~/anaconda3/envs/acl/lib/python3.8/site-packages/spacy/util.py in raise_error(proc_name, proc, docs, e)
   1493 
   1494 def raise_error(proc_name, proc, docs, e):
-> 1495     raise e
   1496 
   1497 

~/anaconda3/envs/acl/lib/python3.8/site-packages/spacy/pipeline/trainable_pipe.pyx in spacy.pipeline.trainable_pipe.TrainablePipe.__call__()

~/anaconda3/envs/acl/lib/python3.8/site-packages/spacy/pipeline/tagger.pyx in spacy.pipeline.tagger.Tagger.predict()

~/anaconda3/envs/acl/lib/python3.8/site-packages/thinc/model.py in predict(self, X)
    310         only the output, instead of the `(output, callback)` tuple.
    311         """
--> 312         return self._func(self, X, is_train=False)[0]
    313 
    314     def finish_update(self, optimizer: Optimizer) -> None:

~/anaconda3/envs/acl/lib/python3.8/site-packages/thinc/layers/chain.py in forward(model, X, is_train)
     52     callbacks = []
     53     for layer in model.layers:
---> 54         Y, inc_layer_grad = layer(X, is_train=is_train)
     55         callbacks.append(inc_layer_grad)
     56         X = Y

~/anaconda3/envs/acl/lib/python3.8/site-packages/thinc/model.py in __call__(self, X, is_train)
    286         """Call the model's `forward` function, returning the output and a
    287         callback to compute the gradients via backpropagation."""
--> 288         return self._func(self, X, is_train=is_train)
    289 
    290     def initialize(self, X: Optional[InT] = None, Y: Optional[OutT] = None) -> "Model":

~/anaconda3/envs/acl/lib/python3.8/site-packages/thinc/layers/chain.py in forward(model, X, is_train)
     52     callbacks = []
     53     for layer in model.layers:
---> 54         Y, inc_layer_grad = layer(X, is_train=is_train)
     55         callbacks.append(inc_layer_grad)
     56         X = Y

~/anaconda3/envs/acl/lib/python3.8/site-packages/thinc/model.py in __call__(self, X, is_train)
    286         """Call the model's `forward` function, returning the output and a
    287         callback to compute the gradients via backpropagation."""
--> 288         return self._func(self, X, is_train=is_train)
    289 
    290     def initialize(self, X: Optional[InT] = None, Y: Optional[OutT] = None) -> "Model":

~/anaconda3/envs/acl/lib/python3.8/site-packages/spacy_transformers/layers/trfs2arrays.py in forward(model, trf_datas, is_train)
     26             src = model.ops.reshape2f(trf_data.tensors[t_i], -1, trf_data.width)
     27             dst, get_d_src = apply_alignment(model.ops, trf_data.align, src)
---> 28             output, get_d_dst = pooling(dst, is_train)
     29             outputs.append(output)
     30             backprops.append((get_d_dst, get_d_src))

~/anaconda3/envs/acl/lib/python3.8/site-packages/thinc/model.py in __call__(self, X, is_train)
    286         """Call the model's `forward` function, returning the output and a
    287         callback to compute the gradients via backpropagation."""
--> 288         return self._func(self, X, is_train=is_train)
    289 
    290     def initialize(self, X: Optional[InT] = None, Y: Optional[OutT] = None) -> "Model":

~/anaconda3/envs/acl/lib/python3.8/site-packages/thinc/layers/reduce_mean.py in forward(model, Xr, is_train)
     16 
     17 def forward(model: Model[InT, OutT], Xr: InT, is_train: bool) -> Tuple[OutT, Callable]:
---> 18     Y = model.ops.reduce_mean(cast(Floats2d, Xr.data), Xr.lengths)
     19     lengths = Xr.lengths
     20 

~/anaconda3/envs/acl/lib/python3.8/site-packages/thinc/backends/numpy_ops.pyx in thinc.backends.numpy_ops.NumpyOps.reduce_mean()

~/anaconda3/envs/acl/lib/python3.8/site-packages/thinc/backends/numpy_ops.cpython-38-x86_64-linux-gnu.so in View.MemoryView.memoryview_cwrapper()

~/anaconda3/envs/acl/lib/python3.8/site-packages/thinc/backends/numpy_ops.cpython-38-x86_64-linux-gnu.so in View.MemoryView.memoryview.__cinit__()

TypeError: a bytes-like object is required, not 'cupy.core.core.ndarray'

When I try en_core_web_sm (3.0.0) and en_core_web_lg (3.0.0), there is no problem at all.

Your Environment

Info about spaCy

  • spaCy version: 3.0.1
  • Platform: Linux-4.19.128-microsoft-standard-x86_64-with-glibc2.10
  • Python version: 3.8.5
  • Pipelines: en_core_web_trf (3.0.0), en_core_web_sm (3.0.0), en_core_web_lg (3.0.0)
  • Operating System: Win10, WSL2
  • Python Version Used: Python 3.8.5
  • spaCy Version Used: 3.0.1
  • Environment Information: Virtual Environment

bitmman avatar Feb 09 '21 10:02 bitmman

Hi, can you check that you also have the latest version of spacy-transformers (pip install -U spacy-transformers)?

adrianeboyd avatar Feb 09 '21 15:02 adrianeboyd

Hi, can you check that you also have the latest version of spacy-transformers (pip install -U spacy-transformers)?

Yes, I do have the latest version of 'spacy-transformers'. I did pip install -U spacy-transformers and the same errors returned.

Thanks.

bitmman avatar Feb 09 '21 17:02 bitmman

Hmm, I'm not really sure what's going on. We saw a similar error recently was when spacy.require_gpu() was called after the model was loaded. Can you double-check that you are running require_gpu() before loading the model? Especially if things might have been executed out-of-order in a notebook, maybe this is a possible source of the error?

If that doesn't help, this is a bit frustrating as a suggestion, but my next suggestion would be to try again in a new venv because pip doesn't always clean up older files when upgrading packages, and it's possible something wasn't upgraded cleanly.

adrianeboyd avatar Feb 09 '21 19:02 adrianeboyd

I'm getting this same error on Windows 10 when trying pass a sentence for a self-trained Transformer and NER pipeline for Finnish. This is happening on a fresh Conda environment (Python 3.8.5) with the latest versions. Errors relating to CuPy have appeared erratically for me. On another environment, I was unable run training on GPU, but that seems to function on this fresh installation. The error described above persists, however. I also made sure to call require_gpu() before loading the model.

Tadusko avatar Feb 09 '21 22:02 Tadusko

Hmm, I'm not really sure what's going on. We saw a similar error recently was when spacy.require_gpu() was called after the model was loaded. Can you double-check that you are running require_gpu() before loading the model? Especially if things might have been executed out-of-order in a notebook, maybe this is a possible source of the error?

If that doesn't help, this is a bit frustrating as a suggestion, but my next suggestion would be to try again in a new venv because pip doesn't always clean up older files when upgrading packages, and it's possible something wasn't upgraded cleanly.

Hi, I double-checked my code and I'm sure that the require_gpu() was before loading the model. I also started a new conda virtual environment and reinstalled spacy v3 following the instruction: pip install -U pip setuptools wheel pip install -U spacy[cuda110] python -m spacy download en_core_web_trf

and I got the same error.

However, I noticed the following:

  1. If I don't use spacy.prefer_gpu() or require_gpu(0), there is no problem with doc = nlp(sent); It means that we are no problem with running spacy-transformer using cpu, right?
  2. If I use spacy.prefer_gpu() or require_gpu(0) and load the "en_core_web_sm" or "en_core_web_lg" models instead of "en_core_web_trf", there is no problem as well. So there is no problem with "en_core_web_sm" or "en_core_web_lg" using gpu, but "en_core_web_trf".
  3. So, I'm wondering if the latest version of Spacy compatible with cuda-11 or not?

I appreciate your help.

bitmman avatar Feb 10 '21 04:02 bitmman

I can't test any of this locally so this is a bit tedious, sorry. CUDA 11.0 support shouldn't be the issue. If en_core_web_lg is working fine with GPU, then spacy and cupy are probably fine. Someone else is reporting the same error in #6971 with a conda install of torch (the next thing I was going to suggest), so I am not sure what's going on and I can't replicate this with a very similar setup with conda in linux, so it's hard to debug.

What is the output of conda list?

Is it possible for you try this in a pip-only venv?

adrianeboyd avatar Feb 10 '21 09:02 adrianeboyd

Hi all. As @adrianeboyd mentioned, I've posted the same problem in #6971. To keep the discussion in one thread, I'll post things here.

In my setup, I've used both conda install and pip install inside a conda environment. So I've tried using pip-only venv as suggested, but the same error still shows up.

ilijaplusx avatar Feb 10 '21 13:02 ilijaplusx

@ilijaplusx: Is it windows or linux?

adrianeboyd avatar Feb 10 '21 13:02 adrianeboyd

Amazon Linux 2, based on RHEL

ilijaplusx avatar Feb 10 '21 13:02 ilijaplusx

What does conda list show?

adrianeboyd avatar Feb 10 '21 14:02 adrianeboyd

conda list in conda env (python 3.8.6):

_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                      1_llvm    conda-forge
aiohttp                   3.7.3            py38h497a2fe_1    conda-forge
async-timeout             3.0.1                   py_1000    conda-forge
attrs                     20.3.0             pyhd3deb0d_0    conda-forge
backcall                  0.2.0              pyh9f0ad1d_0    conda-forge
backports                 1.0                        py_2    conda-forge
backports.functools_lru_cache 1.6.1                      py_0    conda-forge
blas                      1.0                         mkl
boto                      2.49.0                     py_0    conda-forge
boto3                     1.17.3             pyhd8ed1ab_0    conda-forge
botocore                  1.20.3             pyhd8ed1ab_0    conda-forge
brotlipy                  0.7.0           py38h497a2fe_1001    conda-forge
bz2file                   0.98                       py_0    conda-forge
c-ares                    1.17.1               h36c2ea0_0    conda-forge
ca-certificates           2020.12.5            ha878542_0    conda-forge
cachetools                4.2.1              pyhd8ed1ab_0    conda-forge
catalogue                 2.0.1            py38h578d9bd_2    conda-forge
certifi                   2020.12.5        py38h578d9bd_1    conda-forge
cffi                      1.14.4           py38ha65f79e_1    conda-forge
chardet                   3.0.4           py38h924ce5b_1008    conda-forge
click                     7.1.2              pyh9f0ad1d_0    conda-forge
colorama                  0.4.4              pyh9f0ad1d_0    conda-forge
cryptography              3.3.1            py38h2b97feb_1    conda-forge
cudatoolkit               11.0.3               h15472ef_7    conda-forge
cupy-cuda110              8.4.0                    pypi_0    pypi
cymem                     2.0.5            py38h709712a_1    conda-forge
cython-blis               0.7.4            py38h5c078b8_0    conda-forge
dataclasses               0.7                pyhb2cacf7_7    conda-forge
decorator                 4.4.2                      py_0    conda-forge
en-core-web-trf           3.0.0                    pypi_0    pypi
fastrlock                 0.5                      pypi_0    pypi
filelock                  3.0.12                   pypi_0    pypi
freetype                  2.10.4               h0708190_1    conda-forge
ftfy                      5.8                      pypi_0    pypi
google-api-core           1.25.1             pyh44b312d_0    conda-forge
google-auth               1.24.0             pyhd3deb0d_0    conda-forge
google-cloud-core         1.5.0              pyhd3deb0d_0    conda-forge
google-cloud-storage      1.19.0                     py_0    conda-forge
google-crc32c             1.1.2            py38h8838a9a_0    conda-forge
google-resumable-media    1.2.0              pyhd3deb0d_0    conda-forge
googleapis-common-protos  1.52.0           py38h578d9bd_1    conda-forge
grpcio                    1.35.0           py38hdd6454d_0    conda-forge
idna                      2.10               pyh9f0ad1d_0    conda-forge
ipykernel                 5.4.3            py38h81c977d_0    conda-forge
ipython                   7.20.0           py38h81c977d_2    conda-forge
ipython_genutils          0.2.0                      py_1    conda-forge
jedi                      0.18.0           py38h578d9bd_2    conda-forge
jinja2                    2.11.3             pyh44b312d_0    conda-forge
jmespath                  0.10.0             pyh9f0ad1d_0    conda-forge
joblib                    1.0.0                    pypi_0    pypi
jpeg                      9b                   h024ee3a_2
jupyter_client            6.1.11             pyhd8ed1ab_1    conda-forge
jupyter_core              4.7.1            py38h578d9bd_0    conda-forge
lcms2                     2.11                 h396b838_0
ld_impl_linux-64          2.35.1               hea4e1c9_2    conda-forge
libcrc32c                 1.1.1                h9c3ff4c_2    conda-forge
libffi                    3.3                  h58526e2_2    conda-forge
libgcc-ng                 9.3.0               h2828fa1_18    conda-forge
libpng                    1.6.37               h21135ba_2    conda-forge
libprotobuf               3.14.0               h780b84a_0    conda-forge
libsodium                 1.0.18               h36c2ea0_1    conda-forge
libstdcxx-ng              9.3.0               h6de172a_18    conda-forge
libtiff                   4.1.0                h2733197_1
libuv                     1.40.0               h7f98852_0    conda-forge
llvm-openmp               11.0.1               h4bd325d_0    conda-forge
lz4-c                     1.9.3                h9c3ff4c_0    conda-forge
markupsafe                1.1.1            py38h497a2fe_3    conda-forge
mkl                       2020.4             h726a3e6_304    conda-forge
mkl-service               2.3.0            py38h1e0a361_2    conda-forge
mkl_fft                   1.2.0            py38hab2c0dc_1    conda-forge
mkl_random                1.2.0            py38hc5bc63f_1    conda-forge
multidict                 5.1.0            py38h497a2fe_1    conda-forge
murmurhash                1.0.5            py38h709712a_0    conda-forge
ncurses                   6.2                  h58526e2_4    conda-forge
ninja                     1.10.2               h4bd325d_0    conda-forge
numpy                     1.19.2           py38h54aff64_0
numpy-base                1.19.2           py38hfa32c7d_0
olefile                   0.46               pyh9f0ad1d_1    conda-forge
openssl                   1.1.1i               h7f98852_0    conda-forge
packaging                 20.9               pyh44b312d_0    conda-forge
parso                     0.8.1              pyhd8ed1ab_0    conda-forge
pathy                     0.3.5              pyhd8ed1ab_0    conda-forge
pexpect                   4.8.0              pyh9f0ad1d_2    conda-forge
pickleshare               0.7.5                   py_1003    conda-forge
pillow                    8.1.0            py38he98fc37_0
pip                       21.0.1             pyhd8ed1ab_0    conda-forge
preshed                   3.0.5            py38h709712a_0    conda-forge
prompt-toolkit            3.0.14             pyha770c72_0    conda-forge
protobuf                  3.14.0           py38h709712a_1    conda-forge
ptyprocess                0.7.0              pyhd3deb0d_0    conda-forge
pyasn1                    0.4.8                      py_0    conda-forge
pyasn1-modules            0.2.7                      py_0    conda-forge
pycparser                 2.20               pyh9f0ad1d_2    conda-forge
pydantic                  1.7.3            py38h497a2fe_0    conda-forge
pygments                  2.7.4              pyhd8ed1ab_0    conda-forge
pyopenssl                 20.0.1             pyhd8ed1ab_0    conda-forge
pyparsing                 2.4.7              pyh9f0ad1d_0    conda-forge
pysocks                   1.7.1            py38h578d9bd_3    conda-forge
python                    3.8.6           hffdb5ce_5_cpython    conda-forge
python-dateutil           2.8.1                      py_0    conda-forge
python_abi                3.8                      1_cp38    conda-forge
pytorch                   1.7.1           py3.8_cuda11.0.221_cudnn8.0.5_0    pytorch
pytz                      2021.1             pyhd8ed1ab_0    conda-forge
pyzmq                     20.0.0           py38h3d7ac18_1    conda-forge
readline                  8.0                  he28a2e2_2    conda-forge
regex                     2020.11.13               pypi_0    pypi
requests                  2.25.1             pyhd3deb0d_0    conda-forge
rsa                       4.7                pyhd3deb0d_0    conda-forge
s3transfer                0.3.4              pyhd8ed1ab_0    conda-forge
sacremoses                0.0.43                   pypi_0    pypi
setuptools                49.6.0           py38h578d9bd_3    conda-forge
shellingham               1.4.0              pyh44b312d_0    conda-forge
six                       1.15.0             pyh9f0ad1d_0    conda-forge
smart_open                2.2.1              pyh9f0ad1d_0    conda-forge
spacy                     3.0.1            py38hc10631b_1    conda-forge
spacy-alignments          0.7.2                    pypi_0    pypi
spacy-legacy              3.0.1              pyhd8ed1ab_0    conda-forge
spacy-transformers        1.0.1                    pypi_0    pypi
sqlite                    3.34.0               h74cdb3f_0    conda-forge
srsly                     2.4.0            py38h709712a_2    conda-forge
thinc                     8.0.1            py38hc10631b_1    conda-forge
tk                        8.6.10               h21135ba_1    conda-forge
tokenizers                0.9.4                    pypi_0    pypi
torchaudio                0.7.2                      py38    pytorch
torchcontrib              0.0.2                    pypi_0    pypi
torchvision               0.8.2                py38_cu110    pytorch
tornado                   6.1              py38h497a2fe_1    conda-forge
tqdm                      4.56.0             pyhd8ed1ab_0    conda-forge
traitlets                 5.0.5                      py_0    conda-forge
transformers              4.2.2                    pypi_0    pypi
typer                     0.3.2              pyhd8ed1ab_0    conda-forge
typing-extensions         3.7.4.3                       0    conda-forge
typing_extensions         3.7.4.3                    py_0    conda-forge
urllib3                   1.26.3             pyhd8ed1ab_0    conda-forge
wasabi                    0.8.2              pyh44b312d_0    conda-forge
wcwidth                   0.2.5              pyh9f0ad1d_2    conda-forge
wheel                     0.36.2             pyhd3deb0d_0    conda-forge
xz                        5.2.5                h516909a_1    conda-forge
yarl                      1.6.3            py38h497a2fe_1    conda-forge
zeromq                    4.3.4                h9c3ff4c_0    conda-forge
zlib                      1.2.11            h516909a_1010    conda-forge
zstd                      1.4.8                ha95c52a_1    conda-forge

pip freeze in venv (python 3.7.6):

anyio==2.1.0
argon2-cffi==20.1.0
async-generator==1.10
attrs==20.3.0
Babel==2.9.0
backcall==0.2.0
bleach==3.3.0
blis==0.7.4
catalogue==2.0.1
certifi==2020.12.5
cffi==1.14.4
chardet==4.0.0
click==7.1.2
cupy-cuda110==8.4.0
cymem==2.0.5
Cython==0.29.21
decorator==4.4.2
defusedxml==0.6.0
en-core-web-sm @ https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.0.0/en_core_web_sm-3.0.0-py3-none-any.whl
en-core-web-trf @ https://github.com/explosion/spacy-models/releases/download/en_core_web_trf-3.0.0/en_core_web_trf-3.0.0-py3-none-any.whl
entrypoints==0.3
fastrlock==0.5
filelock==3.0.12
ftfy==5.8
idna==2.10
importlib-metadata==3.4.0
ipykernel==5.4.3
ipython==7.20.0
ipython-genutils==0.2.0
jedi==0.18.0
Jinja2==2.11.3
joblib==1.0.1
json5==0.9.5
jsonschema==3.2.0
jupyter-client==6.1.11
jupyter-core==4.7.1
jupyter-server==1.3.0
jupyterlab==3.0.7
jupyterlab-pygments==0.1.2
jupyterlab-server==2.2.0
MarkupSafe==1.1.1
mistune==0.8.4
murmurhash==1.0.5
nbclassic==0.2.6
nbclient==0.5.2
nbconvert==6.0.7
nbformat==5.1.2
nest-asyncio==1.5.1
notebook==6.2.0
numpy==1.20.1
packaging==20.9
pandocfilters==1.4.3
parso==0.8.1
pathy==0.3.5
pexpect==4.8.0
pickleshare==0.7.5
Pillow==8.1.0
preshed==3.0.5
prometheus-client==0.9.0
prompt-toolkit==3.0.14
ptyprocess==0.7.0
pycparser==2.20
pydantic==1.7.3
Pygments==2.7.4
pyparsing==2.4.7
pyrsistent==0.17.3
python-dateutil==2.8.1
pytz==2021.1
pyzmq==22.0.2
regex==2020.11.13
requests==2.25.1
sacremoses==0.0.43
Send2Trash==1.5.0
six==1.15.0
smart-open==3.0.0
sniffio==1.2.0
spacy==3.0.1
spacy-alignments==0.7.2
spacy-legacy==3.0.1
spacy-transformers==1.0.1
srsly==2.4.0
terminado==0.9.2
testpath==0.4.4
thinc==8.0.1
tokenizers==0.9.4
torch==1.7.1+cu110
torchaudio==0.7.2
torchcontrib==0.0.2
torchvision==0.8.2+cu110
tornado==6.1
tqdm==4.56.1
traitlets==5.0.5
transformers==4.2.2
typer==0.3.2
typing-extensions==3.7.4.3
urllib3==1.26.3
wasabi==0.8.2
wcwidth==0.2.5
webencodings==0.5.1
zipp==3.4.0

ilijaplusx avatar Feb 10 '21 16:02 ilijaplusx

The same issue, we are running spacy with CUDA 10.1 and pytorch 1.6. We tested our build pipeline with CPU only, when GPU was enabled, we got exceptions. We can provide all the info about our docker containers and libs used since we build them from the ground up. Here is part of the exception:

/opt/conda/lib/python3.8/site-packages/spacy/pipeline/trainable_pipe.pyx in spacy.pipeline.trainable_pipe.TrainablePipe.__call__()

/opt/conda/lib/python3.8/site-packages/spacy/pipeline/tagger.pyx in spacy.pipeline.tagger.Tagger.predict()

/opt/conda/lib/python3.8/site-packages/thinc/model.py in predict(self, X)
    310         only the output, instead of the `(output, callback)` tuple.
    311         """
--> 312         return self._func(self, X, is_train=False)[0]
    313 
    314     def finish_update(self, optimizer: Optimizer) -> None:

/opt/conda/lib/python3.8/site-packages/thinc/layers/chain.py in forward(model, X, is_train)
     52     callbacks = []
     53     for layer in model.layers:
---> 54         Y, inc_layer_grad = layer(X, is_train=is_train)
     55         callbacks.append(inc_layer_grad)
     56         X = Y

/opt/conda/lib/python3.8/site-packages/thinc/model.py in __call__(self, X, is_train)
    286         """Call the model's `forward` function, returning the output and a
    287         callback to compute the gradients via backpropagation."""
--> 288         return self._func(self, X, is_train=is_train)
    289 
    290     def initialize(self, X: Optional[InT] = None, Y: Optional[OutT] = None) -> "Model":

/opt/conda/lib/python3.8/site-packages/thinc/layers/chain.py in forward(model, X, is_train)
     52     callbacks = []
     53     for layer in model.layers:
---> 54         Y, inc_layer_grad = layer(X, is_train=is_train)
     55         callbacks.append(inc_layer_grad)
     56         X = Y

/opt/conda/lib/python3.8/site-packages/thinc/model.py in __call__(self, X, is_train)
    286         """Call the model's `forward` function, returning the output and a
    287         callback to compute the gradients via backpropagation."""
--> 288         return self._func(self, X, is_train=is_train)
    289 
    290     def initialize(self, X: Optional[InT] = None, Y: Optional[OutT] = None) -> "Model":

/opt/conda/lib/python3.8/site-packages/spacy_transformers/layers/trfs2arrays.py in forward(model, trf_datas, is_train)
     26             src = model.ops.reshape2f(trf_data.tensors[t_i], -1, trf_data.width)
     27             dst, get_d_src = apply_alignment(model.ops, trf_data.align, src)
---> 28             output, get_d_dst = pooling(dst, is_train)
     29             outputs.append(output)
     30             backprops.append((get_d_dst, get_d_src))

/opt/conda/lib/python3.8/site-packages/thinc/model.py in __call__(self, X, is_train)
    286         """Call the model's `forward` function, returning the output and a
    287         callback to compute the gradients via backpropagation."""
--> 288         return self._func(self, X, is_train=is_train)
    289 
    290     def initialize(self, X: Optional[InT] = None, Y: Optional[OutT] = None) -> "Model":

/opt/conda/lib/python3.8/site-packages/thinc/layers/reduce_mean.py in forward(model, Xr, is_train)
     16 
     17 def forward(model: Model[InT, OutT], Xr: InT, is_train: bool) -> Tuple[OutT, Callable]:
---> 18     Y = model.ops.reduce_mean(cast(Floats2d, Xr.data), Xr.lengths)
     19     lengths = Xr.lengths
     20 

/opt/conda/lib/python3.8/site-packages/thinc/backends/numpy_ops.pyx in thinc.backends.numpy_ops.NumpyOps.reduce_mean()

/opt/conda/lib/python3.8/site-packages/thinc/backends/numpy_ops.cpython-38-x86_64-linux-gnu.so in View.MemoryView.memoryview_cwrapper()

/opt/conda/lib/python3.8/site-packages/thinc/backends/numpy_ops.cpython-38-x86_64-linux-gnu.so in View.MemoryView.memoryview.__cinit__()

TypeError: a bytes-like object is required, not 'cupy.core.core.ndarray'

patrykattc avatar Feb 10 '21 16:02 patrykattc

Any information like docker configs that would help us reproduce this locally would be appreciated!

adrianeboyd avatar Feb 10 '21 18:02 adrianeboyd

We build a hierarchy of docker containers for different use cases. I can share some snippets from the GPU container.

Base container -> nvidia/cuda:10.1-cudnn7-devel-ubuntu18.04

#CUDA driver 10.1.243
#CUDNN driver 7.6.5.32

SHELL ["/bin/bash", "-c"]
RUN apt-get update && \
    apt-get install -y --no-install-recommends --allow-downgrades --allow-change-held-packages \
    build-essential \
    cuda-command-line-tools-10-1=10.1.243-1 \
    libcublas10 \
    cuda-cufft-10-1=10.1.243-1 \
    cuda-curand-10-1=10.1.243-1 \
    cuda-cusolver-10-1=10.1.243-1 \
    cuda-cusparse-10-1=10.1.243-1 \
    curl \
    libcudnn7=7.6.4.38-1+cuda10.1 \
    libfreetype6-dev \
    libhdf5-serial-dev \
    libzmq3-dev \
    pkg-config \
    software-properties-common \
    unzip \
    && apt-get clean && rm -rf /var/lib/apt/lists/*

RUN apt-get update && \
    apt-get install -y --no-install-recommends libnvinfer6=6.0.1-1+cuda10.1 \
    libnvinfer-plugin6=6.0.1-1+cuda10.1 \
    && apt-get clean \
    && rm -rf /var/lib/apt/lists/*;

# For CUDA profiling, TensorFlow requires CUPTI.
ENV LD_LIBRARY_PATH /usr/local/cuda/extras/CUPTI/lib64:/usr/local/cuda/lib64:$LD_LIBRARY_PATH

# Link the libcuda stub to the location where tensorflow is searching for it and reconfigure
# dynamic linker run-time bindings
RUN ln -s /usr/local/cuda/lib64/stubs/libcuda.so /usr/local/cuda/lib64/stubs/libcuda.so.1 \
    && echo "/usr/local/cuda/lib64/stubs" > /etc/ld.so.conf.d/z-cuda-stubs.conf \
    && ldconfig

RUN conda install --quiet --yes \
    'cudatoolkit=10.1.243' \
    "pytorch::pytorch=1.6.0" \
    "pytorch::torchvision=0.7.0" \
    'pytorch::torchtext=0.7.0' \
    && \
    conda clean --all -f -y && \
    fix-permissions $CONDA_DIR && \
    fix-permissions /home/$NB_USER

RUN python -m pip install --quiet --no-cache-dir \
    'tensorflow==2.3.0' \
    'sentencepiece' \
    'spacy[cuda101]' \
    'spacy[lookups, cuda101]' \
    'spacy[transformers, cuda101]' \
    && \
    fix-permissions "${CONDA_DIR}" && \
    fix-permissions "/home/${NB_USER}"

RUN python -m spacy download en_core_web_lg
RUN python -m spacy download en_core_web_trf

patrykattc avatar Feb 10 '21 18:02 patrykattc

~I'm still chasing this down but I suspect it will come down to the version of transformers. You've got 4.2.2 there, a clean install without the conda complications will be pulling in 4.3.x.~

Edit: argh that's all wrong, sorry. Thanks @adrianeboyd below.

honnibal avatar Feb 10 '21 21:02 honnibal

As a note: this isn't due to conda. spacy-transformers limits the version to transformers<4.3.0. (Which seems to be a good thing. I do get this error with 4.3.2, which may make it easier to figure out what's going on. But we haven't tested 4.3.x for compatibility at all yet since it's only been released for a few days.)

adrianeboyd avatar Feb 10 '21 22:02 adrianeboyd

Oops! Thanks, edited.

honnibal avatar Feb 10 '21 22:02 honnibal

Could you try running:

python -m pytest --pyargs thinc.tests

This should run Thinc's test suite, which is packaged with the library. The GPU tests should trigger automatically if everything's installed, too. This should help us narrow down which layer things are going wrong at.

honnibal avatar Feb 10 '21 23:02 honnibal

I can't test any of this locally so this is a bit tedious, sorry. CUDA 11.0 support shouldn't be the issue. If en_core_web_lg is working fine with GPU, then spacy and cupy are probably fine. Someone else is reporting the same error in #6971 with a conda install of torch (the next thing I was going to suggest), so I am not sure what's going on and I can't replicate this with a very similar setup with conda in linux, so it's hard to debug.

What is the output of conda list?

Is it possible for you try this in a pip-only venv?

Hi, It's good to know that CUDA version is not the issue. I tried pip-only venv and got the same issue. The output of 'conda list' is like this: Name Version Build Channel _libgcc_mutex 0.1 main argon2-cffi 20.1.0 py38h7b6447c_1 async_generator 1.10 pyhd3eb1b0_0 attrs 20.3.0 pyhd3eb1b0_0 backcall 0.2.0 pyhd3eb1b0_0 blas 1.0 mkl bleach 3.3.0 pyhd3eb1b0_0 blis 0.7.4 pypi_0 pypi ca-certificates 2021.1.19 h06a4308_0 catalogue 2.0.1 pypi_0 pypi certifi 2020.12.5 py38h06a4308_0 cffi 1.14.4 py38h261ae71_0 chardet 4.0.0 pypi_0 pypi click 7.1.2 pypi_0 pypi cudatoolkit 11.0.221 h6bb024c_0 cupy-cuda110 8.4.0 pypi_0 pypi cymem 2.0.5 pypi_0 pypi decorator 4.4.2 pyhd3eb1b0_0 defusedxml 0.6.0 py_0 en-core-web-trf 3.0.0 pypi_0 pypi entrypoints 0.3 py38_0 fastrlock 0.5 pypi_0 pypi filelock 3.0.12 pypi_0 pypi ftfy 5.8 pypi_0 pypi idna 2.10 pypi_0 pypi importlib-metadata 2.0.0 py_1 importlib_metadata 2.0.0 1 intel-openmp 2020.2 254 ipykernel 5.3.4 py38h5ca1d4c_0 ipython 7.20.0 py38hb070fc8_1 ipython_genutils 0.2.0 pyhd3eb1b0_1 jedi 0.17.0 py38_0 jinja2 2.11.3 pyhd3eb1b0_0 joblib 1.0.1 pypi_0 pypi jsonschema 3.2.0 py_2 jupyter_client 6.1.7 py_0 jupyter_core 4.7.1 py38h06a4308_0 jupyterlab_pygments 0.1.2 py_0 ld_impl_linux-64 2.33.1 h53a641e_7 libedit 3.1.20191231 h14c3975_1 libffi 3.3 he6710b0_2 libgcc-ng 9.1.0 hdf63c60_0 libsodium 1.0.18 h7b6447c_0 libstdcxx-ng 9.1.0 hdf63c60_0 libuv 1.40.0 h7b6447c_0 markupsafe 1.1.1 py38h7b6447c_0 mistune 0.8.4 py38h7b6447c_1000 mkl 2020.2 256 mkl-service 2.3.0 py38he904b0f_0 mkl_fft 1.2.0 py38h23d657b_0 mkl_random 1.1.1 py38h0573a6f_0 murmurhash 1.0.5 pypi_0 pypi nb_conda 2.2.1 py38_1 nb_conda_kernels 2.3.1 py38h06a4308_0 nbclient 0.5.1 py_0 nbconvert 6.0.7 py38_0 nbformat 5.1.2 pyhd3eb1b0_1 ncurses 6.2 he6710b0_1 nest-asyncio 1.4.3 pyhd3eb1b0_0 ninja 1.10.2 py38hff7bd54_0 notebook 6.2.0 py38h06a4308_0 numpy 1.19.2 py38h54aff64_0 numpy-base 1.19.2 py38hfa32c7d_0 openssl 1.1.1i h27cfd23_0 packaging 20.9 pyhd3eb1b0_0 pandas 1.2.2 pypi_0 pypi pandoc 2.11 hb0f4dca_0 pandocfilters 1.4.3 py38h06a4308_1 parso 0.8.1 pyhd3eb1b0_0 pathy 0.3.5 pypi_0 pypi pexpect 4.8.0 pyhd3eb1b0_3 pickleshare 0.7.5 pyhd3eb1b0_1003 pip 21.0.1 pypi_0 pypi preshed 3.0.5 pypi_0 pypi prometheus_client 0.9.0 pyhd3eb1b0_0 prompt-toolkit 3.0.8 py_0 ptyprocess 0.7.0 pyhd3eb1b0_2 pycparser 2.20 py_2 pydantic 1.7.3 pypi_0 pypi pygments 2.7.4 pyhd3eb1b0_0 pyparsing 2.4.7 pyhd3eb1b0_0 pyrsistent 0.17.3 py38h7b6447c_0 python 3.8.5 h7579374_1 python-dateutil 2.8.1 pyhd3eb1b0_0 pytorch 1.7.1 py3.8_cuda11.0.221_cudnn8.0.5_0 pytorch pytz 2021.1 pypi_0 pypi pyzmq 20.0.0 py38h2531618_1 readline 8.1 h27cfd23_0 regex 2020.11.13 pypi_0 pypi requests 2.25.1 pypi_0 pypi sacremoses 0.0.43 pypi_0 pypi send2trash 1.5.0 pyhd3eb1b0_1 setuptools 53.0.0 pypi_0 pypi six 1.15.0 py38h06a4308_0 smart-open 3.0.0 pypi_0 pypi spacy 3.0.1 pypi_0 pypi spacy-alignments 0.7.2 pypi_0 pypi spacy-legacy 3.0.1 pypi_0 pypi spacy-transformers 1.0.1 pypi_0 pypi sqlite 3.33.0 h62c20be_0 srsly 2.4.0 pypi_0 pypi terminado 0.9.2 py38h06a4308_0 testpath 0.4.4 pyhd3eb1b0_0 thinc 8.0.1 pypi_0 pypi tk 8.6.10 hbc83047_0 tokenizers 0.9.4 pypi_0 pypi torchcontrib 0.0.2 pypi_0 pypi tornado 6.1 py38h27cfd23_0 tqdm 4.56.1 pypi_0 pypi traitlets 5.0.5 pyhd3eb1b0_0 transformers 4.2.2 pypi_0 pypi typer 0.3.2 pypi_0 pypi typing_extensions 3.7.4.3 pyh06a4308_0 urllib3 1.26.3 pypi_0 pypi wasabi 0.8.2 pypi_0 pypi wcwidth 0.2.5 py_0 webencodings 0.5.1 py38_1 wheel 0.36.2 pyhd3eb1b0_0 xz 5.2.5 h7b6447c_0 zeromq 4.3.3 he6710b0_3 zipp 3.4.0 pyhd3eb1b0_0 zlib 1.2.11 h7b6447c_3

bitmman avatar Feb 11 '21 01:02 bitmman

I can't test any of this locally so this is a bit tedious, sorry. CUDA 11.0 support shouldn't be the issue. If en_core_web_lg is working fine with GPU, then spacy and cupy are probably fine. Someone else is reporting the same error in #6971 with a conda install of torch (the next thing I was going to suggest), so I am not sure what's going on and I can't replicate this with a very similar setup with conda in linux, so it's hard to debug.

What is the output of conda list?

Is it possible for you try this in a pip-only venv?

Hi, my previous code was running in jupyter notebook. I just ran exactly the same code in the terminal both in conda venv and pip-only venv and there are no problems at all. So, I guess this problem only occurs when run "en_core_web_trf" in jupyter notebook?

Thanks.

bitmman avatar Feb 11 '21 01:02 bitmman