LoginSignup
4
3

More than 1 year has passed since last update.

「AssertionError: Torch not compiled with CUDA enabled」とpytorchがGPUを認識しない時

Last updated at Posted at 2022-06-13

Pytorchでcudaが使えない時どうするか?

 Pytorchをconda環境で使っているときに、

AssertionError: Torch not compiled with CUDA enabled

エラーに出会うことがあります。
そんな時は、

conda install -c pytorch pytorch

とすると解決します。

詳細な原因

 詳細な原因と解決策は以下の通りです。

エラーの詳細

エラー文

>>> import torch
>>> torch.cuda.current_device()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/hogehoge/yes/envs/gpu_test/lib/python3.7/site-packages/torch/cuda/__init__.py", line 479, in current_device
    _lazy_init()
  File "/home/hogehoge/yes/envs/gpu_test/lib/python3.7/site-packages/torch/cuda/__init__.py", line 208, in _lazy_init
    raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled

原因

 エラーの原因はPytorchはcudaサポートがあるバージョンとないバージョンがあるためにGPUが認識しないと言うのが原因らしいです。

解決策

 解決策は、以下のコマンドを、好きなconda環境で 打つことらしいです。
なんで解決するかは知りません。

 conda install -c pytorch pytorch

参考

AssertionError: Torch not compiled with CUDA enabled #30664

4
3
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
4
3