Skip to content

Ram memory leak when using tf.function at tf 2.8,2.9 and 2.10, doesn't happen with tf 2.5 #57982

Closed

Description

@bgLeon
Click to expand!

Issue Type

Bug

Source

source

Tensorflow Version

2.10

Custom Code

Yes

OS Platform and Distribution

Ubuntu, also on Windows

Mobile device

No response

Python version

3.10 and 3.9

Bazel version

No response

GCC/Compiler version

No response

CUDA/cuDNN version

No response

GPU model and memory

No response

Current Behaviour?

Every time I use a tf.function decorator there is a memory leak in the ram, that keeps growing every iteration, I observed this in ubuntu and windows, it didn't happen with tf 2.5 but I had the server updated to python 3.10 and all the version compatible with python 3.10 (tf 2.8,2.9,2.10) have this issue. 
I tried with python 3.9 in my personal device and the issue still occurs. The leak is small but in an RL setting this is a critical issue in RL since we have to call a tf.function to take actions in the environment millions of times during training and without the decorator things go like 10 times slower.

Note that it is not an issue about not passing tensorflow objects to the wrapper, neither about having the shape of the tensor changing.

Please I need this to be fixed as soon as possible.

Standalone code to reproduce the issue

import tensorflow as tf

@tf.function
def operate(img):
    return img

img = tf.zeros((6,6,7))
for i in range (100000000):
    s= operate(img)

Relevant log output

just monitor the ram, you will see it growing constantly if you are using tf>=2.8 with tf 2.5.0 ram remains constant for the code above

Activity

  1. added
    comp:tf.function
    on Oct 6, 2022
  2. tilakrayal commented on Oct 6, 2022

    @tilakrayal
    Contributor

    @sachinprasadhs,
    I was able to reproduce the issue on tensorflow v2.8, v2.10 and nightly. Kindly find the gist of it here.

  3. added
    stat:awaiting tensorflower
    on Oct 27, 2022
  4. bgLeon commented on Dec 16, 2022

    @bgLeon
    Author

    Any updates on this?

  5. sampathrajapaksha commented on Mar 8, 2023

    @sampathrajapaksha

    @bgLeon Did you find the solution for this?
    i have the same issue and couldn't find a proper solution yet

  6. bgLeon commented on Mar 8, 2023

    @bgLeon
    Author

    Hi @sampathrajapaksha the only solution I got is to have an script where I periodically save all training data, close everything and restart training. Sadly as you see here there has been no word about a proper fix yet.

  7. sampathrajapaksha commented on Mar 8, 2023

    @sampathrajapaksha

    @bgLeon Yes, that's one possible solution which I also thought about. I saw a few people have posted the same issue in StackOverflow and, unfortunately couldn't find any efficient solution yet

  8. bgLeon commented on Mar 8, 2023

    @bgLeon
    Author

    @sampathrajapaksha could you share the stackoverflow link? might happen that someone posts there useful insights

  9. tnybny commented on Apr 17, 2023

    @tnybny

    reproducible with 2.11. Possible duplicate of #50765.

  10. chrisyeh96 commented on Jan 19, 2024

    @chrisyeh96
    Contributor

    This issue seems to be fixed for me, as of TF 2.14

    import tensorflow as tf
    import os, psutil
    process = psutil.Process(os.getpid())
    
    
    @tf.function
    def operate(img):
        return img
    
    img = tf.zeros((6,6,7))
    rss = 0
    for i in range (100000000):
        s= operate(img)
        new_rss = process.memory_info().rss
        if new_rss != rss:
            print(i, new_rss)
            rss = new_rss

    output:

    0 893091840
    9961 893239296
    149961 893251584
    
  11. sachinprasadhs commented on Jan 19, 2024

    @sachinprasadhs
    Contributor

    @chrisyeh96 , Thanks for validating.

    @bgLeon , Even I was able to see the constant memory when I ran your code, could you please verify and close the issue.

    image

  12. added
    stat:awaiting response
    and removed
    stat:awaiting tensorflower
    on Jan 19, 2024
  13. bgLeon commented on Jan 20, 2024

    @bgLeon
    Author

    Wow it took a while, yes I tested with TF 2.14 and I don't see the error anymore either, it's solved in this version

  14. google-ml-butler commented on Jan 20, 2024

    @google-ml-butler

    Are you satisfied with the resolution of your issue?
    Yes
    No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

TF 2.10comp:tf.functionstat:awaiting responsetype:bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions