Skip to content

Memory leak in *_generator #10756

Closed
Closed
@Dref360

Description

@Dref360
  • Check that you are up-to-date with the master branch of Keras. You can update with:
    pip install git+git://github.com/keras-team/keras.git --upgrade --no-deps

  • If running on TensorFlow, check that you are up-to-date with the latest version. The installation instructions can be found here.

  • Provide a link to a GitHub Gist of a Python script that can reproduce your issue (or just copy the script here if it is short).

Since tf 1.8, the memory leak is worse. It's only happening when calling fit/evaluate multiple time so this is not likely to happen in a real setting. But this may have played a role in #10674 .

For info, tf > 1.8 uses more memory than 1.7.

How to reproduce:

pip install psutil

import numpy as np
import tensorflow as tf

from keras import Sequential
from keras.layers import Dense

print("Tensorflow version", tf.__version__)

model1 = Sequential()
model1.add(Dense(10, input_shape=(1000,)))

model1.add(Dense(3, activation='relu'))
model1.compile('sgd', 'mse')


def gen():
    while True:
        yield np.zeros([10, 1000]), np.ones([10, 3])


import os
import psutil

process = psutil.Process(os.getpid())
g = gen()
while True:
    print(process.memory_info().rss / float(2 ** 20))
    model1.fit_generator(g, 100, 2, use_multiprocessing=True, verbose=0)
    model1.evaluate_generator(gen(), 100, use_multiprocessing=True, verbose=0)

Tensorflow 1.7

('Tensorflow version', '1.7.0')
160.546875
176.2421875
177.70703125
177.8671875
177.87109375
177.87890625
177.88671875
177.890625
177.8984375
177.90234375
177.90234375
177.90234375
177.90234375
177.91015625
177.9140625
177.91796875
177.91796875
177.91796875
177.91796875
177.91796875
177.91796875
177.91796875
177.93359375

Tensorflow 1.8

('Tensorflow version', '1.9.0')
166.3125
180.30078125
182.125
182.16015625
182.22265625
182.31640625
182.3203125
182.32421875
182.3359375
182.34375
182.34765625
182.35546875
182.35546875
182.359375
182.37109375
182.38671875
182.390625
182.40234375
182.40625
182.41015625
182.41796875
182.41796875
182.41796875
182.41796875

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions