Skip to content

Adding a memory profiling example - #41

Merged
Chillee merged 6 commits into
albanD:mainfrom
sanketpurandare:mem_profiling
Jun 29, 2022
Merged

Adding a memory profiling example#41
Chillee merged 6 commits into
albanD:mainfrom
sanketpurandare:mem_profiling

Conversation

@sanketpurandare

@sanketpurandare sanketpurandare commented Jun 21, 2022

Copy link
Copy Markdown
Contributor

This example shows how to use torch_dispatch for memory profiling
It shows two ways

  1. Profiling the forward and backward pass of model
  2. Profiling a any piece of code
    It also provides utilities to plot the memory profile and compare it
    AlbertForMaskedLM_mem_usage
    autograd_mem_usage

@sanketpurandare sanketpurandare changed the title Adding a new example Adding a memory profiling example Jun 21, 2022
@albanD

albanD commented Jun 22, 2022

Copy link
Copy Markdown
Owner

Hey!
For the CI to run, you can add your new dependencies to requirements.txt (torch nightly is always there and doesn't need to be listed there)

Comment thread dispatch_mem_profiler.py Outdated
def reduce_to_scalar_loss(inp):
return inp.sum()

from functorch.compile import aot_module, nop, print_compile, min_cut_rematerialization_partition

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this to the top? Also try running black formatter just for consistent styling.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The lint should already check that everything is black compliant:

include_patterns = ['**/*.py']

Since it passes on the PR, I guess it is good.

@albanD albanD left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice utility!

Comment thread dispatch_mem_profiler.py Outdated

def __torch_dispatch__(self, func, types, args=..., kwargs=None):

global mem_usage, operator_names

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need this since you only write into these dictionaries.
Same for the other functions below except the ones that do set mem_usage.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaned up global usage

@albanD

albanD commented Jun 22, 2022

Copy link
Copy Markdown
Owner

Could you add the new requirements so that we can merge this?

@sanketpurandare

Copy link
Copy Markdown
Contributor Author

Could you add the new requirements so that we can merge this?

Added them

@albanD

albanD commented Jun 23, 2022

Copy link
Copy Markdown
Owner

Python builtin Modules don't need to be in there ;)

@anijain2305

Copy link
Copy Markdown

@albanD Can we merge this PR if it looks good?

@Chillee
Chillee merged commit cba710e into albanD:main Jun 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants