0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Ubuntu(Docker環境)でspaCyをGPUで使うための前提【備忘録】

Posted at

環境

Dockerイメージ :nvidia/cuda:12.3.2-cudnn9-runtime-ubuntu22.04
Pythonバージョン:3.10.12

困ったこと

GPUでspaCyを使おうとしてspacy.require_gpu()を実行すると、以下のエラーが出た。

import spacy
spacy.require_gpu()
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[1], line 2
      1 import spacy
----> 2 spacy.require_gpu()

File /workspace/.venv/lib/python3.10/site-packages/thinc/util.py:230, in require_gpu(gpu_id)
    228     raise ValueError("Cannot use GPU, PyTorch is not installed")
    229 elif platform.system() != "Darwin" and not has_cupy:
--> 230     raise ValueError("Cannot use GPU, CuPy is not installed")
    231 elif not has_gpu:
    232     raise ValueError("No GPU devices detected")

ValueError: Cannot use GPU, CuPy is not installed

確認したこと

spaCyはちゃんとCUDA対応でインストールしている。

pip install spacy[cuda12x]

実際、pip freezeでもcupyのCUDA対応版が入っている。

pip freeze
spacy==3.8.6
cupy-cuda12x==12.3.0

原因

どうやら、Docker側にlibgomp1が入ってないとそもそもimport cupyすら通らないらしい。
というわけで、Docker側に入れる。

apt install -y libgomp1

これでもう一度spacy.require_gpu()をやってもエラーが出なくなった。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?