Skip to content

Out of GPU Memory -- Only 1 LSTM layer on 980 TI #352

Closed

Description

@NickShahML

Hey TF,

I have been using your translate model from your seq2seq tutorial and everything seems to work great.

However, I have encountered a substantial problem. On my 980 TI with 6gb of memory:

  • 5 GRU layers, 512 cells, batch size 32 -- works
  • 1 GRU layer, 1024 cells, batch size 2 -- barely works (tried batch size of 2, 4, 8, 16)

In Keras, I could run 2 GRU layers each with 2048 cells on my the 6gb memory. So the question I have is: how is this possible? What is taking up so much memory when you increase the cell size?

I have a second 980 TI as well. I was really hoping I could put one layer 2048 cells on each card. Thanks again!

Activity

  1. vrv commented on Nov 25, 2015

    @vrv

    When it runs out of memory, it should print information about the memory usage -- can you include that?

  2. NickShahML commented on Nov 25, 2015

    @NickShahML
    Author

    Sure! Here is the pool allocation when it does work -- GRU with 1024 cells at batch size 2:

    W tensorflow/core/common_runtime/gpu/pool_allocator.cc:227] PoolAllocator: After 7923 get requests, put_count=3499 evicted_count=1000 eviction_rate=0.285796 and unsatisfied allocation rate=0.697211
    I tensorflow/core/common_runtime/gpu/pool_allocator.cc:239] Raising pool_size_limit_ from 100 to 110
    W tensorflow/core/common_runtime/gpu/pool_allocator.cc:227] PoolAllocator: After 4623 get requests, put_count=2605 evicted_count=1000 eviction_rate=0.383877 and unsatisfied allocation rate=0.656284
    I tensorflow/core/common_runtime/gpu/pool_allocator.cc:239] Raising pool_size_limit_ from 176 to 193
    W tensorflow/core/common_runtime/gpu/pool_allocator.cc:227] PoolAllocator: After 6 get requests, put_count=2029 evicted_count=2000 eviction_rate=0.985707 and unsatisfied allocation rate=0
    W tensorflow/core/common_runtime/gpu/pool_allocator.cc:227] PoolAllocator: After 4 get requests, put_count=1034 evicted_count=1000 eviction_rate=0.967118 and unsatisfied allocation rate=0
    W tensorflow/core/common_runtime/gpu/pool_allocator.cc:227] PoolAllocator: After 4 get requests, put_count=1044 evicted_count=1000 eviction_rate=0.957854 and unsatisfied allocation rate=0
    W tensorflow/core/common_runtime/gpu/pool_allocator.cc:227] PoolAllocator: After 0 get requests, put_count=1054 evicted_count=1000 eviction_rate=0.948767 and unsatisfied allocation rate=-nan
    W tensorflow/core/common_runtime/gpu/pool_allocator.cc:227] PoolAllocator: After 0 get requests, put_count=1087 evicted_count=1000 eviction_rate=0.919963 and unsatisfied allocation rate=-nan
    W tensorflow/core/common_runtime/gpu/pool_allocator.cc:227] PoolAllocator: After 7337 get requests, put_count=6254 evicted_count=2000 eviction_rate=0.319795 and unsatisfied allocation rate=0.437509
    I tensorflow/core/common_runtime/gpu/pool_allocator.cc:239] Raising pool_size_limit_ from 1400 to 1540
    W tensorflow/core/common_runtime/gpu/pool_allocator.cc:227] PoolAllocator: After 12607 get requests, put_count=10862 evicted_count=1000 eviction_rate=0.0920641 and unsatisfied allocation rate=0.235583
    I tensorflow/core/common_runtime/gpu/pool_allocator.cc:239] Raising pool_size_limit_ from 2478 to 2725
    

    Here is 2 GRU layers of 1024 batch size of 2. When it runs out of memory, the error message keeps repeating over and over again. I've included the print out right as it is about to compute. You can see that it starts to allocate and pool data but then it simply runs out:

    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 256 (256B) Pool: chunks: 2048 free: 247 cumulative malloc: 10736 cumulative freed: 8935
    Number of chunks: 2048, in_use chunks: 1801
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 512 (512B) Pool: chunks: 64 free: 64 cumulative malloc: 360 cumulative freed: 360
    Number of chunks: 64, in_use chunks: 0
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 1024 (1.0KiB) Pool: chunks: 64 free: 62 cumulative malloc: 352 cumulative freed: 350
    Number of chunks: 64, in_use chunks: 2
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 2048 (2.0KiB) Pool: chunks: 128 free: 128 cumulative malloc: 414 cumulative freed: 414
    Number of chunks: 128, in_use chunks: 0
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 4096 (4.0KiB) Pool: chunks: 256 free: 2 cumulative malloc: 963 cumulative freed: 709
    Number of chunks: 256, in_use chunks: 254
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 8192 (8.0KiB) Pool: chunks: 128 free: 63 cumulative malloc: 1052 cumulative freed: 987
    Number of chunks: 128, in_use chunks: 65
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 16384 (16.0KiB) Pool: chunks: 1344 free: 709 cumulative malloc: 14046 cumulative freed: 13411
    Number of chunks: 1344, in_use chunks: 635
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 32768 (32.0KiB) Pool: chunks: 384 free: 247 cumulative malloc: 2187 cumulative freed: 2050
    Number of chunks: 384, in_use chunks: 137
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 65536 (64.0KiB) Pool: chunks: 2 free: 2 cumulative malloc: 9 cumulative freed: 9
    Number of chunks: 2, in_use chunks: 0
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 131072 (128.0KiB) Pool: chunks: 2 free: 1 cumulative malloc: 2 cumulative freed: 1
    Number of chunks: 2, in_use chunks: 1
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 229376 (224.0KiB) Pool: chunks: 44 free: 44 cumulative malloc: 242 cumulative freed: 242
    Number of chunks: 44, in_use chunks: 0
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 327680 (320.0KiB) Pool: chunks: 4 free: 3 cumulative malloc: 4 cumulative freed: 3
    Number of chunks: 4, in_use chunks: 1
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 425984 (416.0KiB) Pool: chunks: 68 free: 68 cumulative malloc: 796 cumulative freed: 796
    Number of chunks: 68, in_use chunks: 0
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 524288 (512.0KiB) Pool: chunks: 2 free: 2 cumulative malloc: 6 cumulative freed: 6
    Number of chunks: 2, in_use chunks: 0
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 1048576 (1.00MiB) Pool: chunks: 190 free: 69 cumulative malloc: 768 cumulative freed: 647
    Number of chunks: 190, in_use chunks: 121
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 2228224 (2.12MiB) Pool: chunks: 119 free: 119 cumulative malloc: 276 cumulative freed: 276
    Number of chunks: 119, in_use chunks: 0
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 4456448 (4.25MiB) Pool: chunks: 62 free: 0 cumulative malloc: 164 cumulative freed: 102
    Number of chunks: 62, in_use chunks: 61
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 8912896 (8.50MiB) Pool: chunks: 123 free: 0 cumulative malloc: 529 cumulative freed: 406
    Number of chunks: 123, in_use chunks: 122
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 17825792 (17.00MiB) Pool: chunks: 61 free: 0 cumulative malloc: 226 cumulative freed: 165
    Number of chunks: 61, in_use chunks: 60
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 41943040 (40.00MiB) Pool: chunks: 1 free: 1 cumulative malloc: 1 cumulative freed: 1
    Number of chunks: 1, in_use chunks: 0
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 67108864 (64.00MiB) Pool: chunks: 1 free: 1 cumulative malloc: 2 cumulative freed: 2
    Number of chunks: 1, in_use chunks: 0
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 134217728 (128.00MiB) Pool: chunks: 1 free: 1 cumulative malloc: 1 cumulative freed: 1
    Number of chunks: 1, in_use chunks: 0
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 335544320 (320.00MiB) Pool: chunks: 7 free: 3 cumulative malloc: 22 cumulative freed: 18
    Number of chunks: 7, in_use chunks: 4
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:345] Aggregate Region Memory: 5596086272 (5.21GiB)
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:347] Aggregate Chunk Memory: 5595824128 (5.21GiB)
    W tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:89] Out of GPU memory, see memory state dump above
    W tensorflow/core/kernels/matmul_op.cc:143] Resource exhausted: OOM when allocating tensor with shapedim { size: 2048 } dim { size: 1024 }
    W tensorflow/core/common_runtime/executor.cc:1027] 0x58dae900 Compute status: Resource exhausted: OOM when allocating tensor with shapedim { size: 2048 } dim { size: 1024 }
         [[Node: gradients_3/model_with_buckets/embedding_attention_seq2seq_3/embedding_attention_decoder/attention_decoder/GRUCell_4/Candidate/Linear/MatMul_grad/MatMul_1 = MatMul[T=DT_FLOAT, transpose_a=true, transpose_b=false, _device="/job:localhost/replica:0/task:0/gpu:0"](model_with_buckets/embedding_attention_seq2seq_3/embedding_attention_decoder/attention_decoder/GRUCell_4/Candidate/Linear/concat, gradients_3/model_with_buckets/embedding_attention_seq2seq_3/embedding_attention_decoder/attention_decoder/GRUCell_4/Candidate/add_grad/Reshape)]]
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 256 (256B) Pool: chunks: 2048 free: 247 cumulative malloc: 10736 cumulative freed: 8935
    Number of chunks: 2048, in_use chunks: 1801
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 512 (512B) Pool: chunks: 64 free: 64 cumulative malloc: 360 cumulative freed: 360
    Number of chunks: 64, in_use chunks: 0
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 1024 (1.0KiB) Pool: chunks: 64 free: 62 cumulative malloc: 352 cumulative freed: 350
    Number of chunks: 64, in_use chunks: 2
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 2048 (2.0KiB) Pool: chunks: 128 free: 128 cumulative malloc: 414 cumulative freed: 414
    Number of chunks: 128, in_use chunks: 0
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 4096 (4.0KiB) Pool: chunks: 256 free: 2 cumulative malloc: 963 cumulative freed: 709
    Number of chunks: 256, in_use chunks: 254
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 8192 (8.0KiB) Pool: chunks: 128 free: 63 cumulative malloc: 1052 cumulative freed: 987
    Number of chunks: 128, in_use chunks: 65
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 16384 (16.0KiB) Pool: chunks: 1344 free: 710 cumulative malloc: 14046 cumulative freed: 13412
    Number of chunks: 1344, in_use chunks: 634
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 32768 (32.0KiB) Pool: chunks: 384 free: 248 cumulative malloc: 2187 cumulative freed: 2051
    Number of chunks: 384, in_use chunks: 136
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 65536 (64.0KiB) Pool: chunks: 2 free: 2 cumulative malloc: 9 cumulative freed: 9
    Number of chunks: 2, in_use chunks: 0
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 131072 (128.0KiB) Pool: chunks: 2 free: 1 cumulative malloc: 2 cumulative freed: 1
    Number of chunks: 2, in_use chunks: 1
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 229376 (224.0KiB) Pool: chunks: 44 free: 44 cumulative malloc: 242 cumulative freed: 242
    Number of chunks: 44, in_use chunks: 0
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 327680 (320.0KiB) Pool: chunks: 4 free: 3 cumulative malloc: 4 cumulative freed: 3
    Number of chunks: 4, in_use chunks: 1
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 425984 (416.0KiB) Pool: chunks: 68 free: 68 cumulative malloc: 796 cumulative freed: 796
    Number of chunks: 68, in_use chunks: 0
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 524288 (512.0KiB) Pool: chunks: 2 free: 2 cumulative malloc: 6 cumulative freed: 6
    Number of chunks: 2, in_use chunks: 0
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 1048576 (1.00MiB) Pool: chunks: 190 free: 69 cumulative malloc: 768 cumulative freed: 647
    Number of chunks: 190, in_use chunks: 121
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 2228224 (2.12MiB) Pool: chunks: 119 free: 119 cumulative malloc: 276 cumulative freed: 276
    Number of chunks: 119, in_use chunks: 0
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 4456448 (4.25MiB) Pool: chunks: 62 free: 0 cumulative malloc: 164 cumulative freed: 102
    Number of chunks: 62, in_use chunks: 61
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 8912896 (8.50MiB) Pool: chunks: 123 free: 0 cumulative malloc: 529 cumulative freed: 406
    Number of chunks: 123, in_use chunks: 122
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 17825792 (17.00MiB) Pool: chunks: 61 free: 0 cumulative malloc: 226 cumulative freed: 165
    Number of chunks: 61, in_use chunks: 60
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 41943040 (40.00MiB) Pool: chunks: 1 free: 1 cumulative malloc: 1 cumulative freed: 1
    Number of chunks: 1, in_use chunks: 0
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 67108864 (64.00MiB) Pool: chunks: 1 free: 1 cumulative malloc: 2 cumulative freed: 2
    Number of chunks: 1, in_use chunks: 0
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 134217728 (128.00MiB) Pool: chunks: 1 free: 1 cumulative malloc: 1 cumulative freed: 1
    Number of chunks: 1, in_use chunks: 0
    I tensorflow/core/common_runtime/gpu/gpu_region_allocator.cc:339] Chunk size: 335544320 (320.00MiB) Pool: chunks: 7 free: 3 cumulative malloc: 22 cumulative freed: 18
    Number of chunks: 7, in_use chunks: 4
    

    It will keep repeating this over and over again.

    Has anyone had similar problems? It just doesn't seem right that a 1024 GRU should barely fit on 5gb of memory. I am purely doing text to text (50 words input and 50 words output), so the input data shouldn't be that heavy. Any help would be immensely appreciated!

  3. vrv commented on Nov 25, 2015

    @vrv

    Ah, this is likely a result of fragmentation caused by our initial / older memory allocator.

    If you build from source (at HEAD), you will by default use a better memory allocator that is less likely to run into these problems. It will be in our next binary release, if you'd rather wait until then.

  4. NickShahML commented on Nov 25, 2015

    @NickShahML
    Author

    Hey @vrv thanks for your help. I just built it from source and it did help some. Now, I can run a 1536 GRU layer at a batch size of 8 -- which is definitely an improvement! However, I can't run the desired 2048 unless I decrease the batch size to 4.

    I'll close this issue as things are certainly better. Hopefully, the gpu allocator can be further improved upon? It seems that multiple layers is great (I can use 6 GRU layers with 512 cells/layer with a batch size of 16). It just seems that these large layer sizes really sucks up memory compared to Theano.

  5. vrv commented on Nov 25, 2015

    @vrv

    Cool, glad it helped at least a little.

    @rafaljozefowicz may have some other ideas too. Memory improvements will certainly come as the project matures :)

  6. rafaljozefowicz commented on Nov 25, 2015

    @rafaljozefowicz

    Could you try locating tf.gradients call in the model code and add a new argument: aggregation_method=1 (or 2 which might be better). This is an experimental feature that optimizes memory consumption of gradient updates for RNNs. I was able to train much larger models with this parameter. There is a chance it will slow down your code somewhat, though.

  7. NickShahML commented on Nov 27, 2015

    @NickShahML
    Author

    @rafaljozefowicz I apologize for the late response. Thank you for letting me know about this!

    Unfortunately, I'm away from my computer because of the holidays, but on Sunday/Monday I will try this, and post back here with results. Again, I really do appreciate the help.

    If it slows it down, that's okay. The main thing I'm hoping for is a GRU of 2048 cells with a batch size of hopefully 16.

  8. NickShahML commented on Nov 29, 2015

    @NickShahML
    Author

    @rafaljozefowicz thank you for the help. Using aggregation_method = 2 got me to a gru of 1536 with a batch size of 16 (which is double the size from what I had previously!). So this is a definite upgrade.

    I'm starting wonder if the softmax is sucking up alot of gpu memory. @vrv is there a way to see how much op is taking GPU memory? This would allow us to diagnose where GPU memory shortages are stemming from.

  9. vrv commented on Dec 3, 2015

    @vrv

    @LeavesBreathe: not yet, but we're working on providing instrumentation so that it can be made available to end-users for debugging.

  10. NickShahML commented on Dec 3, 2015

    @NickShahML
    Author

    That would be such a great upgrade. I'll close this thread, but I tested similar architecture in Theano

    Theano Max with 12gb: two GRU's with 2048 cells with a batch size of 256

    TensorFlow Max with 12gb: Two GRU's with 1536 cells with a batch size of 16

  11. hudvin commented on Jan 25, 2016

    @hudvin

    Want to note, I have the same issue with current version on GTX 770 (translate.py)

  12. baligar commented on Jul 5, 2016

    @baligar

    I think when the GPU runs out of its memory, the weights and maps storage is shifted onto the RAM.
    I observed this when I trained a 50 Layer ResNet on my GT 755m(running on 97%) laptop with 16GB(running on 32%) of RAM. Never faced any issues.

  13. jiapei100 commented on Jul 16, 2016

    @jiapei100

    In my case, the same, and I doubt if this Raising pool_size_limit_ will have effects on generator() ? My gosh....

    jiapei:peijia$ python train.py
    Using TensorFlow backend.
    I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcublas.so.8.0 locally
    I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcudnn.so.5.0.5 locally
    I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcufft.so.8.0 locally
    I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcuda.so.1 locally
    I tensorflow/stream_executor/dso_loader.cc:108] successfully opened CUDA library libcurand.so.8.0 locally
    Loading folder c0...
    Loading folder c1...
    Reading training images...
    /usr/local/lib/python3.5/dist-packages/skimage/util/dtype.py:110: UserWarning: Possible precision loss when converting from float64 to uint8
    "%s to %s" % (dtypeobj_in, dtypeobj))
    Fold 1/(811,)
    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_init.cc:102] Found device 0 with properties:
    name: GeForce GTX 980M
    major: 5 minor: 2 memoryClockRate (GHz) 1.1265
    pciBusID 0000:01:00.0
    Total memory: 3.93GiB
    Free memory: 3.50GiB
    I tensorflow/core/common_runtime/gpu/gpu_init.cc:126] DMA: 0
    I tensorflow/core/common_runtime/gpu/gpu_init.cc:136] 0: Y
    I tensorflow/core/common_runtime/gpu/gpu_device.cc:838] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 980M, pci bus id: 0000:01:00.0)
    Writing model architecture...
    Starting Training...
    fit...
    Train on 1619 samples, validate on 811 samples
    Epoch 1/32
    1024/1619 [=================>............] - ETA: 12s - loss: 0.8683 - acc: 0.8066I tensorflow/core/common_runtime/gpu/pool_allocator.cc:244] PoolAllocator: After 3897 get requests, put_count=3885 evicted_count=1000 eviction_rate=0.2574 and unsatisfied allocation rate=0.285348
    I tensorflow/core/common_runtime/gpu/pool_allocator.cc:256] Raising pool_size_limit_ from 100 to 110

  14. added a commit that references this issue on Jan 23, 2020
  15. added a commit that references this issue on May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions