deepspeedai / deepspeedai/DeepSpeed

[BUG] Patch and reload tensor methods in flops_profiler

Open
#2,231 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
43.1k
Forks
5k
Avg merge
4d 15h
Merged PRs (30d)
112

Description

Describe the bug
Hi, I am using the FLOPs profiler as a standalone package. I found two issues in deepspeed/profiling/flops_profiler/profiler.py:

  1. In _patch_tensor_methods, should this line wrap torch.Tensor.bmm instead of torch.bmm?
  2. In _reload_tensor_methods, only torch.matmul is reset to the old function. Should we also reload other methods that are patched before? Otherwise, the other code in this script will be affected. For example, if we call get_model_profile multiple times in a script, the flops and macs can be different even for the same model. https://github.com/microsoft/DeepSpeed/blob/master/deepspeed/profiling/flops_profiler/profiler.py#L914

To Reproduce
Steps to reproduce the behavior:

  1. Go to code
  2. Scroll down to the two functions: _patch_tensor_methods and _reload_tensor_methods
  3. See error as described above

Expected behavior
The patched methods should be reloaded after profiling. Otherwise, it will affect other code.

ds_report output

--------------------------------------------------
DeepSpeed C++/CUDA extension op report
--------------------------------------------------
NOTE: Ops not installed will be just-in-time (JIT) compiled at
      runtime if needed. Op compatibility means that your system
      meet the required dependencies to JIT install the op.
--------------------------------------------------
JIT compiled ops requires ninja
ninja .................. [OKAY]
--------------------------------------------------
op name ................ installed .. compatible
--------------------------------------------------
cpu_adam ............... [NO] ....... [OKAY]
cpu_adagrad ............ [NO] ....... [OKAY]
fused_adam ............. [NO] ....... [OKAY]
fused_lamb ............. [NO] ....... [OKAY]
 [WARNING]  please install triton==1.0.0 if you want to use sparse attention
sparse_attn ............ [NO] ....... [NO]
transformer ............ [NO] ....... [OKAY]
stochastic_transformer . [NO] ....... [OKAY]
 [WARNING]  async_io requires the dev libaio .so object and headers but these were not found.
 [WARNING]  async_io: please install the libaio-dev package with apt
 [WARNING]  If libaio is already installed (perhaps from source), try setting the CFLAGS and LDFLAGS environment variables to where it can be found.
async_io ............... [NO] ....... [NO]
utils .................. [NO] ....... [OKAY]
quantizer .............. [NO] ....... [OKAY]
transformer_inference .. [NO] ....... [OKAY]
--------------------------------------------------
DeepSpeed general environment info:
torch install path ............... 
torch version .................... 1.11.0
torch cuda version ............... 11.3
torch hip version ................ None
nvcc version .....................  [FAIL] cannot find CUDA_HOME via torch.utils.cpp_extension.CUDA_HOME=None
deepspeed install path ........... 
deepspeed info ................... 0.6.7, unknown, unknown
deepspeed wheel compiled w. ...... torch 1.11, cuda 11.3

Screenshots
No

System info (please complete the following information):

  • OS: Ubuntu 18.04
  • GPU count and types: 10 A6000s
  • Interconnects (if applicable)
  • Python version: 3.9.12
  • Any other relevant info about your setup: No

Launcher context
No, it's a general question about the code itself.

Docker context
No

Additional context
No

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in deepspeed/profiling/flops_profiler/profiler.py by reading _patch_tensor_methods and _reload_tensor_methods, then trace how get_model_profile invokes them. Reproduce repeated profiling of the same model and verify that every patched tensor method is restored afterward and that the bmm patch targets the intended method.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning, performance
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
76/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.