Stonesjtu / pytorch_memlab

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

Add IPython extension #8

Closed willprice closed 4 years ago

willprice commented 4 years ago

This address #7.

It's a WIP at the moment but thought I'd push it up to get some feedback. What do you think? I've tried to stay somewhat consistent with line_profiler's %lprun magic command, although currently, it doesn't support the same breadth of arguments (I probably won't add module support, or anything too complex)

There's a demo notebook demo.ipynb for testing out the IPython line and cell magics.

image image

Stonesjtu commented 4 years ago

Great work to have ipython supported. Can we make ipython an optional dependency by wrapping from . extension import load_ipython_extension with try catch block.

willprice commented 4 years ago

Sure, I've made ipython an optional dep in setup.py now. It can be installed with pip install .[ipython] from a local clone, or when on pypi: pip install pytorch-memlab[ipython]. I've also add some documentation to the README.

These are the options %lprun support:

        Options:
        -f <function>: LineProfiler only profiles functions and methods it is told
        to profile.  This option tells the profiler about these functions. Multiple
        -f options may be used. The argument may be any expression that gives
        a Python function or method object. However, one must be careful to avoid
        spaces that may confuse the option parser.
        -m <module>: Get all the functions/methods in a module
        One or more -f or -m options are required to get any useful results.
        -D <filename>: dump the raw statistics out to a pickle file on disk. The
        usual extension for this is ".lprof". These statistics may be viewed later
        by running line_profiler.py as a script.
        -T <filename>: dump the text-formatted statistics with the code side-by-side
        out to a text file.
        -r: return the LineProfiler object after it has completed profiling.
        -s: strip out all entries from the print-out that have zeros.
        -u: specify time unit for the print-out in seconds.

I'm thinking it might be worth adding -r, and -T. I think I should also add an option for GPU IDs for the profiler

Stonesjtu commented 4 years ago

You are right. We'll leave the API change in the future (or never) work.

Stonesjtu commented 4 years ago

LGTM, is this still a wip

willprice commented 4 years ago

I think this is in a decent state for a first release. I'm happy to spend a bit more time tarting up the docs though? Up to you :)

Stonesjtu commented 4 years ago

OK, just ping me when it's ready.

willprice commented 4 years ago

OK, I'm happy now :)

Stonesjtu commented 4 years ago

Merged. Thanks for your contribution!