본문 바로가기
에러 모음

[CUDA error: out of memory] 프로세스가 없는데 특정 gpu만 안될 때, nvidia-smi 사용하지 않고 gpu 프로세스 확인

by 귤이두번 2023. 7. 13.

RuntimeError: CUDA error: out of memory
CUDA kernel errors might be asynchronously reported at some other API call,so the stacktrace below might be incorrect.
For debugging consider passing CUDA_LAUNCH_BLOCKING=1.

 

--> GPU 메모리가 모자라면 얼만큼 모자르다고 떠야 하는데 아무것도 안뜨고 out of memory라고만 뜬다

 

 

상황:

- nvidia-smi에 아무 프로세스도 잡히지 않음

- 같은 코드인데 gpu 7번을 지정하면 에러가 뜨고 6번을 지정하면 에러가 안뜸

- 원래 7번만 이상있었는데 디버깅하고 이것저것 하다보니 3번도 7번과 같은 증상을 겪음

 

 

발생계기:

- 정확히 알 수 없음. Ctrl+c로 중단했더니 갑자기 이렇게되었다...

 

 

해본것 / OOM 해결법이라고 나와있지만 의미없는것:

1. torch.cuda.empty_cache(): 전혀 작동 안됨. 애초에 학습 혹은 테스트 코드 프로세스가 잡혀있지 않음. 

2. batch_size 줄이기: 다른 gpu에서는 작동함.

3. with torch.no_grad(): 학습코드라서 의미없음. 다른 gpu에서는 작동함.

4. 특정 사용자 이름의 프로세스 삭제: 내가 실행했던 코드이기에 내 이름으로 된 프로세스들을 kill 했음.

 

 

확실한 해결방법:

- 가장 쉬운 해결 방법은 재부팅이다 (이것은 예전에 했던 방법으로 확실히 모든 프로세스를 끄기 때문에 가장 좋은 방법이다)

 

 

나의 해결방법 및 과정 (검증안됨)

1. gpu를 리셋하는 방법이 있기에 이를 하려고 했다. 

nvidia-smi --id=7 --gpu-reset

 

2. 그랬더니 nvidia-smi에 뜨는 프로세스는 없는데 뭔가가 있어서 리셋을 못하겠다고 뜬다

[sudo] password for gpuadmin: The following GPUs could not be reset: GPU 00000000:24:00.0: In use by another client 1 device is currently being used by one or more other processes (e.g., Fabric Manager, CUDA application, graphics application such as an X server, or a monitoring application such as another instance of nvidia-smi). Please first kill all processes using this device and all compute applications running in the system.

 

3. 그래서 저것에 대해 검색하다 다음 페이지를 발견한다. 

https://forums.developer.nvidia.com/t/11-gb-of-gpu-ram-used-and-no-process-listed-by-nvidia-smi/44459/4

 

11 GB of GPU RAM used, and no process listed by nvidia-smi

log out of the username that issued the interrupted work to that gpu as root, find all running processes associated with the username that issued the interrupted work on that gpu: ps -ef|grep username as root, kill all of those as root, retry the nvidia-sm

forums.developer.nvidia.com

sudo fuser -v /dev/nvidia*

nvidia-smi말고 GPU에서 실행되는 프로세스를 확인할 수 있다고 한다.

 

4. 확인했더니 정말 nvidia-smi에 잡히지 않았던 프로세스가 존재했다.

누군가의 텐서보드..?

당장 98269 프로세스를 kill했다. 

 

5. 그 후 gpu7번은 reset을 했다

 

6. 그 결과 7번이 다시 작동하게 되었다. 더불어 3번은 리셋하지 않아도 작동이 되었다.

 

왜 이러는건지, 텐서보드가 메모리를 많이 사용하는건지 정확하게는 모르겠다. 하지만 이 방법을 통해 해결했으므로 다음에 문제가 재발하면 이 방법을 다시 써봐야겠다. 

댓글