【问题标题】:tensorflow: CUDA_ERROR_OUT_OF_MEMORY always happen张量流:CUDA_ERROR_OUT_OF_MEMORY 总是发生
【发布时间】:2017-04-18 08:45:41
【问题描述】:

我将通过 1080 ti (11GB) GPU 使用 tf-seq2seq 包训练 seq2seq 模型。我总是使用不同的网络大小(甚至nmt_small)得到以下错误:

I tensorflow/core/common_runtime/gpu/gpu_device.cc:885] Found device 0 with properties: 
name: Graphics Device
major: 6 minor: 1 memoryClockRate (GHz) 1.582
pciBusID 0000:03:00.0
Total memory: 10.91GiB
Free memory: 10.75GiB
I tensorflow/core/common_runtime/gpu/gpu_device.cc:906] DMA: 0 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:916] 0:   Y 
I tensorflow/core/common_runtime/gpu/gpu_device.cc:975] Creating TensorFlow device (/gpu:0) -> (device: 0, name: Graphics Device, pci bus id: 0000:03:00.0)
E tensorflow/stream_executor/cuda/cuda_driver.cc:1002] failed to allocate 10.91G (11715084288 bytes) from device: CUDA_ERROR_OUT_OF_MEMORY
I tensorflow/core/common_runtime/gpu/pool_allocator.cc:247] PoolAllocator: After 12337 get requests, put_count=10124 evicted_count=1000 eviction_rate=0.0987752 and unsatisfied allocation rate=0.268542
I tensorflow/core/common_runtime/gpu/pool_allocator.cc:259] Raising pool_size_limit_ from 100 to 110
INFO:tensorflow:Saving checkpoints for 1 into ../model/model.ckpt.
INFO:tensorflow:step = 1, loss = 5.07399

似乎tensorflow试图占用GPU的内存总量(10.91GiB),但显然只有10.75GiB可用。

【问题讨论】:

    标签: tensorflow


    【解决方案1】:

    您应该注意一些提示:

    1- 使用内存增长,来自 tensorflow 文档:“在某些情况下,进程只需要分配可用内存的子集,或者只根据进程需要增加内存使用量。TensorFlow 提供了两个在 Session 上配置选项来控制它。”

    config = tf.ConfigProto()
    config.gpu_options.allow_growth = True
    session = tf.Session(config=config, ...)
    

    2- 你使用批量训练吗?或一次提供全部数据?如果是,则减少您的批量大小

    【讨论】:

    • 我正在使用批量训练。批量大小为 32,减少到 16 是没有用的。问题是我的 GPU 根本无法分配 10.91GiB。
    【解决方案2】:

    除了以上关于内存增长的建议,你也可以试试:

    sess_config = tf.ConfigProto()
    sess_config.gpu_options.per_process_gpu_memory_fraction = 0.90
    
    with tf.Session(config=sess_config) as sess:
       ...
    

    这样,您可以限制程序分配的 GPU 内存量,在本例中为可用 GPU 内存的 90%。也许这足以解决您的网络尝试分配比可用内存更多的问题。 如果这还不够,您将不得不减小批量大小或网络大小。

    【讨论】:

      猜你喜欢
      • 2019-07-08
      • 2017-01-20
      • 1970-01-01
      • 1970-01-01
      • 2020-10-27
      • 1970-01-01
      • 2017-11-05
      • 2019-02-23
      • 1970-01-01
      相关资源
      最近更新 更多