Khi tôi bắt đầu đào tạo một số mạng thần kinh, nó đã đáp ứng CUDA_ERROR_OUT_OF_MEMORY
nhưng việc đào tạo có thể tiếp diễn mà không có lỗi. Bởi vì tôi muốn sử dụng bộ nhớ gpu như nó thực sự cần, vì vậy tôi đặt gpu_options.allow_growth = True
.Công bản ghi như sau:CUDA_ERROR_OUT_OF_MEMORY trong 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
...
Và sau khi sử dụng nvidia-smi
lệnh, nó được:
+-----------------------------------------------------------------------------+
| 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 |
+-----------------------------------------------------------------------------+
Sau khi tôi nhận xét gpu_options.allow_growth = True
, tôi đã đào tạo lại mạng lưới và mọi thứ đều bình thường. Không có vấn đề gì với số CUDA_ERROR_OUT_OF_MEMORY
. Cuối cùng, chạy lệnh nvidia-smi
, nó nhận được:
+-----------------------------------------------------------------------------+
| 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 |
+-----------------------------------------------------------------------------+
Tôi có hai câu hỏi về nó. Tại sao CUDA_OUT_OF_MEMORY
xuất hiện và thủ tục diễn ra bình thường? tại sao việc sử dụng bộ nhớ trở nên nhỏ hơn sau khi nhận xét allow_growth = True
.
Tôi chỉ khởi chạy một quy trình. Sau khi tôi nhận xét 'allow_growth = True', tensorflow nên sử dụng toàn bộ bộ nhớ vì tùy chọn mặc định nhưng thực ra nó chỉ sử dụng bộ nhớ 7793M mà thậm chí không lớn hơn 8107M khi tôi sử dụng' allow_growth = True' (đó là nơi tôi bị nhầm lẫn). Việc đào tạo đó có thể cho thấy mạng thực sự không cần nhiều bộ nhớ. – luohao
Theo mặc định, tensorflow chỉ xem xét 95% bộ nhớ gpu là toàn bộ bộ nhớ vì vậy 7793MB có vẻ đúng (xem thêm liên kết). Việc sử dụng nhiều bộ nhớ hơn trong 'allow_growth' nên liên quan đến kích thước mạng của bạn (tôi chưa tìm thấy bất kỳ nguồn nào về điều đó ...). Ví dụ: nếu bạn phân bổ hai biến 4GB trên GPU, nó sẽ khớp với 'allow_growth' (~ 8GB) nhưng không khớp với bộ nhớ preallocated, do đó tăng cảnh báo' CUDA_ERROR_OUT_OF_MEMORY' –