Tensorflow倾向于在其GPU上预分配整个可用内存.对于调试,有没有办法说明实际使用了多少内存?
对于矢量量化 (k-means) 程序,我想知道当前 GPU 上的可用内存量(如果有的话)。这需要选择最佳批量大小,以便在整个数据集上运行尽可能少的批次。
我编写了以下测试程序:
import tensorflow as tf
import numpy as np
from kmeanstf import KMeansTF
print("GPU Available: ", tf.test.is_gpu_available())
nn=1000
dd=250000
print("{:,d} bytes".format(nn*dd*4))
dic = {}
for x in "ABCD":
dic[x]=tf.random.normal((nn,dd))
print(x,dic[x][:1,:2])
print("done...")
Run Code Online (Sandbox Code Playgroud)
这是我的系统上的典型输出(ubuntu 18.04 LTS,GTX-1060 6GB)。请注意核心转储。
python misc/maxmem.py
GPU Available: True
1,000,000,000 bytes
A tf.Tensor([[-0.23787294 -2.0841186 ]], shape=(1, 2), dtype=float32)
B tf.Tensor([[ 0.23762687 -1.1229591 ]], shape=(1, 2), dtype=float32)
C tf.Tensor([[-1.2672468 0.92139906]], shape=(1, 2), dtype=float32)
2020-01-02 17:35:05.988473: W tensorflow/core/common_runtime/bfc_allocator.cc:419] Allocator (GPU_0_bfc) ran out of memory trying to …Run Code Online (Sandbox Code Playgroud) 我正在使用Tensorflow中的LSTM-RNN训练一些音乐数据,并遇到了一些我不理解的GPU内存分配问题:我遇到一个OOM,而实际上似乎还有足够的VRAM可用.一些背景:我正在研究Ubuntu Gnome 16.04,使用的是GTX1060 6GB,Intel Xeon E3-1231V3和8GB RAM.所以现在首先是我能理解的错误消息的一部分,并且我将在最后为可能要求它提供帮助的任何人添加整个错误消息:
I tensorflow/core/common_runtime/bfc_allocator.cc:696] 8 Chunks of size 256 totalling 2.0KiB I tensorflow/core/common_runtime/bfc_allocator.cc:696] 1 Chunks of size 1280 totalling 1.2KiB I tensorflow/core/common_runtime/bfc_allocator.cc:696] 5 Chunks of size 44288 totalling 216.2KiB I tensorflow/core/common_runtime/bfc_allocator.cc:696] 5 Chunks of size 56064 totalling 273.8KiB I tensorflow/core/common_runtime/bfc_allocator.cc:696] 4 Chunks of size 154350080 totalling 588.80MiB I tensorflow/core/common_runtime/bfc_allocator.cc:696] 3 Chunks of size 813400064 totalling 2.27GiB I tensorflow/core/common_runtime/bfc_allocator.cc:696] 1 Chunks of size 1612612352 totalling 1.50GiB I tensorflow/core/common_runtime/bfc_allocator.cc:700] Sum Total of in-use chunks: 4.35GiB I tensorflow/core/common_runtime/bfc_allocator.cc:702] …