-
-
Notifications
You must be signed in to change notification settings - Fork 402
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to explain these memory behaviors when using numpy? #31
Comments
Thanks for your note and the helpful repro case! First, note that in your original code that there's definitely a fair amount of allocation going on in the second Second, I strongly suspect what's happening is that the first line is allocating a bunch of objects and then freeing them, leaving behind an allocated object that is big, but smaller than the other allocated objects that were freed in the process. In any event, the results for (Note you have to add this
This is with the latest version (you may need to do a
Now you can see the allocations, mostly reasonably accounted for. (There's sampling going on, so everything is counted in multiples of 16MB.) Running with
I don't understand the disparity between what Also, my current thinking was that showing negative growth is more useful in understanding what's going on than just printing 0, but maybe just indicating growth ( Anyway, here's what
You can see that |
Thanks once again for posting this. It led me to discovering some issues that I have now resolved in the latest version. The most important problem was that Scalene was missing some samples due to lost signals (something I was already accounting for, but not in the case when native code leads to many signals, which all get coalesced). This fix resolves the difference between
For the original program you posted, here are the results:
As you can see, the results for Scalene (for lines 5 and 6) are similar to those from
And 90 is a lot closer to 76 than 152. :) |
I am going to close this issue since I believe it has been resolved. I am still considering extending the output to show average |
Thanks for the quick support!! Regarding
Having the overall growth is clear to me, but also having (maybe as an option) the possibility to see detailed About the current issue, i can get perfect results with the following:
90M for an array of However, when adjusting the script a bit, results get very strange:
And even stranger:
When doing the lines 2 and 3 of the first script in one line:
|
This was super helpful! It revealed a bug. Scalene tracks average memory growth. That means it needs to know how many times each line of code executes. But that's wrong! It really needs to know how many times each bytecode index executes. Using lines of code was leading to inaccuracies when there were lots of allocations or frees on individual lines, as in your example. I have now fixed this (commit coming momentarily). Here's the output for each of your tests. Test 1:
Test 2:
Test 3:
Thanks again for your help in identifying this problem; please keep me updated on how it works out going forwards! |
Fixed with emeryberger@bcaddaf. |
Amazing! I may have one last interrogation: My interpretation is that since, in Test 2, the first Do you think there could be ways to track suck peaks? When using big numpy arrays, such internal peaks could be super useful to track, because they can be a witness of unwanted memory copies. When doing programming with big numpy arrays (for example in Machine Learning/Deep Learning), this can be a major waste of time. BTW, The new memory usage graph is awesome! |
Scalene intercepts all memory allocations (from Python and native code). What's happening is that |
Another possibility is to work in sparklines for each line of code... |
Having |
So scrap the |
Actually, having the sparklines for each line of code would be a must. |
I guess what I am asking is do you find the usage % info of value? I see it as potentially useful as it shows where the most allocation activity is. |
Just committed a version with memory usage as per-line sparklines (I wonder if printing a % beside it would be of value). Take a look! |
In this example, you can see the increase and decrease over time, which to me is pretty suggestive that there is copying going on (from an old, reclaimed object -- corresponding to the dip -- into the newly allocated one). |
Amazing!! For me, the current metrics (growth, % of use) as well as the sparklines are enough to interpret what's going on. Regarding the sparline of the 6th line, shouldn't there be a "increase, increase, decrease" (e.g. allocation of first array, allocation of second array, deallocations of first array), instead of "increase, decrease, increase"? |
Great catch. This took a surprisingly long time to unwind.
|
When running a very simple script based on numpy functions, we can get the following results:
How can we get:
System info
The text was updated successfully, but these errors were encountered: