如何在Windows上为Spacy启用CUDA GPU加速。

huangapple go评论50阅读模式
英文:

How to enable CUDA GPU acceleration for Spacy on Windows

问题

SpaCy 是一个处理文本和构建自己的模型以提取和处理数据的强大库。当我尝试使用 en_core_web_trf 模型来提取英文文本中的实体时,我遇到了一个令人沮丧的问题 - 当在 CPU 上运行时,模型非常慢。因此,我尝试让 GPU 成为执行此任务的动力源。

但要尝试启用 GPU 加速可能会具有挑战性 - 驱动程序、CUDA、PyTorch、特定的 SpaCy 安装...

经过几次失败的尝试,我找到了在 SpaCy 中启用 GPU 的正确方法。希望它能有所帮助。

英文:

As you may know SpaCy is a great library for processing texts and building your own models for extracting and processing data. One of the

When I tried using en_core_web_trf model for getting entities from english texts, I came to sad outcome - model was very slow when working on CPU. So, I tried to get GPU work as powerhouse for this task.

But trying to enable GPU acceleration may be challenging - drivers, CUDA, pytorch, specific spacy installation...

After few failed attempts I found correct way for enablement of GPU in SpaCy. Hope it will help

答案1

得分: 3

以下是已经翻译好的部分:

步骤:

  1. 从 nVidia 网站安装最新的稳定 GPU 驱动程序(下载链接)。
  2. 从 nVidia 网站安装 CUDA Toolkit(我使用了存档链接)。例如,版本 11.6 是稳定的,可以毫不犹豫地使用。重新启动计算机。
  3. 让我们检查安装的正确性
nvcc --version
nvcc: NVIDIA (R) Cuda 编译器驱动程序
版权所有 (c) 2005-2021 NVIDIA Corporation
构建于 20211217 日 18:28:54 太平洋标准时间
Cuda 编译工具,版本 11.6,V11.6.55z
构建 cuda_11.6.r11.6/compiler.30794723_0
  1. 从这个下载链接安装 PyTorch。PyTorch 将为我们提供 GPU 支持的后端。
    检查以下选项:

构建: 稳定
操作系统: Windows
包: pip
计算平台:
Cuda 11.6

在检查这些选项的列表后,您应该能够复制以下字符串

pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu116

以管理员权限在 cmd 中运行此字符串

  1. 检查 PyTorch 是否正确安装
import torch
torch.cuda.is_available()
True
  1. 从以下网页安装 SpaCy。请检查以下选项:

操作系统 – Windows
平台 – x86
包管理器 – pip
硬件
– GPU
CUDA - 11.6

  1. 使用管理员权限在 cmd 中运行以下代码:
pip install -U pip setuptools wheel
pip install -U “spacy[cuda116]python -m spacy download en_core_web_trf
  1. 让我们检查一切是否正常运行:
spacy.require_gpu()
load_nlp = spacy.load("en_core_web_trf")
doc = load_nlp(text)

其中 text - 你想要处理的任何英语文本

谈到加速 - SpaCy 有自己的基准测试

英文:

Steps:

  1. Install latest stable drivers for your GPU from nVidia website (download).
  2. Install CUDA Toolkit from nVidia website (I used archive). For example, version 11.6 is stable and can be used without hesitation. Reboot.
  3. Let's check correctness of installation
nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2021 NVIDIA Corporation
Built on Fri_Dec_17_18:28:54_Pacific_Standard_Time_2021
Cuda compilation tools, release 11.6, V11.6.55z
Build cuda_11.6.r11.6/compiler.30794723_0
  1. Install PyTorch from this download link. PyTorch will provide us backend for GPU support.
    Check following options:

> Build: Stable<br> OS: Windows<br> Package: pip<br> Compute Platform:
> Cuda 11.6<br>

After checking list of these options you should be able to copy following string

pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu116

Run this string in cmd with admin rights

  1. Check if PyTorch is installed correctly
import torch
torch.cuda.is_available()
True
  1. Install SpaCy from following webpage. Please check following options:

> OS – Windows<br> Platform – x86<br> package manager – pip<br> Hardware
> – GPU<br> CUDA - 11.6

  1. Using admin rights run following code in cmd:
pip install -U pip setuptools wheel
pip install -U “spacy[cuda116]”
python -m spacy download en_core_web_trf
  1. Let's check that everything is working just fine:
spacy.require_gpu()
load_nlp = spacy.load(&quot;en_core_web_trf&quot;)
doc = load_nlp(text)

, where text - any text on English you want to process

Speaking about acceleration - SpaCy has it's own benchmarks

huangapple
  • 本文由 发表于 2023年2月6日 04:21:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/75355264.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定