일부 신경망을 훈련하기 시작했을 때 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
을 주석 처리 한 후 메모리 사용량이 줄어들 었는가?
하나의 프로세스 만 실행합니다. 내가'allow_growth = True' 주석을 달고 나면 tensorflow는 기본 옵션 때문에 전체 메모리를 사용해야하지만 실제로는 allow_growth = True를 사용했을 때 8107M보다 크지 않은 7793M 메모리 만 사용했습니다 (이것은 혼란 스러웠습니다).). 그 훈련은 그물이 실제로 많은 양의 기억을 필요로하지 않는다는 것을 보여줄 수 있습니다. – luohao
기본적으로 tensorflow는 전체 메모리로 gpu 메모리의 95 % 만 고려하므로 7793MB는 옳습니다 (추가 링크 참조). 'allow_growth'에서 더 많은 메모리를 사용하는 것은 여러분의 네트워크의 크기와 관련이 있어야합니다. (아직 그 소스를 찾지 못했습니다 ...). 예를 들어 GPU에 2 개의 4GB 변수를 할당하면'allow_growth' (~ 8GB)에 맞지만 미리 할당 된 메모리에는 맞지 않으므로'CUDA_ERROR_OUT_OF_MEMORY' 경고가 발생합니다 –