Joonas' Note
[PyTorch] AssertionError: Torch not compiled with CUDA enabled 본문
[PyTorch] AssertionError: Torch not compiled with CUDA enabled
2022. 5. 30. 02:26 joonas 읽는데 2분집에 있는 데스크탑에 주피터를 새로 설치했다. 아나콘다는 따로 사용하지 않다보니까 별도로 가상환경을 준비했다.
간단하게 모델을 학습하려고 이전에 잘 동작했던 노트북 파일을 조금 수정해서 실행했는데, 아래와 같은 에러가 났다.
File C:\Python38\lib\site-packages\torch\cuda\__init__.py:210, in _lazy_init()
206 raise RuntimeError(
207 "Cannot re-initialize CUDA in forked subprocess. To use CUDA with "
208 "multiprocessing, you must use the 'spawn' start method")
209 if not hasattr(torch._C, '_cuda_getDeviceCount'):
--> 210 raise AssertionError("Torch not compiled with CUDA enabled")
211 if _cudart is None:
212 raise AssertionError(
213 "libcudart functions unavailable. It looks like you have a broken build?")
AssertionError: Torch not compiled with CUDA enabled
코드 상으로는 문제가 없는 것 같아서 검색을 해봤는데, GPU가 활성화된 버전으로 설치를 해야한다고 한다.
PyTorch: AssertionError ("Torch not compiled with CUDA enabled")
I tried using pytorch with my GPU, but I alway get the error AssertionError: Torch not compiled with CUDA enabled Here are the environment information for torch: PyTorch version: 1.11.0 Is debug bu...
stackoverflow.com
https://pytorch.org/get-started/previous-versions/
파이토치 공식 사이트에서 torch, torchvision, torchaudio 이렇게 3개가 서로 호환되는 버전을 안내하고 있다.
# ROCM 4.2 (Linux only)
pip install torch==1.10.1+rocm4.2 torchvision==0.11.2+rocm4.2 torchaudio==0.10.1 -f https://download.pytorch.org/whl/torch_stable.html
# ROCM 4.1 (Linux only)
pip install torch==1.10.1+rocm4.1 torchvision==0.11.2+rocm4.1 torchaudio==0.10.1 -f https://download.pytorch.org/whl/torch_stable.html
# ROCM 4.0.1 (Linux only)
pip install torch==1.10.1+rocm4.0.1 torchvision==0.10.2+rocm4.0.1 torchaudio==0.10.1 -f https://download.pytorch.org/whl/torch_stable.html
# CUDA 11.1
pip install torch==1.10.1+cu111 torchvision==0.11.2+cu111 torchaudio==0.10.1 -f https://download.pytorch.org/whl/torch_stable.html
# CUDA 10.2
pip install torch==1.10.1+cu102 torchvision==0.11.2+cu102 torchaudio==0.10.1 -f https://download.pytorch.org/whl/torch_stable.html
# CPU only
pip install torch==1.10.1+cpu torchvision==0.11.2+cpu torchaudio==0.10.1 -f https://download.pytorch.org/whl/torch_stable.html
PyTorch
An open source machine learning framework that accelerates the path from research prototyping to production deployment.
pytorch.org
1.11.0 버전도 stable 이긴 한데, 아래처럼 그냥 설치를 해서 그런 것 같다. 이렇게 설치하면 CPU만 사용하기 때문에, cuda() 나 gpu() 같은 GPU 함수들이 동작하지 않는 모양이다.
pip3 install torch torchvision torchaudio # only CPU
# CUDA 11.3
pip3 install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu113
하지만 위 방법을 전부 시도해봤는데 해결되지 않았다.
torch와 CUDA 버전이 맞지 않아서라고해서 (https://choice37.tistory.com/27)
NVIDIA 사이트에서 CUDA를 새로 설치했다. https://developer.nvidia.com/cuda-toolkit-archive
CUDA Toolkit Archive
Previous releases of the CUDA Toolkit, GPU Computing SDK, documentation and developer drivers can be found using the links below. Please select the release you want from the list below, and be sure to check www.nvidia.com/drivers for more recent production
developer.nvidia.com
설치 후에 확인한 CUDA 버전은 이렇다.
$ nvidia-smi.exe
Mon May 30 02:27:40 2022
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 461.09 Driver Version: 461.09 CUDA Version: 11.2 |
|-------------------------------+----------------------+----------------------+
| GPU Name TCC/WDDM | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 GeForce GTX 1660 WDDM | 00000000:01:00.0 On | N/A |
| 45% 37C P8 5W / 130W | 744MiB / 6144MiB | 1% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
이전에 있던 torch를 전부 삭제하고, 호환되는 버전으로 다시 설치했다.
pip uninstall torch torchvision torchaudio
pip install torch==1.10.1+cu102 torchvision==0.11.2+cu102 torchaudio==0.10.1 -f https://download.pytorch.org/whl/torch_stable.html
해결!
'AI > 딥러닝' 카테고리의 다른 글
[딥러닝 일지] Auto Encoder (with MNIST) (0) | 2022.06.03 |
---|---|
[PyTorch] RuntimeError: DataLoader worker is killed by signal: Bus error. (0) | 2022.05.30 |
[PyTorch] GPU 메모리가 부족할 때 확인할 내용들 (0) | 2022.04.25 |
[딥러닝 일지] MNIST Competition (0) | 2022.03.31 |
[딥러닝 일지] 오프라인에서 파이토치 모델 불러오기 (0) | 2022.03.29 |