如何在SpaCy中在CPU上的GPU上运行经过训练的模型

时间:2019-03-01 15:38:31

标签: python spacy

我正在使用spaCy 2.0.18。我已经使用GPU训练了一个模型,但是现在我想为预测加载该模型并仅在CPU上运行。 我能够将模型加载到内存中,但是一旦尝试使用它,就会出现以下错误:

import spacy
nlp = spacy.load("path_to_my_model")
# works fine up to this moment
result = nlp("Test") # throws the exception below:
Exception ignored in: <bound method Stream.__del__ of <cupy.cuda.stream.Stream object at 0x7fd288621be0>>
Traceback (most recent call last):
  File "cupy/cuda/stream.pyx", line 161, in cupy.cuda.stream.Stream.__del__
AttributeError: 'Stream' object has no attribute 'ptr'
---------------------------------------------------------------------------
CUDARuntimeError                          Traceback (most recent call last)
<ipython-input-4-306c96b208c5> in <module>
----> 1 nlp("Yolo")

/opt/anaconda3/lib/python3.7/site-packages/spacy/language.py in __call__(self, text, disable)
    344             if not hasattr(proc, '__call__'):
    345                 raise ValueError(Errors.E003.format(component=type(proc), name=name))
--> 346             doc = proc(doc)
    347             if doc is None:
    348                 raise ValueError(Errors.E005.format(name=name))

nn_parser.pyx in spacy.syntax.nn_parser.Parser.__call__()

nn_parser.pyx in spacy.syntax.nn_parser.Parser.parse_batch()

/opt/anaconda3/lib/python3.7/site-packages/spacy/util.py in get_cuda_stream(require)
    236 
    237 def get_cuda_stream(require=False):
--> 238     return CudaStream() if CudaStream is not None else None
    239 
    240 

cupy/cuda/stream.pyx in cupy.cuda.stream.Stream.__init__()

cupy/cuda/runtime.pyx in cupy.cuda.runtime.streamCreate()

cupy/cuda/runtime.pyx in cupy.cuda.runtime.streamCreate()

cupy/cuda/runtime.pyx in cupy.cuda.runtime.check_status()

CUDARuntimeError: cudaErrorNoDevice: no CUDA-capable device is detected

如何强制spaCy使用CPU而不是GPU?

0 个答案:

没有答案
相关问题