Repository navigation
Closed
Labels
Description
Hi, We use tensorflow for training our OCR system models. I simply train models in tensorflow 0.9 and former versions. after some upgrade in cuda and tensorflow, I see large memory leak in our server with 32GB RAM.
I have tried all of suggestions in How to debug a memory leak in TensorFlow and some other github issues and stackoverflow posts. No of them worked.
train code:
#!/bin/env python
import tensorflow as tf
import Config
import Utilities
from Dataset import Dataset
from Model import Model
dataset = Dataset()
sess_config = tf.ConfigProto()
sess_config.gpu_options.allow_growth = True
sess = tf.Session(config=sess_config)
images, labels = dataset.train_images_labels()
model = Model(images, labels, training=True)
tf.train.start_queue_runners(sess=sess)
def main(global_step=0):
if global_step == 0:
init_op = tf.global_variables_initializer()
sess.run(init_op)
else:
checkpoint_path = Utilities.get_checkpoint_path(global_step)
model.saver.restore(sess, checkpoint_path)
Utilities.log_checkpoint_load(checkpoint_path)
loss = 0
train_iterations = global_step
while train_iterations < Config.train_max_iterations:
# train
l = model.train(sess)
loss += l
train_iterations += 1
# show train loss
if train_iterations % Config.display_intervals == 0:
loss /= float(Config.display_intervals)
Utilities.log_train_loss(train_iterations, loss)
loss = 0
# save checkpoint
if train_iterations % Config.checkpoint_intervals == 0:
checkpoint_path = model.saver.save(sess, Utilities.get_checkpoint_path(train_iterations))
Utilities.log_checkpoint_save(checkpoint_path)
if __name__ == '__main__':
main()
images, labels are queues from tf.train.shuffle_batch function. I used Graph.finalize() and I am sure no new operation added to graph in training because the size of stored models' files are equal. I guess the reason of leak is tensorflow queues.
Environment info
Ubuntu Server 14.04.5 LTS
Installed version of CUDA and cuDNN:
CUDA V8.0.44, cuDNN V5.1.5.
installed tensorflow from PyPI.
- sudo pip install --upgrade tensorflow_gpu.
- tensorflow 0.12.1.
Activity
yaroslavvb commentedon Jan 2, 2017
It can be useful to do a memory profile using google performance tools
Mahdizade commentedon Jan 2, 2017
@yaroslavvb I use google-pprof and heap profile save in /tmp folder. it takes too long time to train so the profile only contain near 150 itrations. the files uploaded here
yaroslavvb commentedon Jan 2, 2017
if you combine it with pprof, you can get a graph and track down which function is responsible for allocating extra memory
Mahdizade commentedon Jan 2, 2017
It doesn't show any function, this is the output of top30 command in pprof:
graph file uploaded here, unfortunately I cant find a function is responsible for allocating extra memory
yaroslavvb commentedon Jan 2, 2017
That usage doesn't seem very high, why do you think there's a memory leak in queue? Memory usage can increase between versions without having a leak
Mahdizade commentedon Jan 2, 2017
because I see 32 GB memory usage after 700000 iterations. I think the cause is data, I use tfrecord and tensorflow queue for data handling. I am sure that I hadn't leak in version 0.9.
yaroslavvb commentedon Jan 4, 2017
@zffchen78 do you have any idea why google perf tools shows "29.5% 00007f8a8afae90e" instead of symbol name in the memory dump? Does it mean this memory was allocated outside of tensorflow?
drpngx commentedon Jan 27, 2017
@yaroslavvb the hex address shows up when the symbol lookup failed. Address to symbol name mappings are always very brittle. You can try to fiddle with build options to see if it helps. You need the frame pointers for instance, IIRC. If you gdb attach to it, then info symbol, then you might be able to reverse map it.
erikchwang commentedon Jan 30, 2017
I got exactly the same problem as you, I also use TFRecord and Queue to process data, and my main memory keeps growing until the system goes down...
By the way, I use Tensorflow 0.12.1, CUDA 8.0.44, CUDNN 5.1, CentOS 7
drpngx commentedon Jan 30, 2017
Main memory as in CPU? Could you build with tcmalloc, then get a heap profile?
yaroslavvb commentedon Jan 30, 2017
To enable tcmalloc
erikchwang commentedon Feb 3, 2017
Can this problem be solved in the next release?
yaroslavvb commentedon Feb 3, 2017
@carltonwang Could you give a reproducible example and profile as a picture/graph?
cc @ebrevdo in case he has ideas
6 remaining items
erikchwang commentedon Feb 9, 2017
I implemented an encoding algorithm in my code. Today I just encapsulated this encoding method as an RNN cell, and then the memory leak disappeared!!!
girving commentedon Feb 10, 2017
Closing since the problem is gone. Happy to reopen if there is still an underlying bug to be fixed in TensorFlow, but it sounds like everything so far is inconclusive.
benwu232 commentedon Mar 16, 2017
@Mahdizade I met similar problem.
My program is similar to yours and after several epoch, 32G memory exhausted. I debugged the program and found each time the saver.save() function is run, the python process got a little bigger. I recommend you try this and see if the same thing happens.
erogol commentedon Mar 22, 2017
I have the same issue here. It goes overflowing after couple of iterations on version 1.0.1
Mahdizade commentedon Mar 23, 2017
My issue is already exists in TF 1.0. @benwu232 Thanks for your comment. I will test your solution but I see the leak on my validation code. till now I cant find the problem. in my validation code leak happened only after the first load of graph parameters (checkpoint), after validate one checkpoint and load another checkpoint, I don't see any leak in htop. I will investigate more on this problem. I don't thing the saver is the cause, I see the steady leak on training, I save the checkpoint every 5000 iteration but leak exists in this intervals.
erikchwang commentedon Mar 24, 2017
Look at this code:
result = tf.contrib.layers.bias_add(inputs=tf.matmul(a=left, b=right), activation_fn=tf.nn.softmax)If I use "softmax" as the activation function, there will be a memory leak, but if I change the activation function to "relu" or "softplus" or "sigmoid", the memory leak will disappear.
By the way, this "softmax" is not the one used at the last layer for classification.
Platform: CentOS 7, x86_64
TensorFlow version: 1.0_gpu
aselle commentedon Mar 28, 2017
Could you provide a complete test case that exhibits this behavior so we can reproduce this?
erikchwang commentedon Mar 29, 2017
After I update from TF 1.0.0 to TF 1.0.1, this problem disappear...
gunan commentedon May 28, 2017
looks like this was resolved with 1.0 release. Closing the issue.
PR #6599: Fp8 Fast Accumulation support for cublasLt