Skip to content

Memory Leak #7714

Closed
Closed

Description

@aboettcher

The following code has a memory leak with the current numpy version:

import numpy as np
import scipy
import scipy.stats
u = np.random.random(128**2)
for i in range(100000):
    scipy.stats.norm.ppf(u)

Checking with htop the memory increases as the loops are performed. With older versions of numpy the above code runs with very little memory usage and especially no increase over time.

I tested if the error is due to a bug in scipy but it isn't. Then I checked with which numpy version the error got introduced (since I realized it after an update of all my packages).

According to git bisect the commit that introduced the error is:
9128ed5

OS: Ubuntu 14.04.3 LTS
Python: sys.version_info(major=3, minor=4, micro=3, releaselevel='final', serial=0)
numpy: 1.12.0.dev0+cc51ba8
scipy: 0.18.0.dev0+41e2d00

Activity

  1. added this to the milestone on Jun 7, 2016
  2. charris commented on Jun 7, 2016

    @charris
    Member

    @gfyoung This is yours.

  3. gfyoung commented on Jun 7, 2016

    @gfyoung
    Contributor

    @aboettcher : Thanks for alerting us about this! Unfortunately, I can't seem to reproduce the problem. I ran your commands and monitored htop as the loop was running and my MEM% and usage remained constant virtually the entire time. Can you provide further information about your architecture, Python version, and numpy + scipy versions? Here are mine:

    OS: Ubuntu 14.04
    Python: 2.7.11
    numpy: v1.11.0
    scipy: 0.18.0.dev0+e2c946c

    Also, not really sure at the moment how this memory leak could have been triggered by those changes, as they seem quite distant from what you are running here. Perhaps a more experience C developer could illuminate possible problems with that commit.

  4. aboettcher commented on Jun 7, 2016

    @aboettcher
    Author

    @gfyoung thank you for fast response. Those are my versions:
    OS: Ubuntu 14.04.3 LTS
    Python: sys.version_info(major=3, minor=4, micro=3, releaselevel='final', serial=0)
    numpy: 1.12.0.dev0+cc51ba8
    scipy: 0.18.0.dev0+41e2d00
    I did not yet test python 2.7.

  5. gfyoung commented on Jun 7, 2016

    @gfyoung
    Contributor

    @aboettcher : should have mentioned this initially, but could you actually put that system info in your original issue? I think that would be useful for people (maintainers especially) when they read it so they know the entire context, as your wording of "current numpy" threw me off since I thought you were talking about the latest released version.

  6. aboettcher commented on Jun 7, 2016

    @aboettcher
    Author

    @gfyoung I tested your version of numpy (v1.11.0) and the memory leak is indeed not there.

    Can you confirm the memory leak for this version?:
    9128ed5

  7. gfyoung commented on Jun 7, 2016

    @gfyoung
    Contributor

    @aboettcher : okay, so at least we know it was introduced after v1.11.0 - however, it did seem strange that git would get it wrong with bisect, so I checked the release and it turns out that PR wasn't included. Sigh...I'll double check now against master to see if I can replicate.

  8. charris commented on Jun 7, 2016

    @charris
    Member

    @gfyoung I do see that commit in v1.11.0, but if the bug doesn't show up there it suggests a bisection failure.

  9. aboettcher commented on Jun 7, 2016

    @aboettcher
    Author

    @gfyoung I am sorry for giving the wrong pointer. I trusted bisect at this point.

  10. gfyoung commented on Jun 7, 2016

    @gfyoung
    Contributor

    Sorry, before we relegate it to a bisect failure, @charris , can you show me where you're seeing that commit show up in v1.11.0? I couldn't find it anywhere in the maintenance branch nor in the tagged v1.11.0 version of the C code that I fixed here.

  11. gfyoung commented on Jun 7, 2016

    @gfyoung
    Contributor

    @aboettcher : I am able to replicate the memory leak using the bleeding versions of scipy (5a779fd) and numpy (175476f) on the architecture and Python I gave earlier.

  12. charris commented on Jun 7, 2016

    @charris
    Member

    @aboettcher

    charris@fc [numpy.git ((v1.11.0))]$ git log 9128ed5
    commit 9128ed5198cc8544406467a00824e5fe6791f090
    Author: gfyoung <[email protected]>
    Date:   Wed Jan 13 13:15:21 2016 +0000
    
        BUG: Fix string copying for np.place
    
  13. charris commented on Jun 7, 2016

    @charris
    Member

    Changes in Scipy may have exposed the problem. There is also the possibly related (unlikely?) report #7710.

  14. gfyoung commented on Jun 7, 2016

    @gfyoung
    Contributor

    @charris : I hate to keep pushing this, but that doesn't convince me. When I do git checkout v1.11.0 and then I run git log 175476fec7 (that's the LRU cache PR that you just merged), I still get output for that commit.

  15. aboettcher commented on Jun 7, 2016

    @aboettcher
    Author
  16. charris commented on Jun 7, 2016

    @charris
    Member

    @gfyoung Seems like pilot error on my part, git log also finds it in 1.8.x. Probably need to make git log only search reachable from HEAD.

  17. charris commented on Jun 7, 2016

    @charris
    Member

    OK, this works better git log --grep 'BUG: Fix string copy'. Looks like searching by hash looks into the whole tree. Learn something everyday ;)

  18. gfyoung commented on Jun 7, 2016

    @gfyoung
    Contributor

    Me too! 😄

    In any case, I will run git bisect between v1.11.0 and master and see where the bug lies. I'll also take a look to see whether there are sources of improvement upon that PR.

  19. aboettcher commented on Jun 7, 2016

    @aboettcher
    Author

    I am currently rerunning bisect with
    git bisect good v1.11.1rc1
    git bisect bad 175476fec763984573e60485a447978cbcb381c0 (newest version). Will report the result soon.

  20. aboettcher commented on Jun 7, 2016

    @aboettcher
    Author

    The rerun of bisect gave the same result as I reported above (9128ed5)

  21. gfyoung commented on Jun 7, 2016

    @gfyoung
    Contributor

    Yep, I can confirm as well. It's my PR...now off to figuring out why. 😕

  22. modified the milestones: , 1.12.0 release on Jun 7, 2016
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

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions