Stonesjtu / pytorch_memlab

Profiling and inspecting memory in pytorch
MIT License
1.01k stars 37 forks source link

Use new `memory_stats` call; use pandas for formatting #11

Closed andyljones closed 4 years ago

andyljones commented 4 years ago

This PR

Upshot is that .records() will give you a dataframe like this

image

with 96 columns covering every memory stat Torch offers. Terminal output can be whatever subset you want:

image

I don't think you'll want to take this PR as is; I've broken a bunch of stuff getting to what I need for the task at hand. I'm more making this PR in case you want to nab parts for the main branch.

andyljones commented 4 years ago

now with bonus HTML barcharts

image

andyljones commented 4 years ago

And now it accurately reports peaks and allocated/freed when you're profiling a hierarchy of functions.

image

This has been really useful for me, thanks so much for making it!

I've tried to restore some of the things I know that I broke, but some other stuff is still going to block merging with main. In particular,

Stonesjtu commented 4 years ago

It's great that you liked this tool. This is really a big PR, hopefully I can review these changes thoroughly this weekend.

andyljones commented 4 years ago

Thanks! No need to feel rushed though, and I understand if you decide it's too far from the original tool to be justifiable to fold in.

Really it's the pandas dep that's the critical bit: if you're okay with it, I'm happy to do the minimal extra work to get the tests working. Since pandas is a big library and doesn't support 2.7 any more, that might be too much for you though.

Stonesjtu commented 4 years ago

@andyljones I'm totally ok to drop python2.7 support. We have only < 1% python2.7 downloads.

Pandas dependency should not be a problem for me, it's a pretty common package. But I'm wondering if we can bypass pandas for the command-line interface.

andyljones commented 4 years ago

Ok, I've resolved lots of the smaller issues. Bigger ones:

Stonesjtu commented 4 years ago

Let's clean things up based on ipython and pandas

andyljones commented 4 years ago

Great. I'll do a full pass. Rather than list off individual names you'd like changed, is a there a style guide you can point me at?

Stonesjtu commented 4 years ago

We followed Google's python style guide.

andyljones commented 4 years ago

Right:

andyljones commented 4 years ago

can you make the function name an action rather than a thing? e.g. _subset_line_records to _extract_line_records, _line_records_merged_with_code to merge_line_records_with_code.

I've done this, but as an aside this is an idiom from functional programming. If a function has no side-effects, it effectively is its return value, so it should be called a noun rather than a verb. Think of it as soft command-query separation.

OK. I've fulfilled most of the revision requests, and at this point the cleanup for the PR has taken substantially longer than implementing the original functionality. I respect that you've got high standards for the code in your projects, and I know you've invested time too in reviewing my code, but I'm afraid I can't put any more time towards this. If you're not happy with the PR as-is, and you don't want to make the final revisions yourself, that's okay: I'll close this and I'll instead publish the functionality I wrote as it's own package. I'd be disappointed, but unfortunately that's just how things work out sometimes.

Stonesjtu commented 4 years ago

Andy, thanks for your valued time to make this PR and address my suggestions. This PR has been impressive since the first proposal. I'm just trying to help you make it more pythonic and readable (for most python coders). It's a common situation that people spend more time addressing code reviews than functionality.

I can merge this PR first and then do some changes myself, but I think it's better for you to make this PR a complete one. Sadly you don't have that amount of time.

andyljones commented 4 years ago

Huurah! Thanks very much.

I think this might be a workplace culture thing; my previous experience has been much more relaxed about code style (as you can likely tell!). It's my bad for not asking after your standards originally, but you might also want to add some brief contributor guidelines to the readme or wiki.