Reputation: 31
When trying to run a model for spacy NER training with
spacy.require_gpu()
I got this error:
AttributeError Traceback (most recent call last)
<ipython-input-6-a86608cac558> in <module>
3 }
4 start_time = time.time()
----> 5 train_model(data)
<ipython-input-2-10f04ac303a6> in train_model(train_data)
82 other_pipes = [pipe for pipe in nlp.pipe_names if pipe != 'ner']
83 with nlp.disable_pipes(*other_pipes):
---> 84 optimizer = nlp.begin_training()
85 for itn in range(1):
86 print("Starting iteration " + str(itn))
c:\users\aventus\envs\py38\lib\site-packages\spacy\language.py in begin_training(self, get_gold_tuples, sgd, component_cfg, **cfg)
623 kwargs = component_cfg.get(name, {})
624 kwargs.update(cfg)
--> 625 proc.begin_training(
626 get_gold_tuples,
627 pipeline=self.pipeline,
nn_parser.pyx in spacy.syntax.nn_parser.Parser.begin_training()
_parser_model.pyx in spacy.syntax._parser_model.ParserModel.begin_training()
c:\users\aventus\envs\py38\lib\site-packages\thinc\check.py in checked_function(wrapped, instance, args, kwargs)
154 raise ExpectedTypeError(check, ["Callable"])
155 check(arg_id, fix_args, kwargs)
--> 156 return wrapped(*args, **kwargs)
157
158 def arg_check_adder(func):
c:\users\aventus\envs\py38\lib\site-packages\thinc\neural\_classes\model.py in begin_training(self, train_X, train_y, **trainer_cfg)
120 def begin_training(self, train_X, train_y=None, **trainer_cfg):
121 for hook in self.on_data_hooks:
--> 122 hook(self, train_X, train_y)
123 return self.Trainer(self, **trainer_cfg)
124
c:\users\aventus\envs\py38\lib\site-packages\spacy\_ml.py in <lambda>(model, X, y)
149
150 @describe.on_data(
--> 151 _set_dimensions_if_needed, lambda model, X, y: model.init_weights(model)
152 )
153 @describe.attributes(
c:\users\aventus\envs\py38\lib\site-packages\spacy\_ml.py in init_weights(model)
268 t_i = 0
269 for t_i in range(t_max):
--> 270 acts1 = predict(ids, tokvecs)
271 var = model.ops.xp.var(acts1)
272 mean = model.ops.xp.mean(acts1)
c:\users\aventus\envs\py38\lib\site-packages\spacy\_ml.py in predict(ids, tokvecs)
254 (hiddens.shape[0] * model.nF, model.nO * model.nP)
255 )
--> 256 model.ops.scatter_add(vectors, ids.flatten(), hiddens)
257 vectors = vectors.reshape((vectors.shape[0], model.nO, model.nP))
258 vectors += model.b
ops.pyx in thinc.neural.ops.CupyOps.scatter_add()
c:\users\aventus\envs\py38\lib\site-packages\cupy\__init__.py in __getattr__(name)
873 value = _deprecated_attrs.get(name)
874 if value is None:
--> 875 raise AttributeError(
876 f"module 'cupy' has no attribute {name!r}")
877 attr, eq_attr = value
AttributeError: module 'cupy' has no attribute 'scatter_add'
The data used for training the model is annotation for spacy NER.
When running spacy.require_gpu() got this:
Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>import spacy
>>>spacy.require_gpu()
True
How to get rid of this error? Any help will be greatly appreciated.
Upvotes: 0
Views: 6590
Reputation: 11474
There are a couple options to avoid this error:
cupy<8.0.0
(pip install "cupy-cuda110<8.0.0"
)From the comments I don't know how you got spacy v2.2.4 from pip install -U spacy
, but if you don't need that version in particular, upgrading to a version without this error is the easiest solution and newer versions are compatible with cupy v8.
If you definitely need spacy v2.2.4 (which requires thinc==7.4.0
) and newer versions of cupy, you could apply this patch to thinc v7.4.0 and install from source:
See also: https://github.com/explosion/spaCy/issues/5380
Upvotes: 1