본문 바로가기

인공지능/문제해결

jupyter notebook에서 pytorch-GPU 사용하기

>>> 결론 - jupyter notebook에 가상환경 kernel을 추가하자!


파이토치를 설치하였는데, 터미널에서는 GPU가 사용되지만 주피터 노트북에서는 GPU가 동작하지 않았다....

CUDA toolkit도 재 설치해 보고, 가상환경도 새로 구성해 보았지만 해결되지 않았다.

 

Anaconda Prompt에서 pytorch-gpu 확인

 

jupyter notebook에서 pytorch-gpu 확인

 

 

다행히도, 구글 검색 도중 pytorch 커뮤니티에서 jupyter notebook에 가상환경의 kernal이 추가되지 않아 발생한 문제라는 글을 찾게 되어 해결할 수 있었다... [참고 링크]

 

 

Torch.cuda.is_available() returns False only for jupyter notebook

Most likely because the Jupyter notebook isn’t using the same Python kernel. You can select the Python kernel inside the notebook to make sure you are using the same, which is called in your terminal. Also, a bit unrelated, but I personally prefer to cre

discuss.pytorch.org

 


1.  pytorch를 사용할 가상환경에 ipykernel 설치

conda install ipykernel

2. 해당 가상환경에 커널 추가

python -m ipykernel install --user --name 가상환경이름 --display-name "가상환경이름"

 

이후, 주피터 노트북의 커널목록에 새롭게 추가된 커널을 선택하여 실행하면 해결!

새롭게 추가된 커널

 

jupyter notebook에서 pytorch-gpu 확인