최근 Object Detection 관련 연구를 하기 위해 yolov4-keras 버전 github를 발견하여 돌려보다가 처음 보는 에러를 발견하였다.
UnknownError:
Failed to get convolution algorithm. This is probably because cuDNN failed to initialize, so try looking to see if a warning log message was printed above. [[node Yolo_v4/convn_0/Conv2D (defined at <ipython-input-25-f68d3f7b8346>:7) ]] [Op:__inference_predict_function_12792]
이 에러에 대해서 구글링을 해보았는데, Tensorflow github - issue와 stackoverflow 에서 쉽게 찾아볼 수 있는 에러였다.
해답으로는
tensorflow 버전을 변경해라 , conda에서 CUDA 버전 변경해라, cuDNN 파일을 건들어야 된다. 새로운 명령어를 쳐라.. 등등
여러 가지가 있었다. 그래서 하라는 대로 모든 것을 해보았는데 결과는 똑같은 에러가 발생하였다.
이 에러에 대한 해결을 하기위해 삽질을 열심히 한 결과, 해답은 굉장히 간단한 것이었다.
yolov4-keras 모델을 돌릴 때 input image의 크기를 608,608로 진행하였었다. (상당히 큰 크기)
그 결과 한 개의 모델만 돌려도 이 모델이 대부분의 GPU-memory를 잡아먹고 있었다.
위 사진에서도 볼 수 있듯이 GPU-memory를 다 차지한 것을 볼 수 있다.
(Processes: 있는 부분에서 어떤 것이 memory를 차지하고 있는지 자세히 볼 수 있다.)
하지만 이 상태에서 다른 모델을 돌릴려고 하니 GPU-memory가 가득 차 돌릴 수 없다는 에러였다.
그래서 정상적으로 구동을 하기 위해서는 한 개의 모델을 종료해야 다른 한 개의 모델의 실행이 가능했다.
(혹은 image size 크기를 조정하면 된다.)
나에게는 안좋은 습관이 있는데 jupyter lab에서 kernel shut down 기능이 있지만, 종료할 때 jupyter lab이 실행 중인 터미널로 가서 직접 ctrl+c를 한다. 즉 강제 종료를 한다.
이 습관은 간혹 프로세스가 완전히 종료되지 않아 GPU-memory에 데이터가 남아있는 경우가 있다.
그래서 터미널을 이용하여 직접 GPU-memory를 청소하는법에 대해 포스팅을 작성하고자 한다.
참고로 실행중인 os는 Ubuntu 20.04로 window, macOS는 명령어가 틀릴 수도 있다.
1. ps aux|grep python 명령어를 사용하여 현재 GPU-memory를 차지하고 있는 파일들을 살펴본다.
$ ps aux|grep python
root 896 0.0 0.0 40688 20120 ? Ss 15:20 0:00 /usr/bin/python3 /usr/bin/networkd-dispatcher --run-startup-triggers
root 1100 0.0 0.0 119424 22732 ? Ssl 15:20 0:00 /usr/bin/python3 /usr/share/unattended-upgrades/unattended-upgrade-shutdown --wait-for-signal
username+ 67105 0.1 0.1 308548 77120 pts/0 Sl+ 22:08 0:03 /home/username/anaconda3/bin/python3.8 /home/username/anaconda3/bin/jupyter-lab
username+ 67238 0.4 3.3 38746532 2214104 ? Ssl 22:08 0:10 /usr/local/bin/python3.9 -m ipykernel_launcher -f /home/username/.local/share/jupyter/runtime/kernel-b7508480-fffb-49d2-8e51-b2fd5ba1e982.json
username+ 67855 0.4 3.1 16833068 2061936 ? Ssl 22:12 0:11 /usr/local/bin/python3.9 -m ipykernel_launcher -f /home/username/.local/share/jupyter/runtime/kernel-1a6578e0-e771-463d-b01f-4dd487c6fcfe.json
username+ 70516 0.0 0.0 10360 2476 pts/1 S+ 22:52 0:00 grep --color=auto python
2. 그 다음 삭제할 파일의 실행 ID를 찾는다. 실행 ID는 두 번째 칸에 있는 숫자들이다. (896,1100,67105,67238,67855,70516)
3. sudo kill -9 [삭제할 파일의 실행 ID] 명령어를 이용하여 메모리를 사용하지 못하도록 shut down을 해준다.
$ sudo kill -9 67855
5번째에 있는 jupyter 파일을 kill 해보았다.
삭제 후 확인한 결과
$ ps aux|grep python
root 896 0.0 0.0 40688 20120 ? Ss 15:20 0:00 /usr/bin/python3 /usr/bin/networkd-dispatcher --run-startup-triggers
root 1100 0.0 0.0 119424 22732 ? Ssl 15:20 0:00 /usr/bin/python3 /usr/share/unattended-upgrades/unattended-upgrade-shutdown --wait-for-signal
username 67105 0.1 0.1 308548 77268 pts/0 Sl+ 22:08 0:03 /home/username/anaconda3/bin/python3.8 /home/dlwpgjs0723/anaconda3/bin/jupyter-lab
username 67238 0.3 3.3 38746532 2214104 ? Ssl 22:08 0:11 /usr/local/bin/python3.9 -m ipykernel_launcher -f /home/username/.local/share/jupyter/runtime/kernel-b7508480-fffb-49d2-8e51-b2fd5ba1e982.json
username 70813 0.0 0.0 10360 2620 pts/1 S+ 22:59 0:00 grep --color=auto python
하나만 삭제했는데 약 2000mib 의 메모리가 남는 것을 볼 수 있다.
이런 식으로 sudo kill을 이용해서 gpu-memory를 비우면 된다.
'Error 해결' 카테고리의 다른 글
[ Linux ] SCP 오류 (0) | 2023.04.09 |
---|---|
[ Tibero ] tbboot - BOOT FAILED (0) | 2022.02.13 |