NLP - chanandrew96/MyLearning GitHub Wiki
NLP
SpaCy
Run SpaCy on GPU
Pre-install
Go to Install SpaCy and select your Hardware - GPU CUAD version
You should get the install command like pip install -U spacy[cuda92]
If you don't know which CUAD version using, use command nvcc --version
to check
Or you can check the installed version on C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA
in Windows
Runtime
import spacy
spacy.prefer_gpu()
nlp_model = spacy.load("en_core_web_sm")
HanLP
Run on GPU
In the offical document (maybe already out-dated), it mentioned that HanLP will look for the GPU on runtime
And no need for user to set whether HanLP using GPU or CPU
HanLP Documentation - Use GPUs
There are no setting or validation for checking HanLP running on GPU
怎么查看GPU是否成功使用
Limit which GPU available
# macOS / Linux
export CUDA_VISIBLE_DEVICES=0,1
# Windows
set CUDA_VISIBLE_DEVICES=0,1
PyTorch / Tensorflow in HanLP
HanLP made dependency on PyTorch / Tensorflow, therefore, you need to set PyTorch and Tensorflow to use GPU as well
Troubleshoot
ModuleNotFoundError: No module named 'pip'
python -m ensurepip
python -m pip install --upgrade pip
Reference
Windows查看CUDA版本
Compare runtimes of spaCy NER pipelines using CPU and GPU
spaCy - Getting Started
解决 ModuleNotFoundError: No module named 'pip'