2016-09-13 3 views
7

일부 신경망을 훈련하기 시작했을 때 CUDA_ERROR_OUT_OF_MEMORY을 만났지만 오류없이 훈련을 계속할 수있었습니다.CUDA_ERROR_OUT_OF_MEMORY in tensorflow

I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcublas.so locally 
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcudnn.so locally 
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcufft.so locally 
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcuda.so.1 locally 
I tensorflow/stream_executor/dso_loader.cc:111] successfully opened CUDA library libcurand.so locally 
I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:925] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:951] Found device 0 with properties: 
name: GeForce GTX 1080 
major: 6 minor: 1 memoryClockRate (GHz) 1.7335 
pciBusID 0000:01:00.0 
Total memory: 7.92GiB 
Free memory: 7.81GiB 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:972] DMA: 0 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:982] 0: Y 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:1041] Creating TensorFlow device (/gpu:0) -> (device:0, name: GeForce GTX 1080, pci bus id: 0000:01:00.0) 
E tensorflow/stream_executor/cuda/cuda_driver.cc:965] failed to allocate 4.00G (4294967296 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY 
Iter 20, Minibatch Loss= 40491.636719 
... 

그리고 nvidia-smi 명령을 사용한 후, 그것을 가져옵니다 :

+-----------------------------------------------------------------------------+ 
| NVIDIA-SMI 367.27     Driver Version: 367.27        
|-------------------------------+----------------------+----------------------+ 
| GPU Name  Persistence-M| Bus-Id  Disp.A | Volatile Uncorr. ECC | 
| Fan Temp Perf Pwr:Usage/Cap|   Memory-Usage | GPU-Util Compute M. 
|===============================+======================+======================| 
| 0 GeForce GTX 1080 Off | 0000:01:00.0  Off |     N/A | 
| 40% 61C P2 46W/180W | 8107MiB/8111MiB |  96%  Default | 
+-------------------------------+----------------------+----------------------+ 
| 1 GeForce GTX 1080 Off | 0000:02:00.0  Off |     N/A | 
| 0% 40C P0 40W/180W |  0MiB/8113MiB |  0%  Default | 
+-------------------------------+----------------------+----------------------+ 
                       │ 
+-----------------------------------------------------------------------------+ 
| Processes:              GPU Memory | 
| GPU  PID Type Process name        Usage  | 
|=============================================================================| 
| 0  22932 C python          8105MiB | 
+-----------------------------------------------------------------------------+ 

를 내가 주석 후 내가 정말 필요로 GPU 메모리를 사용하고 싶어하기 때문에, 그래서 나는 다음과 같이 gpu_options.allow_growth = True 국지적 인 로그가 설정 gpu_options.allow_growth = True, 나는 그물을 다시 훈련했고 모든 것이 정상이었다. CUDA_ERROR_OUT_OF_MEMORY의 문제는 없었습니다. 마지막으로, nvidia-smi 명령을 실행, 그것을 가져옵니다

+-----------------------------------------------------------------------------+ 
| NVIDIA-SMI 367.27     Driver Version: 367.27        
|-------------------------------+----------------------+----------------------+ 
| GPU Name  Persistence-M| Bus-Id  Disp.A | Volatile Uncorr. ECC | 
| Fan Temp Perf Pwr:Usage/Cap|   Memory-Usage | GPU-Util Compute M. 
|===============================+======================+======================| 
| 0 GeForce GTX 1080 Off | 0000:01:00.0  Off |     N/A | 
| 40% 61C P2 46W/180W | 7793MiB/8111MiB |  99%  Default | 
+-------------------------------+----------------------+----------------------+ 
| 1 GeForce GTX 1080 Off | 0000:02:00.0  Off |     N/A | 
| 0% 40C P0 40W/180W |  0MiB/8113MiB |  0%  Default | 
+-------------------------------+----------------------+----------------------+ 
                       │ 
+-----------------------------------------------------------------------------+ 
| Processes:              GPU Memory | 
| GPU  PID Type Process name        Usage  | 
|=============================================================================| 
| 0  22932 C python          7791MiB | 
+-----------------------------------------------------------------------------+ 

나는 그것에 대해 두 가지 질문이 있습니다. 왜 CUDA_OUT_OF_MEMORY가 나오고 절차가 정상적으로 진행 되었습니까? 왜 allow_growth = True을 주석 처리 한 후 메모리 사용량이 줄어들 었는가?

답변

5

기본적으로 tensorflow는 값 비싼 메모리 관리를 피하기 위해 GPU 메모리의 분수 012o를 해당 프로세스에 할당하려고합니다. 자세한 내용은 GPUOptions 설명을 참조하십시오.
경고가 발생하여 CUDA_OUT_OF_MEMORY 경고가 발생합니다. 이 경우 대체품이 무엇인지 알 수 없습니다 (CPU 작동 또는 allow_growth=True 사용).
다른 프로세스가 현재 GPU를 사용하는 경우 (예를 들어 tensorflow을 실행하는 두 프로세스를 시작하는 경우) 발생할 수 있습니다. 기본 동작은 메모리의 95 %를 차지합니다 (이 answer 참조).

allow_growth = True을 사용하면 GPU 메모리가 사전 할당되지 않고 필요에 따라 확장 될 수 있습니다. 이렇게하면 메모리 사용량이 줄어들지 만 (기본 옵션은 전체 메모리를 사용하는 것이므로) 메모리를 더 복잡하게 처리해야하기 때문에 적절하게 사용하지 않으면 perfomances가 감소합니다 (CPU/GPU 상호 작용에서 가장 효율적인 부분은 아닙니다).).

+0

하나의 프로세스 만 실행합니다. 내가'allow_growth = True' 주석을 달고 나면 tensorflow는 기본 옵션 때문에 전체 메모리를 사용해야하지만 실제로는 allow_growth = True를 사용했을 때 8107M보다 크지 않은 7793M 메모리 만 사용했습니다 (이것은 혼란 스러웠습니다).). 그 훈련은 그물이 실제로 많은 양의 기억을 필요로하지 않는다는 것을 보여줄 수 있습니다. – luohao

+0

기본적으로 tensorflow는 전체 메모리로 gpu 메모리의 95 % 만 고려하므로 7793MB는 옳습니다 (추가 링크 참조). 'allow_growth'에서 더 많은 메모리를 사용하는 것은 여러분의 네트워크의 크기와 관련이 있어야합니다. (아직 그 소스를 찾지 못했습니다 ...). 예를 들어 GPU에 2 개의 4GB 변수를 할당하면'allow_growth' (~ 8GB)에 맞지만 미리 할당 된 메모리에는 맞지 않으므로'CUDA_ERROR_OUT_OF_MEMORY' 경고가 발생합니다 –

4

누군가와 관련이있는 경우 처음 실행이 중단 된 후 Keras/Tensorflow를 두 번째 실행하려고 할 때이 문제가 발생했습니다. GPU 메모리가 여전히 할당되어있어 다시 할당 할 수없는 것 같습니다. GPU를 사용하는 모든 파이썬 프로세스를 수동으로 종료하거나 기존 터미널을 닫고 새 터미널 창에서 다시 실행함으로써 해결되었습니다.